Skip to content

Create Release PR

Create Release PR #4

name: Create Release PR
on:
workflow_dispatch:
inputs:
version:
description: 'New SDK version (e.g. 5.1.38 or 5.2.0-beta1)'
type: string
required: true
permissions:
contents: write
pull-requests: write
jobs:
bump-version:
runs-on: ubuntu-latest
env:
VERSION: ${{ github.event.inputs.version }}
BRANCH: rel/${{ github.event.inputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensure full history for git log
fetch-tags: true
- name: Authenticate GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Create release branch from main
run: |
if git ls-remote --exit-code --heads origin "$BRANCH"; then
echo "Deleting remote branch $BRANCH"
git push origin --delete "$BRANCH"
fi
git checkout -b "$BRANCH" origin/main
- name: Update SDK_VERSION in gradle.properties
run: |
sed -i.bak "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" OneSignalSDK/gradle.properties
rm OneSignalSDK/gradle.properties.bak
sed -i.bak "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" Examples/OneSignalDemo/gradle.properties
rm Examples/OneSignalDemo/gradle.properties.bak
- name: Commit and Push changes
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
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
if: steps.fetch_last_release.outputs.range != ''
run: |
RANGE: ${{ steps.fetch_last_release.outputs.range }}
echo "## 🔖 Auto-Generated Release Notes" > pr_body.md
echo "" >> pr_body.md
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
echo "Using commit range: $RANGE"
PR_TITLES=$(git log "$RANGE" --pretty=format:"%s" | grep -E '^Merge pull request' | awk -F'"' '{print $2}')
if [[ -z "$PR_TITLES" ]]; then
echo "❌ No merged PRs found since last release. Exiting safely."
exit 0
fi
echo "$PR_TITLES" > pr_titles.txt
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 -vi -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 main