Skip to content

Commit

Permalink
Update code freeze bot to check target PR branch correctly for issue_…
Browse files Browse the repository at this point in the history
…comment

Signed-off-by: Andrew Leonard <[email protected]>
  • Loading branch information
andrew-m-leonard committed Apr 29, 2024
1 parent da26277 commit 1dd231c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 31 deletions.
31 changes: 0 additions & 31 deletions .github/workflows/code-freeze-new.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,6 @@ jobs:
codefreeze_new:
runs-on: ubuntu-latest
steps:
- name: Get pull request target branch
if: github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)
id: get-pr-target-branch
run: |
echo "Getting target branch"
if [[ -z $PR_NUMBER ]]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
fi
TARGET_BRANCH="$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json baseRefName --jq '.baseRefName')"
echo "pr_target_branch=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
echo "PR target branch = $TARGET_BRANCH"
env:
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if target branch is a code freeze branch
if: github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)
id: check-freeze-branch
# Following grep "regex" needs to exactly match the required target branches to "freeze"
run: |
if echo "$PR_TARGET_BRANCH" | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$'; then
FREEZE_BRANCH='true'
else
FREEZE_BRANCH='false'
fi
echo "code_freeze_branch=$FREEZE_BRANCH" >> "$GITHUB_OUTPUT"
echo "Is $PR_TARGET_BRANCH a code freeze branch? => $FREEZE_BRANCH"
env:
PR_TARGET_BRANCH: ${{ steps.get-pr-target-branch.outputs.pr_target_branch }}

- name: Code Freeze New
if: (github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && steps.check-freeze-branch.outputs.code_freeze_branch == 'true'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
Expand Down
71 changes: 71 additions & 0 deletions .github/workflows/code-freeze-regex-branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ********************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made
# available under the terms of the Apache Software License 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: Apache-2.0
# ********************************************************************************

---
name: Code Freeze for regex branch

# Controls when the workflow will run
on:
workflow_call:
inputs:
branch-regex:
required: true
type: string

permissions:
contents: write
pull-requests: write

jobs:
codefreeze_branch_check:
runs-on: ubuntu-latest
steps:
- name: Get pull request target branch
if: github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)
id: get-pr-target-branch
run: |
echo "Getting target branch"
if [[ -z $PR_NUMBER ]]; then
PR_NUMBER="${{ github.event.pull_request.number }}"
fi
TARGET_BRANCH="$(gh pr view "$PR_NUMBER" --repo "$REPOSITORY" --json baseRefName --jq '.baseRefName')"
echo "pr_target_branch=$TARGET_BRANCH" >> "$GITHUB_OUTPUT"
echo "PR target branch = $TARGET_BRANCH"
env:
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.issue.number }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check if target branch is a code freeze branch
if: github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)
id: check-freeze-branch
run: |
echo "Checking if $PR_TARGET_BRANCH matches a code freeze branch with regex $BRANCH_REGEX"
if echo "$PR_TARGET_BRANCH" | grep -E "$BRANCH_REGEX"; then
FREEZE_BRANCH='true'
else
FREEZE_BRANCH='false'
fi
echo "code_freeze_branch=$FREEZE_BRANCH" >> "$GITHUB_OUTPUT"
echo "Is $PR_TARGET_BRANCH a code freeze branch? => $FREEZE_BRANCH"
env:
PR_TARGET_BRANCH: ${{ steps.get-pr-target-branch.outputs.pr_target_branch }}
BRANCH_REGEX: ${{ inputs.branch-regex }}

- name: Code Freeze if matches regex
if: (github.event_name == 'pull_request_target' || (github.event_name == 'issue_comment' && github.event.issue.pull_request)) && steps.check-freeze-branch.outputs.code_freeze_branch == 'true'
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ github.event.issue.number }}
body: echo "IT REALLY IS A CODE_FREEZE!! ${{ github.event.issue.number }}"

0 comments on commit 1dd231c

Please sign in to comment.