Skip to content

Commit 47a982f

Browse files
authored
Merge pull request #1381 from OneSignal/fadi/sdk-2943-create-release-workflow
chore: add a create pr workflow
2 parents c8d81da + ea501a3 commit 47a982f

2 files changed

Lines changed: 129 additions & 42 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Create Release PR
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
bump-version:
8+
runs-on: ubuntu-latest
9+
10+
env:
11+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v6
16+
with:
17+
fetch-depth: 0
18+
fetch-tags: true
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v5
22+
with:
23+
node-version-file: '.nvmrc'
24+
25+
- name: Get current SDK version
26+
id: current_version
27+
run: |
28+
CURRENT_VERSION=$(node -p "require('./package.json').config.sdkVersion")
29+
echo "current=$CURRENT_VERSION" >> $GITHUB_OUTPUT
30+
31+
- name: Get last release commit
32+
id: last_commit
33+
run: |
34+
LAST_RELEASE_TAG="${{ steps.current_version.outputs.current }}"
35+
LAST_RELEASE_COMMIT=$(git rev-parse "$LAST_RELEASE_TAG")
36+
echo "commit=$LAST_RELEASE_COMMIT" >> $GITHUB_OUTPUT
37+
38+
- name: Get merged PRs since last release
39+
id: get_prs
40+
uses: actions/github-script@v7
41+
with:
42+
script: |
43+
const lastReleaseCommit = '${{ steps.last_commit.outputs.commit }}';
44+
45+
// Get merged PRs
46+
const { data: prs } = await github.rest.pulls.list({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
state: 'closed',
50+
base: 'main',
51+
per_page: 100
52+
});
53+
54+
// Filter and process PRs
55+
const mergedPrs = prs
56+
.filter(pr => pr.merged_at && pr.merge_commit_sha !== lastReleaseCommit)
57+
.map(pr => ({
58+
number: pr.number,
59+
title: pr.title,
60+
}));
61+
core.setOutput('prs', JSON.stringify(mergedPrs));
62+
63+
const hasFeatures = mergedPrs.some(pr => /^feat/i.test(pr.title));
64+
core.setOutput('isFeature', hasFeatures);
65+
66+
- name: Calculate new version
67+
id: new_version
68+
run: |
69+
CURRENT="${{ steps.current_version.outputs.current }}"
70+
PRS='${{ steps.get_prs.outputs.prs }}'
71+
IS_FEATURE='${{ steps.get_prs.outputs.isFeature }}'
72+
73+
MAJOR=${CURRENT:0:2}
74+
MINOR=${CURRENT:2:2}
75+
PATCH=${CURRENT:4:2}
76+
77+
if [[ "$IS_FEATURE" == "true" ]]; then
78+
MINOR=$(printf "%02d" $((10#$MINOR + 1)))
79+
PATCH="00"
80+
else
81+
PATCH=$(printf "%02d" $((10#$PATCH + 1)))
82+
fi
83+
84+
NEW_VERSION="${MAJOR}${MINOR}${PATCH}"
85+
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
86+
87+
- name: Create release branch on main
88+
run: |
89+
git checkout -b rel/${{ steps.new_version.outputs.version }}
90+
git push -u origin rel/${{ steps.new_version.outputs.version }}
91+
92+
- name: Generate release notes
93+
id: release_notes
94+
uses: actions/github-script@v7
95+
with:
96+
script: |
97+
const prs = JSON.parse('${{ steps.get_prs.outputs.prs }}');
98+
99+
// Categorize PRs
100+
const features = prs.filter(pr => /^feat/i.test(pr.title));
101+
const fixes = prs.filter(pr => /^fix/i.test(pr.title));
102+
const improvements = prs.filter(pr => /^(perf|refactor|chore)/i.test(pr.title));
103+
104+
// Helper function to build section
105+
const buildSection = (title, prs) => {
106+
if (prs.length === 0) return '';
107+
let section = `### ${title}\n\n`;
108+
prs.forEach(pr => {
109+
section += `- ${pr.title} (#${pr.number})\n`;
110+
});
111+
return section + '\n';
112+
};
113+
114+
let releaseNotes = '';
115+
releaseNotes += buildSection('🚀 New Features', features);
116+
releaseNotes += buildSection('🐛 Bug Fixes', fixes);
117+
releaseNotes += buildSection('🔧 Improvements', improvements);
118+
119+
core.setOutput('notes', releaseNotes);
120+
121+
- name: Create release PR
122+
run: |
123+
NEW_VERSION="${{ steps.new_version.outputs.version }}"
124+
RELEASE_NOTES="${{ steps.release_notes.outputs.notes }}"
125+
126+
gh pr create \
127+
--title "Release $NEW_VERSION" \
128+
--body "$RELEASE_NOTES" \
129+
--base main

.github/workflows/release-drafter.yml

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

0 commit comments

Comments
 (0)