Skip to content

Commit de3ffb3

Browse files
abdulraqeeb33AR Abdul Azeez
andauthored
improvement: add branch parameter (#2385)
* add branch parameter * branch name validation --------- Co-authored-by: AR Abdul Azeez <abdul@onesignal.com>
1 parent 6628770 commit de3ffb3

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

.github/workflows/create-release-pr.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
name: Create Release PR
22

3+
# Note: The "Use workflow from" dropdown selects which version of THIS workflow to run.
4+
# Always select "main" unless you're testing workflow changes from another branch.
5+
# The "base_branch" input below determines where the release PR will be targeted.
6+
37
on:
48
workflow_dispatch:
59
inputs:
610
version:
711
description: 'New SDK version (e.g. 5.1.38 or 5.2.0-beta1)'
812
type: string
913
required: true
14+
base_branch:
15+
description: 'Target branch for the PR (e.g. main for regular releases, 5.4-main for 5.4.x releases)'
16+
type: string
17+
required: false
18+
default: 'main'
1019

1120
permissions:
1221
contents: write
@@ -18,25 +27,58 @@ jobs:
1827

1928
env:
2029
VERSION: ${{ github.event.inputs.version }}
30+
BASE_BRANCH: ${{ github.event.inputs.base_branch || 'main' }}
2131
BRANCH: rel/${{ github.event.inputs.version }}
2232
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2333

2434
steps:
35+
- name: 📋 Display Configuration
36+
run: |
37+
echo "============================================"
38+
echo "📦 Release Version: $VERSION"
39+
echo "🎯 Base Branch (PR Target): $BASE_BRANCH"
40+
echo "🌿 Release Branch (to create): $BRANCH"
41+
echo "============================================"
42+
43+
- name: ✅ Validate Base Branch
44+
run: |
45+
if [[ "$BASE_BRANCH" == "main" ]]; then
46+
echo "✅ Valid base branch: main"
47+
elif [[ "$BASE_BRANCH" =~ ^[0-9]+\.[0-9]+-main$ ]]; then
48+
echo "✅ Valid base branch: $BASE_BRANCH"
49+
else
50+
echo "❌ ERROR: Invalid base branch '$BASE_BRANCH'"
51+
echo ""
52+
echo "Base branch must be either:"
53+
echo " - 'main' (for regular releases)"
54+
echo " - 'X.Y-main' (for version-specific releases, e.g., 5.4-main, 5.5-main)"
55+
echo ""
56+
echo "Examples:"
57+
echo " ✅ main"
58+
echo " ✅ 5.4-main"
59+
echo " ✅ 5.10-main"
60+
echo " ❌ master"
61+
echo " ❌ 5.4"
62+
echo " ❌ 5.4-develop"
63+
exit 1
64+
fi
65+
2566
- name: Checkout repository
2667
uses: actions/checkout@v4
2768
with:
2869
fetch-depth: 0 # Ensure full history for git log
2970
fetch-tags: true
3071

31-
- name: Create release branch from main
72+
- name: Create release branch from base
3273
run: |
3374
3475
if git ls-remote --exit-code --heads origin "$BRANCH"; then
3576
echo "Deleting remote branch $BRANCH"
3677
git push origin --delete "$BRANCH"
3778
fi
3879
39-
git checkout -b "$BRANCH" origin/main
80+
echo "Creating release branch $BRANCH from $BASE_BRANCH"
81+
git checkout -b "$BRANCH" origin/$BASE_BRANCH
4082
4183
- name: Update SDK_VERSION in gradle.properties
4284
run: |
@@ -141,4 +183,4 @@ jobs:
141183
--title "Release SDK v$VERSION" \
142184
--body-file pr_body.md \
143185
--head "$BRANCH" \
144-
--base main
186+
--base "$BASE_BRANCH"

.github/workflows/publish-release.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- '*-main' # Matches 5.4-main, 5.5-main, etc.
78
workflow_dispatch:
89
inputs:
910
ref:
@@ -19,7 +20,7 @@ jobs:
1920
publish:
2021
runs-on: ubuntu-latest
2122

22-
# Auto-run only if this is a rel/* merge commit into main, OR manual dispatch
23+
# Auto-run only if this is a rel/* merge commit, OR manual dispatch
2324
if: github.event_name == 'workflow_dispatch' ||
2425
(startsWith(github.event.head_commit.message, 'Merge pull request') &&
2526
contains(github.event.head_commit.message, 'rel/'))
@@ -39,6 +40,17 @@ jobs:
3940
with:
4041
ref: ${{ github.event.inputs.ref || github.sha }}
4142

43+
- name: Detect current branch
44+
id: detect_branch
45+
run: |
46+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
47+
BRANCH="${{ github.event.inputs.ref }}"
48+
else
49+
BRANCH="${{ github.ref_name }}"
50+
fi
51+
echo "CURRENT_BRANCH=$BRANCH" >> $GITHUB_ENV
52+
echo "Publishing from branch: $BRANCH"
53+
4254
- name: Ensure Java 11 or 17
4355
run: |
4456
CURRENT_JAVA=$(java -version 2>&1 | head -n 1 | awk -F '"' '{print $2}')
@@ -92,17 +104,19 @@ jobs:
92104
-Psigning.password="$SDK_SIGNING_PASSWORD" \
93105
-Psigning.secretKeyRingFile="$GPG_FILE_PATH"
94106
95-
- name: Get latest merged rel/* PR into main
107+
- name: Get latest merged rel/* PR
96108
id: fetch_pr
97109
run: |
110+
echo "Looking for merged release PRs into base branch: $CURRENT_BRANCH"
111+
98112
PR_JSON=$(gh pr list \
99113
--state merged \
100-
--base main \
114+
--base "$CURRENT_BRANCH" \
101115
--json number,title,body,headRefName,mergedAt \
102116
--jq '[.[] | select(.headRefName | startswith("rel/"))] | sort_by(.mergedAt) | last')
103117
104118
if [[ -z "$PR_JSON" || "$PR_JSON" == "null" ]]; then
105-
echo "❌ No merged release PR found."
119+
echo "❌ No merged release PR found for base branch: $CURRENT_BRANCH"
106120
exit 1
107121
fi
108122

0 commit comments

Comments
 (0)