Skip to content

Commit 35e921c

Browse files
authored
ci: add create-release-pr workflow action (#1084)
1 parent d26d108 commit 35e921c

File tree

4 files changed

+303
-70
lines changed

4 files changed

+303
-70
lines changed

.github/release-drafter.yml

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

.github/workflows/release-drafter.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)