1+ name : Version Bump PR
2+
3+ on :
4+ push :
5+ branches :
6+ - master
7+ - staging
8+ workflow_dispatch :
9+
10+ permissions :
11+ contents : write
12+ pull-requests : write
13+
14+ jobs :
15+ version-bump :
16+ name : Prepare Release Branch
17+ runs-on : ubuntu-latest
18+ if : " !contains(github.event.head_commit.message, '[skip ci]')"
19+
20+ env :
21+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
22+
23+ steps :
24+ - name : Checkout code
25+ uses : actions/checkout@v4
26+ with :
27+ fetch-depth : 0
28+ token : ${{ secrets.GITHUB_TOKEN }}
29+
30+ - name : Setup Node.js
31+ uses : actions/setup-node@v4
32+ with :
33+ node-version : ' 20'
34+
35+ - name : Install dependencies
36+ run : npm install -g semantic-release @semantic-release/exec @semantic-release/changelog @semantic-release/git conventional-changelog-conventionalcommits
37+
38+ - name : Configure Git
39+ run : |
40+ git config user.name "github-actions[bot]"
41+ git config user.email "github-actions[bot]@users.noreply.github.com"
42+
43+ - name : Extract current version
44+ id : current_version
45+ run : |
46+ # Read version from gradle.properties
47+ CURRENT_VERSION=$(grep "^GLOBAL_VERSION_NAME=" gradle.properties | cut -d'=' -f2)
48+ echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
49+ echo "Current version: $CURRENT_VERSION"
50+
51+ - name : Get next version
52+ id : get_version
53+ run : |
54+ CURRENT_VERSION="${{ steps.current_version.outputs.current_version }}"
55+
56+ # Run dry-run
57+ npx semantic-release --dry-run --no-ci > semantic-output.txt 2>&1 || true
58+
59+ # Parse output
60+ NEXT_VERSION=$(grep "The next release version is" semantic-output.txt | sed -E 's/.*The next release version is ([0-9]+\.[0-9]+\.[0-9]+).*/\1/' | head -1)
61+
62+ if [ -z "$NEXT_VERSION" ]; then
63+ echo "::notice::No new version needed."
64+ echo "should_create_pr=false" >> $GITHUB_OUTPUT
65+ exit 0
66+ fi
67+
68+ if [ "$NEXT_VERSION" = "$CURRENT_VERSION" ]; then
69+ echo "::notice::Version already matches."
70+ echo "should_create_pr=false" >> $GITHUB_OUTPUT
71+ exit 0
72+ fi
73+
74+ echo "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
75+ echo "should_create_pr=true" >> $GITHUB_OUTPUT
76+ echo "release_branch=release/${NEXT_VERSION}" >> $GITHUB_OUTPUT
77+ echo "::notice::Bumping version: $CURRENT_VERSION -> $NEXT_VERSION"
78+
79+ - name : Check if release branch exists
80+ if : steps.get_version.outputs.should_create_pr == 'true'
81+ id : check_branch
82+ run : |
83+ RELEASE_BRANCH="${{ steps.get_version.outputs.release_branch }}"
84+ if git ls-remote --exit-code --heads origin "$RELEASE_BRANCH" >/dev/null 2>&1; then
85+ echo "branch_exists=true" >> $GITHUB_OUTPUT
86+ exit 0
87+ fi
88+ echo "branch_exists=false" >> $GITHUB_OUTPUT
89+
90+ - name : Create release branch
91+ if : steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
92+ run : |
93+ BRANCH_NAME="${{ steps.get_version.outputs.release_branch }}"
94+ git checkout -b "$BRANCH_NAME"
95+ echo "branch_name=$BRANCH_NAME" >> $GITHUB_ENV
96+
97+ - name : Update Gradle version
98+ if : steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
99+ run : |
100+ VERSION="${{ steps.get_version.outputs.next_version }}"
101+
102+ echo "Running bump_version.sh..."
103+ chmod +x ./scripts/bump_version.sh
104+ ./scripts/bump_version.sh "$VERSION"
105+
106+ grep "^GLOBAL_VERSION_NAME=" gradle.properties
107+
108+ - name : Generate Changelog
109+ if : steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
110+ run : |
111+ npx semantic-release --no-ci 2>&1 | tee release-output.txt || true
112+
113+ - name : Commit changes
114+ if : steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
115+ run : |
116+ VERSION="${{ steps.get_version.outputs.next_version }}"
117+
118+ git add gradle.properties CHANGELOG.md
119+ git commit -m "chore(release): prepare version ${VERSION}"
120+ echo "Committed version bump and changelog."
121+
122+ - name : Push and Create PR
123+ if : steps.get_version.outputs.should_create_pr == 'true' && steps.check_branch.outputs.branch_exists == 'false'
124+ run : |
125+ VERSION="${{ steps.get_version.outputs.next_version }}"
126+ BRANCH_NAME="${{ env.branch_name }}"
127+ BASE_BRANCH="${{ github.ref_name }}"
128+
129+ git push origin "$BRANCH_NAME"
130+
131+ if [ -f CHANGELOG.md ]; then
132+ CHANGELOG_EXCERPT=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$ d' || echo "See CHANGELOG.md")
133+ else
134+ CHANGELOG_EXCERPT="See CHANGELOG.md for details"
135+ fi
136+
137+ # We construct the body string first to avoid multiline string issues in the CLI command
138+ PR_BODY="Automated release PR
139+
140+ **Version:** \`$VERSION\`
141+
142+ ## Changes
143+ $CHANGELOG_EXCERPT
144+
145+ ---
146+ *Merge this PR to publish the release.*"
147+
148+ gh pr create \
149+ --base "$BASE_BRANCH" \
150+ --head "$BRANCH_NAME" \
151+ --title "chore(release): $VERSION" \
152+ --body "$PR_BODY"
153+
154+ # Add release label
155+ PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --base "$BASE_BRANCH" --json number --jq '.[0].number')
156+ gh pr edit "$PR_NUMBER" --add-label "release"
0 commit comments