Skip to content

Commit b605354

Browse files
fix: use release branch and PR for version bump to respect branch pro… (#904)
* fix: use release branch and PR for version bump to respect branch protection - Add pull-requests: write permission - Create release branch instead of pushing directly to target branch - Automatically create PR from release branch to target branch - Check if PR already exists before creating (idempotent re-runs) - Update build-tauri and create-release jobs to use release branch - Document tag timing behavior in auto-generated PR description
1 parent 4e6f51c commit b605354

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

.github/workflows/Tauri-Release.yml

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: Manually Triggered Desktop Release
33
permissions:
44
contents: write
55
actions: read
6+
pull-requests: write
67

78
concurrency:
89
group: desktop-release-${{ github.ref }}
@@ -27,6 +28,7 @@ jobs:
2728
outputs:
2829
new_version: ${{ steps.bump.outputs.new_version }}
2930
changelog: ${{ steps.changelog.outputs.clean_changelog }}
31+
release_branch: ${{ steps.bump.outputs.release_branch }}
3032
steps:
3133
- name: Checkout repository
3234
uses: actions/checkout@v4
@@ -72,9 +74,11 @@ jobs:
7274
7375
NEW_VERSION="v$MAJOR.$MINOR.$PATCH"
7476
VERSION_NO_V="$MAJOR.$MINOR.$PATCH"
77+
RELEASE_BRANCH="release/$NEW_VERSION"
7578
7679
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
7780
echo "version_no_v=$VERSION_NO_V" >> "$GITHUB_OUTPUT"
81+
echo "release_branch=$RELEASE_BRANCH" >> "$GITHUB_OUTPUT"
7882
echo "New version will be: $NEW_VERSION"
7983
8084
- name: Update Version Files
@@ -109,16 +113,51 @@ jobs:
109113
release-count: 0
110114
tag-prefix: 'v'
111115

112-
- name: Commit Version Bump
116+
- name: Commit Version Bump and Create Release Branch
113117
run: |
114118
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
119+
RELEASE_BRANCH="release/$NEW_VERSION"
115120
121+
git checkout -b "$RELEASE_BRANCH"
116122
git add package.json src-tauri/tauri.conf.json src-tauri/Cargo.toml
117123
git commit -m "chore: bump version to $NEW_VERSION"
118124
git tag "$NEW_VERSION"
119-
git push origin HEAD:${{ github.ref_name }}
125+
git push origin "$RELEASE_BRANCH"
120126
git push origin "$NEW_VERSION"
121127
128+
- name: Create Pull Request
129+
env:
130+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
131+
run: |
132+
NEW_VERSION="${{ steps.bump.outputs.new_version }}"
133+
RELEASE_BRANCH="release/$NEW_VERSION"
134+
TARGET_BRANCH="${{ github.ref_name }}"
135+
136+
# Check if a PR already exists for this release branch
137+
EXISTING_PR=$(gh pr list --head "$RELEASE_BRANCH" --base "$TARGET_BRANCH" --json number --jq '.[0].number' || true)
138+
139+
if [ -n "$EXISTING_PR" ]; then
140+
echo "PR #$EXISTING_PR already exists for $RELEASE_BRANCH -> $TARGET_BRANCH. Skipping PR creation."
141+
else
142+
gh pr create \
143+
--title "chore: release $NEW_VERSION" \
144+
--body "## Release $NEW_VERSION
145+
146+
This PR contains the version bump for release $NEW_VERSION.
147+
148+
### Changes
149+
- Updated version in package.json, tauri.conf.json, and Cargo.toml
150+
- Tagged release $NEW_VERSION
151+
152+
> **Note:** The tag is created on the release branch before merge. This is intentional to allow the build and release process to complete. The tag points to the version bump commit.
153+
154+
---
155+
*This PR was automatically created by the release workflow.*" \
156+
--base "$TARGET_BRANCH" \
157+
--head "$RELEASE_BRANCH"
158+
echo "Created PR for $RELEASE_BRANCH -> $TARGET_BRANCH"
159+
fi
160+
122161
build-tauri:
123162
runs-on: ${{ matrix.os }}
124163
needs: version
@@ -131,11 +170,11 @@ jobs:
131170
- name: Checkout repository
132171
uses: actions/checkout@v4
133172
with:
134-
ref: ${{ github.ref_name }}
173+
ref: ${{ needs.version.outputs.release_branch }}
135174
fetch-depth: 0
136175

137176
- name: Pull latest changes
138-
run: git pull origin ${{ github.ref_name }}
177+
run: git pull origin ${{ needs.version.outputs.release_branch }}
139178

140179
- name: Setup Node.js
141180
uses: actions/setup-node@v4
@@ -215,7 +254,7 @@ jobs:
215254
with:
216255
fetch-depth: 0
217256
token: ${{ secrets.GITHUB_TOKEN }}
218-
ref: ${{ github.ref_name }}
257+
ref: ${{ needs.version.outputs.release_branch }}
219258

220259
- name: Configure Git
221260
run: |
@@ -244,18 +283,19 @@ jobs:
244283
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245284
run: |
246285
set -euo pipefail
247-
286+
RELEASE_BRANCH="${{ needs.version.outputs.release_branch }}"
287+
248288
# Pull latest changes (version job pushed new commits)
249-
git pull origin ${{ github.ref_name }} --rebase
250-
289+
git pull origin "$RELEASE_BRANCH" --rebase
290+
251291
if git diff --quiet -- CHANGELOG.md; then
252292
echo "No changelog updates to commit."
253293
exit 0
254294
fi
255295
256296
git add CHANGELOG.md
257297
git commit -m "chore: update changelog for ${{ needs.version.outputs.new_version }}"
258-
git push origin HEAD:${{ github.ref_name }}
298+
git push origin HEAD:"$RELEASE_BRANCH"
259299
260300
- name: Download all build artifacts
261301
uses: actions/download-artifact@v4
@@ -309,4 +349,4 @@ jobs:
309349
gh release create "$NEW_VERSION" \
310350
--title "CircuitVerse Desktop $NEW_VERSION" \
311351
--notes-file "$CHANGELOG_NOTES_FILE" \
312-
release-assets/*
352+
release-assets/*

0 commit comments

Comments
 (0)