1- name : Android Release
1+ name : Create Release PR
22
33on :
44 push :
55 branches :
6- - master
6+ - test/dry-run # <--- Change this from 'master'
7+ # - master
78
89permissions :
910 contents : write
10- issues : write
1111 pull-requests : write
1212
1313jobs :
14- release :
15- name : Release
16- # Prevent infinite loops: Don't run if the commit is already a release commit
17- if : " !contains(github.event.head_commit.message, 'chore(release):')"
14+ create- release-pr :
15+ name : Create Release PR
16+ # Skip if the commit is already a release commit to prevent infinite loops
17+ if : github.event_name == 'push' && !contains(github.event.head_commit.message, 'chore(release):')
1818 runs-on : ubuntu-latest
1919 steps :
20- - name : Checkout Code
20+ - name : Checkout
2121 uses : actions/checkout@v4
2222 with :
23- fetch-depth : 0 # Important: Fetch all history for semantic-release to analyze commits
23+ fetch-depth : 0
2424 token : ${{ secrets.GITHUB_TOKEN }}
2525
2626 - name : Setup Node.js
2727 uses : actions/setup-node@v4
2828 with :
2929 node-version : 20
3030
31- - name : Setup Java
32- uses : actions/setup-java@v3
33- with :
34- distribution : ' temurin'
35- java-version : ' 17'
31+ # Clean Repo Approach: Install tools globally so we don't need package.json
32+ - name : Install dependencies
33+ run : npm install -g semantic-release @semantic-release/exec @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits
3634
3735 - name : Make Script Executable
3836 run : chmod +x ./scripts/bump_version.sh
3937
40- - name : Install Release Tools
38+ - name : Configure Git
39+ run : |
40+ git config user.name "semantic-release-bot"
41+ git config user.email "semantic-release-bot@github.com"
42+
43+ - name : Analyze commits and prepare release
44+ id : prepare-release
45+ env :
46+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4147 run : |
42- npm install -g semantic-release \
43- @semantic-release/git \
44- @semantic-release/changelog \
45- @semantic-release/exec \
46- @semantic-release/github \
47- conventional-changelog-conventionalcommits
48-
49- - name : Run Semantic Release
48+ # 1. Run dry-run to calculate version (without modifying files yet)
49+ npx semantic-release --dry-run --no-ci > dry-run.log 2>&1 || true
50+
51+ # 2. Extract the new version number from the logs
52+ NEW_VERSION=$(grep "The next release version is" dry-run.log | sed -n 's/.*The next release version is \([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1)
53+
54+ if [ -z "$NEW_VERSION" ]; then
55+ echo "No release needed."
56+ echo "skip=true" >> $GITHUB_OUTPUT
57+ exit 0
58+ fi
59+
60+ RELEASE_BRANCH="release/v${NEW_VERSION}"
61+
62+ # 3. Check if this release branch already exists
63+ if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
64+ echo "Branch $RELEASE_BRANCH already exists."
65+ echo "skip=true" >> $GITHUB_OUTPUT
66+ exit 0
67+ fi
68+
69+ echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
70+ echo "release_branch=$RELEASE_BRANCH" >> $GITHUB_OUTPUT
71+ echo "skip=false" >> $GITHUB_OUTPUT
72+
73+ - name : Create release branch and commit changes
74+ if : steps.prepare-release.outputs.skip != 'true'
5075 env :
76+ NEW_VERSION : ${{ steps.prepare-release.outputs.new_version }}
77+ RELEASE_BRANCH : ${{ steps.prepare-release.outputs.release_branch }}
5178 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
52- # We run 'npx semantic-release' which uses the config from .releaserc.json
53- run : npx semantic-release
79+ run : |
80+ # Create the temporary release branch
81+ git checkout -b "$RELEASE_BRANCH"
82+
83+ # Run semantic-release for real.
84+ # Because of our .releaserc.json, this will:
85+ # 1. Run bump_version.sh (Update Gradle files)
86+ # 2. Generate CHANGELOG.md
87+ npx semantic-release --no-ci
88+
89+ # Manually stage the changed files
90+ # Manually stage the changed files
91+ # We now update gradle.properties instead of build.gradle
92+ git add gradle.properties CHANGELOG.md
93+ # Verify there are changes
94+ if git diff --staged --quiet; then
95+ echo "Error : No changes generated."
96+ exit 1
97+ fi
98+
99+ # Commit and Push
100+ git commit -m "chore(release) : $NEW_VERSION [skip ci]"
101+ git push -u origin "$RELEASE_BRANCH"
102+
103+ - name : Create Pull Request
104+ if : steps.prepare-release.outputs.skip != 'true'
105+ env :
106+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
107+ NEW_VERSION : ${{ steps.prepare-release.outputs.new_version }}
108+ RELEASE_BRANCH : ${{ steps.prepare-release.outputs.release_branch }}
109+ run : |
110+ gh pr create \
111+ --base master \
112+ --head "$RELEASE_BRANCH" \
113+ --title "chore(release): $NEW_VERSION" \
114+ --body "Automated release PR for **v$NEW_VERSION**. Merge this PR to trigger the official release (Tag & JitPack)."
0 commit comments