1+ name : Create Release PR
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ version :
7+ description : ' New SDK version (e.g. 5.1.38 or 5.2.0-beta1)'
8+ type : string
9+ required : true
10+
11+ permissions :
12+ contents : write
13+ pull-requests : write
14+
15+ jobs :
16+ bump-version :
17+ runs-on : ubuntu-latest
18+
19+ env :
20+ VERSION : ${{ github.event.inputs.version }}
21+ BRANCH : rel/${{ github.event.inputs.version }}
22+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
23+
24+ steps :
25+ - name : Checkout repository
26+ uses : actions/checkout@v4
27+ with :
28+ fetch-depth : 0 # Ensure full history for git log
29+ fetch-tags : true
30+
31+ - name : Create release branch from main
32+ run : |
33+
34+ if git ls-remote --exit-code --heads origin "$BRANCH"; then
35+ echo "Deleting remote branch $BRANCH"
36+ git push origin --delete "$BRANCH"
37+ fi
38+
39+ git checkout -b "$BRANCH" origin/main
40+
41+ - name : Update SDK_VERSION in gradle.properties
42+ run : |
43+ sed -i "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" OneSignalSDK/gradle.properties
44+ sed -i "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" Examples/OneSignalDemo/gradle.properties
45+
46+ - name : Commit and Push changes
47+ run : |
48+ git config user.name "github-actions[bot]"
49+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
50+
51+ git commit -am "chore: bump SDK_VERSION to $VERSION"
52+ git push origin "$BRANCH"
53+
54+ - name : Fetch Last GitHub Release Tag
55+ id : fetch_last_release
56+ run : |
57+ echo "Fetching latest GitHub release tag..."
58+ LAST_TAG=$(gh release list --limit 1 --json tagName --jq '.[0].tagName')
59+
60+ if [[ -z "$LAST_TAG" ]]; then
61+ echo "❌ No previous release tag found. Cannot generate release notes."
62+ exit 0
63+ fi
64+
65+ echo "✅ Found last release tag: $LAST_TAG"
66+ echo "range=$LAST_TAG..HEAD" >> $GITHUB_OUTPUT
67+
68+ - name : Generate Release Notes from PR Titles
69+ id : generate_notes
70+ run : |
71+ echo "## 🔖 Auto-Generated Release Notes" > pr_body.md
72+ echo "" >> pr_body.md
73+
74+ if [[ "$VERSION" == *"alpha"* ]]; then
75+ CHANNEL="alpha"
76+ elif [[ "$VERSION" == *"beta"* ]]; then
77+ CHANNEL="beta"
78+ else
79+ CHANNEL="current"
80+ fi
81+
82+ echo "**Channels:** $CHANNEL" >> pr_body.md
83+ echo "" >> pr_body.md
84+
85+ RANGE="${{ steps.fetch_last_release.outputs.range }}"
86+ echo "📦 Commit range: $RANGE"
87+
88+ COMMITS=$(git log "$RANGE" --pretty=format:"%H" | sort -u)
89+
90+ if [[ -z "$COMMITS" ]]; then
91+ echo "❌ No commits found. Exiting."
92+ exit 0
93+ fi
94+
95+ > raw_titles.txt
96+ for SHA in $COMMITS; do
97+ PR_INFO=$(gh api "repos/${{ github.repository }}/commits/$SHA/pulls" \
98+ -H "Accept: application/vnd.github.groot-preview+json" 2>/dev/null)
99+
100+ TITLE=$(echo "$PR_INFO" | jq -r '.[0].title // empty')
101+ NUMBER=$(echo "$PR_INFO" | jq -r '.[0].number // empty')
102+
103+ if [[ -n "$TITLE" && -n "$NUMBER" ]]; then
104+ echo "$TITLE ([#$NUMBER](https://github.com/${{ github.repository }}/pull/$NUMBER))" >> raw_titles.txt
105+ echo "✅ $SHA → $TITLE (#$NUMBER)"
106+ else
107+ echo "⚠️ $SHA → No PR found"
108+ fi
109+ done
110+
111+ sort -fu raw_titles.txt > pr_titles.txt
112+
113+ if [[ ! -s pr_titles.txt ]]; then
114+ echo "❌ No PR titles found from commits. Exiting."
115+ exit 0
116+ fi
117+
118+ echo "" >> pr_body.md
119+ echo "### 🚀 New Features" >> pr_body.md
120+ grep -i '^feat' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
121+
122+ echo "" >> pr_body.md
123+ echo "### 🐛 Bug Fixes" >> pr_body.md
124+ grep -i '^bug' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
125+
126+ echo "" >> pr_body.md
127+ echo "### 🔧 Improvements" >> pr_body.md
128+ grep -i -E '^(perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
129+
130+ echo "" >> pr_body.md
131+ echo "### 📝 Uncategorized PRs" >> pr_body.md
132+ grep -v -i -E '^(feat|bug|perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
133+
134+ echo "" >> pr_body.md
135+ echo "### 📦 Version" >> pr_body.md
136+ echo "$VERSION" >> pr_body.md
137+
138+ - name : Create Pull Request
139+ run : |
140+ gh pr create \
141+ --title "Release SDK v$VERSION" \
142+ --body-file pr_body.md \
143+ --head "$BRANCH" \
144+ --base main
0 commit comments