-
Notifications
You must be signed in to change notification settings - Fork 378
183 lines (150 loc) · 6.28 KB
/
Copy pathcreate-release-pr.yml
File metadata and controls
183 lines (150 loc) · 6.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Create Release PR
# Note: The "Use workflow from" dropdown selects which version of THIS workflow to run.
# Always select "main" unless you're testing workflow changes from another branch.
# The "base_branch" input below determines where the release PR will be targeted.
on:
workflow_dispatch:
inputs:
version:
description: "New SDK version (e.g. 5.1.38 or 5.2.0-beta1)"
type: string
required: true
base_branch:
description: "Target branch for the PR (e.g. main for regular releases, 5.4-main for 5.4.x releases)"
type: string
required: false
default: "main"
permissions:
contents: write
pull-requests: write
jobs:
bump-version:
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.version }}
BASE_BRANCH: ${{ github.event.inputs.base_branch || 'main' }}
BRANCH: rel/${{ github.event.inputs.version }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: 📋 Display Configuration
run: |
echo "============================================"
echo "📦 Release Version: $VERSION"
echo "🎯 Base Branch (PR Target): $BASE_BRANCH"
echo "🌿 Release Branch (to create): $BRANCH"
echo "============================================"
- name: ✅ Validate Base Branch
run: |
if [[ "$BASE_BRANCH" == "main" ]]; then
echo "✅ Valid base branch: main"
elif [[ "$BASE_BRANCH" =~ ^[0-9]+\.[0-9]+-main$ ]]; then
echo "✅ Valid base branch: $BASE_BRANCH"
else
echo "❌ ERROR: Invalid base branch '$BASE_BRANCH'"
echo ""
echo "Base branch must be either:"
echo " - 'main' (for regular releases)"
echo " - 'X.Y-main' (for version-specific releases, e.g., 5.4-main, 5.5-main)"
echo ""
echo "Examples:"
echo " ✅ main"
echo " ✅ 5.4-main"
echo " ✅ 5.10-main"
echo " ❌ master"
echo " ❌ 5.4"
echo " ❌ 5.4-develop"
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0 # Ensure full history for git log
fetch-tags: true
- name: Setup Git User
uses: OneSignal/sdk-shared/.github/actions/setup-git-user@main
- name: Create release branch from base
run: |
if git ls-remote --exit-code --heads origin "$BRANCH"; then
echo "Deleting remote branch $BRANCH"
git push origin --delete "$BRANCH"
fi
echo "Creating release branch $BRANCH from $BASE_BRANCH"
git checkout -b "$BRANCH" origin/$BASE_BRANCH
- name: Update SDK_VERSION in gradle.properties
run: |
sed -i "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" OneSignalSDK/gradle.properties
sed -i "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" examples/demo/gradle.properties
- name: Commit and Push changes
run: |
git commit -am "chore: bump SDK_VERSION to $VERSION"
git push origin "$BRANCH"
- name: Fetch Last GitHub Release Tag
id: fetch_last_release
run: |
echo "Fetching latest GitHub release tag..."
LAST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName')
if [[ -z "$LAST_TAG" ]]; then
echo "❌ No previous release tag found. Cannot generate release notes."
exit 0
fi
echo "✅ Found last release tag: $LAST_TAG"
echo "range=$LAST_TAG..HEAD" >> $GITHUB_OUTPUT
- name: Generate Release Notes from PR Titles
id: generate_notes
run: |
if [[ "$VERSION" == *"alpha"* ]]; then
CHANNEL="alpha"
elif [[ "$VERSION" == *"beta"* ]]; then
CHANNEL="beta"
else
CHANNEL="current"
fi
echo "**Channels:** $CHANNEL" >> pr_body.md
echo "" >> pr_body.md
RANGE="${{ steps.fetch_last_release.outputs.range }}"
echo "📦 Commit range: $RANGE"
COMMITS=$(git log "$RANGE" --pretty=format:"%H" | sort -u)
if [[ -z "$COMMITS" ]]; then
echo "❌ No commits found. Exiting."
exit 0
fi
> raw_titles.txt
for SHA in $COMMITS; do
PR_INFO=$(gh api "repos/${{ github.repository }}/commits/$SHA/pulls" \
-H "Accept: application/vnd.github.groot-preview+json" 2>/dev/null)
TITLE=$(echo "$PR_INFO" | jq -r '.[0].title // empty')
NUMBER=$(echo "$PR_INFO" | jq -r '.[0].number // empty')
if [[ -n "$TITLE" && -n "$NUMBER" ]]; then
echo "$TITLE ([#$NUMBER](https://github.com/${{ github.repository }}/pull/$NUMBER))" >> raw_titles.txt
echo "✅ $SHA → $TITLE (#$NUMBER)"
else
echo "⚠️ $SHA → No PR found"
fi
done
sort -fu raw_titles.txt > pr_titles.txt
if [[ ! -s pr_titles.txt ]]; then
echo "❌ No PR titles found from commits. Exiting."
exit 0
fi
echo "" >> pr_body.md
echo "### 🚀 New Features" >> pr_body.md
grep -i '^feat' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
echo "" >> pr_body.md
echo "### 🐛 Bug Fixes" >> pr_body.md
grep -i '^bug' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
echo "" >> pr_body.md
echo "### 🔧 Improvements" >> pr_body.md
grep -i -E '^(perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
echo "" >> pr_body.md
echo "### 📝 Uncategorized PRs" >> pr_body.md
grep -v -i -E '^(feat|bug|perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
echo "" >> pr_body.md
echo "### 📦 Version" >> pr_body.md
echo "$VERSION" >> pr_body.md
- name: Create Pull Request
run: |
gh pr create \
--title "Release SDK v$VERSION" \
--body-file pr_body.md \
--head "$BRANCH" \
--base "$BASE_BRANCH"