Skip to content

Commit 7c0ab4d

Browse files
authored
INFRA-3000: Merge Version Bump PRs with comment (#179)
1 parent 26bff79 commit 7c0ab4d

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

.github/workflows/merge-approved-pr.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ on:
77
required: true
88
type: number
99
description: 'The number of the pull request to process'
10+
required-base-branch:
11+
required: true
12+
type: string
13+
description: 'The required base branch name (e.g., main)'
14+
head-branch-pattern:
15+
required: true
16+
type: string
17+
description: 'Regex pattern for the required head branch (e.g., ^stable-main-[0-9]+\.[0-9]+\.[0-9]+$)'
1018
secrets:
1119
github-token:
1220
required: true
@@ -16,6 +24,19 @@ jobs:
1624
merge-pr:
1725
runs-on: ubuntu-latest
1826
steps:
27+
# Validate required inputs
28+
- name: Validate Inputs
29+
run: |
30+
if [[ -z "${{ inputs.required-base-branch }}" ]]; then
31+
echo "::error::Missing required input: 'required-base-branch' must be provided."
32+
exit 1
33+
fi
34+
if [[ -z "${{ inputs.head-branch-pattern }}" ]]; then
35+
echo "::error::Missing required input: 'head-branch-pattern' must be provided."
36+
exit 1
37+
fi
38+
echo "Inputs validated: required-base-branch='${{ inputs.required-base-branch }}', head-branch-pattern='${{ inputs.head-branch-pattern }}'"
39+
1940
# Fetch PR metadata (head and base branches) using the GitHub API
2041
- name: Get PR Details
2142
id: get-pr
@@ -34,22 +55,21 @@ jobs:
3455
core.setOutput('base', pr.base.ref);
3556
core.setOutput('head', pr.head.ref);
3657
37-
# Verify that the PR targets 'main' from 'stable-main-x.y.z'
58+
# Verify that the PR targets the required base branch from the required head pattern
3859
- name: Verify Branch Names
3960
id: verify-branches
4061
run: |
41-
# Define the required branch pattern
42-
REQUIRED_BASE="main"
43-
# Head branch must match pattern: stable-main-X.Y.Z where X, Y, Z are integers
44-
HEAD_PATTERN="^stable-main-[0-9]+\.[0-9]+\.[0-9]+$"
62+
# Get required branch patterns from inputs
63+
REQUIRED_BASE="${{ inputs.required-base-branch }}"
64+
HEAD_PATTERN="${{ inputs.head-branch-pattern }}"
4565
4666
# Get actual values from the previous step
4767
ACTUAL_BASE="${{ steps.get-pr.outputs.base }}"
4868
ACTUAL_HEAD="${{ steps.get-pr.outputs.head }}"
4969
5070
# Compare actual branches against requirements
5171
if [[ "$ACTUAL_BASE" != "$REQUIRED_BASE" ]] || ! [[ "$ACTUAL_HEAD" =~ $HEAD_PATTERN ]]; then
52-
echo "Skipping: PR must be from 'stable-main-X.Y.Z' to '$REQUIRED_BASE'. Found $ACTUAL_HEAD -> $ACTUAL_BASE"
72+
echo "Skipping: PR must be from '$HEAD_PATTERN' to '$REQUIRED_BASE'. Found $ACTUAL_HEAD -> $ACTUAL_BASE"
5373
echo "should_skip=true" >> "$GITHUB_OUTPUT"
5474
else
5575
echo "Branches match requirements: Source '$ACTUAL_HEAD' -> Target '$ACTUAL_BASE'."

0 commit comments

Comments
 (0)