Skip to content

Commit fbf87da

Browse files
author
AR Abdul Azeez
committed
Cleaned up based on feedback
1 parent 8961f4f commit fbf87da

File tree

1 file changed

+39
-57
lines changed

1 file changed

+39
-57
lines changed
Lines changed: 39 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Create Release PR
22

33
on:
4+
5+
push:
6+
branches:
7+
- automated-release
8+
49
workflow_dispatch:
510
inputs:
611
version:
@@ -16,69 +21,52 @@ jobs:
1621
bump-version:
1722
runs-on: ubuntu-latest
1823

24+
env:
25+
VERSION: ${{ github.event.inputs.version }}
26+
BRANCH: rel/${{ github.event.inputs.version }}
27+
1928
steps:
2029
- name: Checkout repository
21-
uses: actions/checkout@v3
22-
23-
- name: Install GitHub CLI
24-
run: sudo apt-get install -y gh
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0 # Ensure full history for git log
33+
fetch-tags: true
2534

2635
- name: Authenticate GitHub CLI
2736
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
2837

29-
- name: Create release branch from main (delete it first, it it already exists)
38+
- name: Create release branch from main
3039
run: |
31-
VERSION="${{ github.event.inputs.version }}"
32-
BRANCH="rel/$VERSION"
33-
34-
git fetch origin
3540
36-
# Delete local branch if it exists
37-
if git show-ref --quiet refs/heads/"$BRANCH"; then
38-
echo "Deleting local branch $BRANCH"
39-
git branch -D "$BRANCH"
40-
fi
41-
42-
# Delete remote branch if it exists (optional)
4341
if git ls-remote --exit-code --heads origin "$BRANCH"; then
4442
echo "Deleting remote branch $BRANCH"
4543
git push origin --delete "$BRANCH"
4644
fi
4745
48-
# Create branch fresh from origin/main
4946
git checkout -b "$BRANCH" origin/main
5047
51-
- name: Update gradle.properties files with SDK_VERSION
48+
- name: Update SDK_VERSION in gradle.properties
5249
run: |
53-
VERSION="${{ github.event.inputs.version }}"
54-
echo "Updating SDK_VERSION to $VERSION"
55-
5650
sed -i.bak "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" OneSignalSDK/gradle.properties
5751
rm OneSignalSDK/gradle.properties.bak
5852
5953
sed -i.bak "s/^SDK_VERSION=.*/SDK_VERSION=$VERSION/" Examples/OneSignalDemo/gradle.properties
6054
rm Examples/OneSignalDemo/gradle.properties.bak
61-
62-
- name: Configure Git and commit changes
63-
run: |
64-
VERSION="${{ github.event.inputs.version }}"
65-
BRANCH="rel/$VERSION"
6655
56+
- name: Commit and Push changes
57+
run: |
6758
git config user.name "github-actions[bot]"
6859
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
6960
7061
git commit -am "chore: bump SDK_VERSION to $VERSION"
7162
git push origin "$BRANCH"
72-
73-
- name: Generate Release Notes from Commits
63+
64+
- name: Generate Release Notes from PR titles
7465
id: generate_notes
7566
run: |
7667
echo "## 🔖 Auto-Generated Release Notes" > pr_body.md
7768
echo "" >> pr_body.md
7869
79-
VERSION="${{ github.event.inputs.version }}"
80-
81-
# Determine release channel
8270
if [[ "$VERSION" == *"alpha"* ]]; then
8371
CHANNEL="alpha"
8472
elif [[ "$VERSION" == *"beta"* ]]; then
@@ -90,54 +78,48 @@ jobs:
9078
echo "**Channels:** $CHANNEL" >> pr_body.md
9179
echo "" >> pr_body.md
9280
93-
git fetch origin main
81+
LAST_REL_MERGE_SHA=$(git log origin/main --merges --pretty=format:"%H %s" | grep -m1 "Merge pull request" | grep "from rel/" | cut -d' ' -f1)
9482
95-
# Find last release merge commit (merge from rel/*)
96-
LAST_RELEASE_COMMIT=$(git log origin/main --merges --pretty=format:"%H %s" \
97-
| grep -m 1 -E "Merge pull request.*from rel/" \
98-
| cut -d' ' -f1)
83+
if [[ -z "$LAST_REL_MERGE_SHA" ]]; then
84+
echo "⚠️ Could not find previous rel/* merge. Using fallback HEAD~50"
85+
RANGE="HEAD~50..HEAD"
86+
else
87+
echo "✅ Last rel/* merge SHA: $LAST_REL_MERGE_SHA"
88+
RANGE="$LAST_REL_MERGE_SHA..HEAD"
89+
fi
9990
100-
echo "Last release merge commit: $LAST_RELEASE_COMMIT"
91+
PR_TITLES=$(git log $RANGE --pretty=format:"%s" | grep -E '^Merge pull request' | awk -F'"' '{print $2}')
10192
102-
COMMITS=$(git log $LAST_RELEASE_COMMIT..HEAD --pretty=format:"%s")
93+
if [[ -z "$PR_TITLES" ]]; then
94+
echo "❌ No merged PRs found since last release. Exiting safely."
95+
exit 0
96+
fi
10397
104-
echo "$COMMITS" > all_commits.txt
98+
echo "$PR_TITLES" > pr_titles.txt
10599
106100
echo "### 🚀 New Features" >> pr_body.md
107-
grep -E '^feat' all_commits.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
101+
grep -i '^feat' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
108102
109103
echo "" >> pr_body.md
110104
echo "### 🐛 Bug Fixes" >> pr_body.md
111-
grep -E '^bug' all_commits.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
105+
grep -i '^bug' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
112106
113107
echo "" >> pr_body.md
114108
echo "### 🔧 Improvements" >> pr_body.md
115-
grep -E '^(perf|refactor)' all_commits.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
109+
grep -i -E '^(perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
116110
117111
echo "" >> pr_body.md
118-
echo "### 📝 Uncategorized Commits" >> pr_body.md
119-
grep -v -E '^(feat|bug|perf|refactor)' all_commits.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
112+
echo "### 📝 Uncategorized PRs" >> pr_body.md
113+
grep -vi -E '^(feat|bug|perf|refactor)' pr_titles.txt | sed 's/^/- /' >> pr_body.md || echo "- _None_" >> pr_body.md
120114
121115
echo "" >> pr_body.md
122116
echo "### 📦 Version" >> pr_body.md
123117
echo "$VERSION" >> pr_body.md
124-
125-
echo "" >> pr_body.md
126-
127-
# Final fallback: check if any commits were found at all
128-
if [[ -z "$COMMITS" ]]; then
129-
echo "### ⚠️ No commits found" >> pr_body.md
130-
echo "_No commits were found since the last release merge._" >> pr_body.md
131-
echo "Release manager to verify and add appropriate release notes." >> pr_body.md
132-
fi
133118
134119
- name: Create Pull Request
135120
run: |
136-
VERSION="${{ github.event.inputs.version }}"
137-
BRANCH="rel/$VERSION"
138-
139121
gh pr create \
140122
--title "Release SDK v$VERSION" \
141123
--body-file pr_body.md \
142124
--head "$BRANCH" \
143-
--base main
125+
--base main

0 commit comments

Comments
 (0)