11name : Update Stable Branch
22
33on :
4- pull_request :
5- types : [closed]
4+ push :
65 branches :
76 - main
7+
88permissions :
99 contents : write
1010
1111jobs :
12- update-stable :
13- if : github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'stable-release')
12+ update-commit :
13+ if : contains(github.event.head_commit.message, '#release')
14+ runs-on : ubuntu-latest
15+
16+ steps :
17+ - name : Checkout the code
18+ uses : actions/checkout@v3
19+
20+ - name : Get the latest commit hash
21+ run : echo "COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
22+
23+ - name : Update commit file
24+ run : |
25+ echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
26+
27+ - name : Commit and push the update
28+ run : |
29+ git config --global user.name "github-actions[bot]"
30+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
31+ git add app/commit.json
32+ git commit -m "chore: update commit hash to $COMMIT_HASH"
33+ git push
34+ prepare-release :
35+ needs : update-commit
36+ if : contains(github.event.head_commit.message, '#release')
1437 runs-on : ubuntu-latest
15- permissions :
16- contents : write
17- pull-requests : read
1838
1939 steps :
20- - uses : actions/checkout@v3
40+ - uses : actions/checkout@v4
41+ with :
42+ fetch-depth : 0
2143
2244 - name : Configure Git
2345 run : |
4971 restore-keys : |
5072 ${{ runner.os }}-pnpm-store-
5173
52- - name : Determine Version Bump
53- id : version_bump
54- run : |
55- if [[ "${{ contains(github.event.pull_request.labels.*.name, 'major') }}" == "true" ]]; then
56- echo "bump=major" >> $GITHUB_OUTPUT
57- elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'minor') }}" == "true" ]]; then
58- echo "bump=minor" >> $GITHUB_OUTPUT
59- else
60- echo "bump=patch" >> $GITHUB_OUTPUT
61- fi
62-
6374 - name : Get Current Version
6475 id : current_version
6576 run : |
6980 - name : Install semver
7081 run : pnpm add -g semver
7182
83+ - name : Determine Version Bump
84+ id : version_bump
85+ run : |
86+ COMMIT_MSG="${{ github.event.head_commit.message }}"
87+ if [[ $COMMIT_MSG =~ "#release:major" ]]; then
88+ echo "bump=major" >> $GITHUB_OUTPUT
89+ elif [[ $COMMIT_MSG =~ "#release:minor" ]]; then
90+ echo "bump=minor" >> $GITHUB_OUTPUT
91+ else
92+ echo "bump=patch" >> $GITHUB_OUTPUT
93+ fi
94+
7295 - name : Bump Version
7396 id : bump_version
7497 run : |
@@ -158,32 +181,30 @@ jobs:
158181 echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
159182 echo "EOF" >> $GITHUB_OUTPUT
160183
161- - name : Commit Version Update
184+ - name : Commit and Tag Release
162185 run : |
163186 git pull
164187 git add package.json pnpm-lock.yaml changelog.md
165- git commit -m "chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
188+ git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
189+ git tag "v${{ steps.bump_version.outputs.new_version }}"
166190 git push
191+ git push --tags
167192
168193 - name : Update Stable Branch
169194 run : |
170- # Ensure stable branch exists
171- git checkout stable 2>/dev/null || git checkout -b stable
172- git merge main --no-ff -m "chore: merge main into stable for version ${{ steps.bump_version.outputs.new_version }}"
173- git push --set-upstream origin stable
195+ if ! git checkout stable 2>/dev/null; then
196+ echo "Creating new stable branch..."
197+ git checkout -b stable
198+ fi
199+ git merge main --no-ff -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
200+ git push --set-upstream origin stable --force
174201
175- - name : Create and Push Tag
202+ - name : Create GitHub Release
203+ env :
204+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
176205 run : |
177206 VERSION="v${{ steps.bump_version.outputs.new_version }}"
178- git tag -a "$VERSION" -m "Release $VERSION"
179- git push origin "$VERSION"
180-
181- # - name: Create GitHub Release
182- # env:
183- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
184- # run: |
185- # VERSION="v${{ steps.bump_version.outputs.new_version }}"
186- # gh release create "$VERSION" \
187- # --title "Release $VERSION" \
188- # --notes "${{ steps.changelog.outputs.content }}" \
189- # --target stable
207+ gh release create "$VERSION" \
208+ --title "Release $VERSION" \
209+ --notes "${{ steps.changelog.outputs.content }}" \
210+ --target stable
0 commit comments