Skip to content

Commit 8261eda

Browse files
committed
ci: add create-release-pr workflow action (#1084)
1 parent d26d108 commit 8261eda

File tree

6 files changed

+502
-72
lines changed

6 files changed

+502
-72
lines changed

.github/release-drafter.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 323 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,323 @@
1+
name: Create Release PR
2+
3+
on:
4+
# For making a release pr from android / ios sdk actions
5+
workflow_call:
6+
inputs:
7+
cordova_version:
8+
description: 'New Cordova Version (e.g., 5.2.15 or 5.2.15-beta.1)'
9+
required: true
10+
type: string
11+
android_version:
12+
description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.'
13+
required: false
14+
type: string
15+
ios_version:
16+
description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.'
17+
required: false
18+
type: string
19+
20+
# For making a release pr from cordova github actions
21+
workflow_dispatch:
22+
inputs:
23+
cordova_version:
24+
description: 'New Cordova Version (e.g., 5.2.15 or 5.2.15-beta.1)'
25+
required: true
26+
type: string
27+
android_version:
28+
description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.'
29+
required: false
30+
type: string
31+
ios_version:
32+
description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.'
33+
required: false
34+
type: string
35+
36+
jobs:
37+
update-version:
38+
runs-on: ubuntu-latest
39+
40+
env:
41+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
42+
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v5
46+
with:
47+
fetch-depth: 0
48+
fetch-tags: true
49+
50+
- name: Setup Bun
51+
uses: oven-sh/setup-bun@v2
52+
with:
53+
bun-version: latest
54+
55+
- name: Install
56+
run: bun install --frozen-lockfile
57+
58+
- name: Get release type
59+
id: release_type
60+
run: |
61+
NEW_VERSION="${{ inputs.cordova_version }}"
62+
if [[ "$NEW_VERSION" =~ -alpha ]]; then
63+
echo "release-type=Alpha" >> $GITHUB_OUTPUT
64+
elif [[ "$NEW_VERSION" =~ -beta ]]; then
65+
echo "release-type=Beta" >> $GITHUB_OUTPUT
66+
else
67+
echo "release-type=Current" >> $GITHUB_OUTPUT
68+
fi
69+
70+
- name: Get last release commit
71+
id: last_commit
72+
run: |
73+
CURRENT_VERSION=$(bun -e "console.log(require('./package.json').version)")
74+
LAST_RELEASE_DATE=$(git show -s --format=%cI "$CURRENT_VERSION")
75+
echo "date=$LAST_RELEASE_DATE" >> $GITHUB_OUTPUT
76+
77+
- name: Release branch name
78+
id: release_branch
79+
run: |
80+
# Omit alpha/beta version e.g. 5.2.15-beta.1 -> 5.2.15-beta
81+
BRANCH_VERSION=$(echo "${{ inputs.cordova_version }}" | sed 's/\(-[a-z]*\)\.[0-9]*$/\1/')
82+
echo "releaseBranch=rel/$BRANCH_VERSION" >> $GITHUB_OUTPUT
83+
84+
- name: Create release branch
85+
run: |
86+
releaseBranch="${{ steps.release_branch.outputs.releaseBranch }}"
87+
releaseType="${{ steps.release_type.outputs.release-type }}"
88+
89+
if ! git checkout -b "$releaseBranch" 2>/dev/null; then
90+
# Branch already exists
91+
if [[ "$releaseType" == "Current" ]]; then
92+
echo "Error: Release branch already exists for Current release"
93+
exit 1
94+
fi
95+
# For Alpha/Beta, use existing branch
96+
git checkout "$releaseBranch"
97+
fi
98+
git push -u origin "$releaseBranch"
99+
100+
- name: Get merged PRs
101+
id: get_prs
102+
uses: actions/github-script@v8
103+
with:
104+
script: |
105+
const lastReleaseDate = '${{ steps.last_commit.outputs.date }}';
106+
const releaseBranch = '${{ steps.release_branch.outputs.releaseBranch }}';
107+
108+
// Get the creation date of the release branch (when it diverged from main)
109+
const { data: branchInfo } = await github.rest.repos.getBranch({
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
branch: releaseBranch
113+
});
114+
const branchCreatedAt = branchInfo.commit.commit.committer.date;
115+
116+
// Get PRs merged to main since last release but BEFORE release branch was created
117+
const { data: prs } = await github.rest.pulls.list({
118+
owner: context.repo.owner,
119+
repo: context.repo.repo,
120+
state: 'closed',
121+
base: 'main',
122+
per_page: 100
123+
});
124+
125+
const mergedPrs = prs
126+
.filter(pr =>
127+
pr.merged_at &&
128+
new Date(pr.merged_at) > new Date(lastReleaseDate) &&
129+
new Date(pr.merged_at) <= new Date(branchCreatedAt) // Only before branch creation
130+
)
131+
.map(pr => ({
132+
number: pr.number,
133+
title: pr.title,
134+
}));
135+
core.setOutput('prs', JSON.stringify(mergedPrs));
136+
- name: Get current native SDK versions
137+
id: current_versions
138+
run: |
139+
# Extract current Android SDK version
140+
ANDROID_VERSION=$(grep -oP 'com\.onesignal:OneSignal:\K[0-9.]+' plugin.xml | head -1)
141+
142+
# Extract current iOS SDK version
143+
IOS_VERSION=$(grep -oP 'OneSignalXCFramework.*spec="\K[0-9.]+' plugin.xml | head -1)
144+
145+
echo "prev_android=$ANDROID_VERSION" >> $GITHUB_OUTPUT
146+
echo "prev_ios=$IOS_VERSION" >> $GITHUB_OUTPUT
147+
148+
# Cordova specific steps
149+
- name: Update Android SDK version
150+
if: inputs.android_version != ''
151+
run: |
152+
VERSION="${{ inputs.android_version }}"
153+
154+
# Validate version exists on GitHub
155+
RELEASE=$(curl -s -H "Authorization: token ${{ github.token }}" \
156+
"https://api.github.com/repos/OneSignal/OneSignal-Android-SDK/releases/tags/${VERSION}")
157+
158+
if echo "$RELEASE" | grep -q "\"id\""; then
159+
# Update plugin.xml with new version
160+
sed -i "s|<framework src=\"com\.onesignal:OneSignal:[^\"]*\" />|<framework src=\"com.onesignal:OneSignal:${VERSION}\" />|" plugin.xml
161+
echo "✓ Updated plugin.xml with Android SDK ${VERSION}"
162+
else
163+
echo "✗ Android SDK version ${VERSION} not found"
164+
exit 1
165+
fi
166+
167+
- name: Update iOS SDK version
168+
if: inputs.ios_version != ''
169+
run: |
170+
VERSION="${{ inputs.ios_version }}"
171+
172+
# Validate version exists on GitHub
173+
RELEASE=$(curl -s -H "Authorization: token ${{ github.token }}" \
174+
"https://api.github.com/repos/OneSignal/OneSignal-iOS-SDK/releases/tags/${VERSION}")
175+
176+
if echo "$RELEASE" | grep -q "\"id\""; then
177+
# Update plugin.xml with new version
178+
sed -i "s|<pod name=\"OneSignalXCFramework\" spec=\"[^\"]*\" />|<pod name=\"OneSignalXCFramework\" spec=\"${VERSION}\" />|" plugin.xml
179+
echo "✓ Updated plugin.xml with iOS SDK ${VERSION}"
180+
181+
# Need to clear the Podfile.lock to force a re-install of the framework
182+
rm -f example/IonicCapOneSignal/ios/App/Podfile.lock
183+
else
184+
echo "✗ iOS SDK version ${VERSION} not found"
185+
exit 1
186+
fi
187+
188+
- name: Capacitor update
189+
run: |
190+
bun link
191+
cd example/IonicCapOneSignal
192+
bun install --frozen-lockfile
193+
bun run build
194+
bunx cap sync || exit 1
195+
git add .
196+
197+
- name: Update sdk version
198+
run: |
199+
NEW_VERSION="${{ inputs.cordova_version }}"
200+
git config user.name "github-actions[bot]"
201+
git config user.email "github-actions[bot]@users.noreply.github.com"
202+
203+
# Convert version format for OneSignal wrapper (e.g., 5.2.15 -> 050215)
204+
# For pre-releases, extract base version first (e.g., 5.2.15-alpha.1 -> 5.2.15)
205+
BASE_VERSION=$(echo "$NEW_VERSION" | sed 's/-[a-z].*//')
206+
WRAPPER_VERSION=$(echo "$BASE_VERSION" | awk -F'.' '{printf "%02d%02d%02d", $1, $2, $3}')
207+
208+
# Update package.json version
209+
npm pkg set version="$NEW_VERSION"
210+
211+
# Update plugin.xml cordova plugin version (target <plugin> element specifically)
212+
sed -i 's|<plugin \(xmlns="[^"]*" xmlns:android="[^"]*" id="[^"]*"\) version="[^"]*"|<plugin \1 version="'"$NEW_VERSION"'"|' plugin.xml
213+
214+
# Update OneSignalPush.java wrapper version
215+
sed -i "s/OneSignalWrapper\.setSdkVersion(\"[^\"]*\")/OneSignalWrapper.setSdkVersion(\"$WRAPPER_VERSION\")/g" src/android/com/onesignal/cordova/OneSignalPush.java
216+
217+
# Update OneSignalPush.m wrapper version
218+
sed -i "s/OneSignalWrapper\.sdkVersion = @\"[^\"]*\"/OneSignalWrapper.sdkVersion = @\"$WRAPPER_VERSION\"/g" src/ios/OneSignalPush.m
219+
220+
git add package.json plugin.xml src/android/com/onesignal/cordova/OneSignalPush.java src/ios/OneSignalPush.m
221+
222+
git commit -m "Release $NEW_VERSION"
223+
git push
224+
225+
- name: Document native sdk changes
226+
id: native_deps
227+
run: |
228+
# Get the current plugin.xml
229+
CURRENT_PLUGIN=$(cat plugin.xml)
230+
231+
# Extract current Android SDK version
232+
ANDROID_VERSION=$(echo "$CURRENT_PLUGIN" | grep -oP 'com\.onesignal:OneSignal:\K[0-9.]+' | head -1)
233+
PREVIOUS_ANDROID="${{ steps.current_versions.outputs.prev_android }}"
234+
235+
# Extract current iOS SDK version
236+
IOS_VERSION=$(echo "$CURRENT_PLUGIN" | grep -oP 'OneSignalXCFramework.*spec="\K[0-9.]+' | head -1)
237+
PREVIOUS_IOS="${{ steps.current_versions.outputs.prev_ios }}"
238+
239+
# Build output for native dependency changes
240+
NATIVE_UPDATES=""
241+
if [[ "$ANDROID_VERSION" != "$PREVIOUS_ANDROID" && ! -z "$PREVIOUS_ANDROID" ]]; then
242+
printf -v NATIVE_UPDATES '%sANDROID_UPDATE=true\nANDROID_FROM=%s\nANDROID_TO=%s\n' "$NATIVE_UPDATES" "$PREVIOUS_ANDROID" "$ANDROID_VERSION"
243+
fi
244+
245+
if [[ "$IOS_VERSION" != "$PREVIOUS_IOS" && ! -z "$PREVIOUS_IOS" ]]; then
246+
printf -v NATIVE_UPDATES '%sIOS_UPDATE=true\nIOS_FROM=%s\nIOS_TO=%s\n' "$NATIVE_UPDATES" "$PREVIOUS_IOS" "$IOS_VERSION"
247+
fi
248+
249+
# Output the variables
250+
echo "$NATIVE_UPDATES" >> $GITHUB_OUTPUT
251+
252+
- name: Generate release notes
253+
id: release_notes
254+
uses: actions/github-script@v8
255+
with:
256+
script: |
257+
// Trim whitespace from PR titles
258+
const prs = JSON.parse('${{ steps.get_prs.outputs.prs }}').map(pr => ({
259+
...pr,
260+
title: pr.title.trim()
261+
}));
262+
263+
// Categorize PRs
264+
const features = prs.filter(pr => /^feat/i.test(pr.title));
265+
const fixes = prs.filter(pr => /^fix/i.test(pr.title));
266+
const improvements = prs.filter(pr => /^(perf|refactor|chore)/i.test(pr.title));
267+
268+
// Helper function to build section
269+
const buildSection = (title, prs) => {
270+
if (prs.length === 0) return '';
271+
let section = `### ${title}\n\n`;
272+
prs.forEach(pr => {
273+
section += `- ${pr.title} (#${pr.number})\n`;
274+
});
275+
return section + '\n';
276+
};
277+
278+
let releaseNotes = `Channels: ${{ steps.release_type.outputs.release-type }}\n\n`;
279+
releaseNotes += buildSection('🚀 New Features', features);
280+
releaseNotes += buildSection('🐛 Bug Fixes', fixes);
281+
releaseNotes += buildSection('✨ Improvements', improvements);
282+
283+
// Check for native dependency changes
284+
const hasAndroidUpdate = '${{ steps.native_deps.outputs.ANDROID_UPDATE }}' === 'true';
285+
const hasIosUpdate = '${{ steps.native_deps.outputs.IOS_UPDATE }}' === 'true';
286+
287+
if (hasAndroidUpdate || hasIosUpdate) {
288+
releaseNotes += '\n### 🛠️ Native Dependency Updates\n\n';
289+
if (hasAndroidUpdate) {
290+
releaseNotes += `- Update Android SDK from ${{ steps.native_deps.outputs.ANDROID_FROM }} to ${{ steps.native_deps.outputs.ANDROID_TO }}\n`;
291+
releaseNotes += `- See [release notes](https://github.com/OneSignal/OneSignal-Android-SDK/releases) for full details\n`;
292+
}
293+
if (hasIosUpdate) {
294+
releaseNotes += `- Update iOS SDK from ${{ steps.native_deps.outputs.IOS_FROM }} to ${{ steps.native_deps.outputs.IOS_TO }}\n`;
295+
releaseNotes += `- See [release notes](https://github.com/OneSignal/OneSignal-iOS-SDK/releases) for full details\n`;
296+
}
297+
releaseNotes += '\n';
298+
}
299+
300+
core.setOutput('notes', releaseNotes);
301+
302+
- name: Create release PR
303+
run: |
304+
NEW_VERSION="${{ inputs.cordova_version }}"
305+
RELEASE_TYPE="${{ steps.release_type.outputs.release-type }}"
306+
307+
# Determine base branch based on release type
308+
if [[ "$RELEASE_TYPE" == "Current" ]]; then
309+
BASE_BRANCH="main"
310+
else
311+
BASE_BRANCH="${{ steps.release_branch.outputs.releaseBranch }}"
312+
fi
313+
314+
# Write release notes to file to avoid shell interpretation
315+
cat > release_notes.md << 'EOF'
316+
${{ steps.release_notes.outputs.notes }}
317+
EOF
318+
319+
gh pr create \
320+
--title "Release $NEW_VERSION" \
321+
--body-file release_notes.md \
322+
--base "$BASE_BRANCH" \
323+
--reviewer fadi-george,sherwinski,jkasten2

.github/workflows/lint-pr-title.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
lint:
13+
lint-pr-title:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: amannn/action-semantic-pull-request@v6

0 commit comments

Comments
 (0)