Skip to content

Commit 564fd79

Browse files
committed
ID-482 Split branch create from PR.
Allows for an external step to create the branch rather than doing it from a workflow dispatch.
1 parent e751101 commit 564fd79

3 files changed

Lines changed: 145 additions & 55 deletions

File tree

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: Create Release Branch
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version number (X.Y.Z, with optional prerelease suffix like -alpha)'
8+
required: true
9+
type: string
10+
11+
jobs:
12+
create-branch:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Normalize and validate version
20+
id: version
21+
run: |
22+
# Normalize version (remove leading v if present)
23+
VERSION="${{ github.event.inputs.version }}"
24+
VERSION="${VERSION#v}"
25+
26+
# Validate format: X.Y.Z or X.Y.Z-prerelease
27+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
28+
echo "❌ Invalid version format: $VERSION"
29+
echo "Expected format: X.Y.Z or X.Y.Z-prerelease (with or without leading 'v')"
30+
exit 1
31+
fi
32+
33+
echo "✓ Valid version: $VERSION"
34+
echo "version=$VERSION" >> $GITHUB_OUTPUT
35+
echo "branch=release/v$VERSION" >> $GITHUB_OUTPUT
36+
37+
- name: Check if branch already exists
38+
id: branch-check
39+
run: |
40+
BRANCH="${{ steps.version.outputs.branch }}"
41+
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
42+
echo "exists=true" >> $GITHUB_OUTPUT
43+
echo "ℹ️ Branch '$BRANCH' already exists"
44+
else
45+
echo "exists=false" >> $GITHUB_OUTPUT
46+
echo "ℹ️ Creating new branch '$BRANCH'"
47+
fi
48+
49+
- name: Create or checkout release branch
50+
run: |
51+
BRANCH="${{ steps.version.outputs.branch }}"
52+
if [ "${{ steps.branch-check.outputs.exists }}" = "true" ]; then
53+
git fetch origin "$BRANCH"
54+
git checkout "$BRANCH"
55+
else
56+
git checkout -b "$BRANCH"
57+
fi
58+
59+
- name: Update version in package.json and _config.yml
60+
run: |
61+
VERSION="${{ steps.version.outputs.version }}"
62+
63+
# Update package.json
64+
sed -i -E 's/"version": "[^"]+"/"version": "'$VERSION'"/' package.json
65+
echo "✓ Updated package.json to $VERSION"
66+
67+
# Update _config.yml
68+
sed -i -E 's/current_version: [^ ]+/current_version: '$VERSION'/' _config.yml
69+
echo "✓ Updated _config.yml to $VERSION"
70+
71+
- name: Verify version updates
72+
run: |
73+
VERSION="${{ steps.version.outputs.version }}"
74+
PKG_VERSION=$(grep -o '"version": "[^"]*"' package.json | cut -d'"' -f4)
75+
CONFIG_VERSION=$(grep 'current_version:' _config.yml | awk '{print $2}')
76+
77+
echo "package.json version: $PKG_VERSION"
78+
echo "_config.yml version: $CONFIG_VERSION"
79+
80+
if [ "$PKG_VERSION" != "$VERSION" ] || [ "$CONFIG_VERSION" != "$VERSION" ]; then
81+
echo "❌ Version update verification failed"
82+
exit 1
83+
fi
84+
85+
echo "✓ Version updates verified"
86+
87+
- name: Commit changes
88+
run: |
89+
VERSION="${{ steps.version.outputs.version }}"
90+
git config user.name "github-actions[bot]"
91+
git config user.email "github-actions[bot]@users.noreply.github.com"
92+
93+
if ! git diff --quiet; then
94+
git add package.json _config.yml
95+
git commit -m "Release v$VERSION"
96+
echo "✓ Committed version bump"
97+
else
98+
echo "ℹ️ No changes to commit (version may already be up to date)"
99+
fi
100+
101+
- name: Push branch
102+
run: |
103+
BRANCH="${{ steps.version.outputs.branch }}"
104+
git push origin "$BRANCH" --force-with-lease
105+
106+
- name: Summary
107+
run: |
108+
BRANCH="${{ steps.version.outputs.branch }}"
109+
echo "✅ Release branch created"
110+
echo ""
111+
echo "📊 Summary:"
112+
echo " Version: ${{ steps.version.outputs.version }}"
113+
echo " Branch: $BRANCH"
114+
echo ""
115+
echo "🔗 Branch: https://github.com/${{ github.repository }}/tree/$BRANCH"
116+
echo ""
117+
echo "Next: A pull request will be created automatically when the branch is pushed."
118+

.github/workflows/create-release-pr.yml

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,31 @@
1-
name: Create Release PR
1+
name: Prepare Release PR
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: 'Version number (X.Y.Z, with optional prerelease suffix like -alpha)'
8-
required: true
9-
type: string
4+
push:
5+
branches:
6+
- release/v*
107

118
jobs:
12-
create-pr:
9+
prepare-pr:
1310
runs-on: ubuntu-latest
1411
steps:
1512
- uses: actions/checkout@v4
1613
with:
1714
fetch-depth: 0
15+
ref: ${{ github.ref_name }}
1816

19-
- name: Normalize and validate version
17+
- name: Extract version from branch name
2018
id: version
2119
run: |
22-
# Normalize version (remove leading v if present)
23-
VERSION="${{ github.event.inputs.version }}"
24-
VERSION="${VERSION#v}"
20+
BRANCH="${{ github.ref_name }}"
21+
# Extract version from release/vX.Y.Z
22+
VERSION="${BRANCH#release/v}"
2523
26-
# Validate format: X.Y.Z or X.Y.Z-prerelease
27-
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]]; then
28-
echo "❌ Invalid version format: $VERSION"
29-
echo "Expected format: X.Y.Z or X.Y.Z-prerelease (with or without leading 'v')"
30-
exit 1
31-
fi
32-
33-
echo "✓ Valid version: $VERSION"
3424
echo "version=$VERSION" >> $GITHUB_OUTPUT
35-
echo "branch=release/v$VERSION" >> $GITHUB_OUTPUT
36-
37-
- name: Check if branch already exists
38-
id: branch-check
39-
run: |
40-
BRANCH="${{ steps.version.outputs.branch }}"
41-
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
42-
echo "exists=true" >> $GITHUB_OUTPUT
43-
echo "ℹ️ Branch '$BRANCH' already exists"
44-
else
45-
echo "exists=false" >> $GITHUB_OUTPUT
46-
echo "ℹ️ Creating new branch '$BRANCH'"
47-
fi
48-
49-
- name: Create or checkout release branch
50-
run: |
51-
BRANCH="${{ steps.version.outputs.branch }}"
52-
if [ "${{ steps.branch-check.outputs.exists }}" = "true" ]; then
53-
git fetch origin "$BRANCH"
54-
git checkout "$BRANCH"
55-
else
56-
git checkout -b "$BRANCH"
57-
fi
25+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
26+
27+
echo "📦 Detected version from branch: $VERSION"
28+
echo "🌿 Branch: $BRANCH"
5829
5930
- name: Update version in package.json and _config.yml
6031
run: |
@@ -84,7 +55,7 @@ jobs:
8455
8556
echo "✓ Version updates verified"
8657
87-
- name: Commit changes
58+
- name: Commit version updates
8859
run: |
8960
VERSION="${{ steps.version.outputs.version }}"
9061
git config user.name "github-actions[bot]"
@@ -95,13 +66,13 @@ jobs:
9566
git commit -m "Release v$VERSION"
9667
echo "✓ Committed version bump"
9768
else
98-
echo "ℹ️ No changes to commit (version may already be up to date)"
69+
echo "ℹ️ No changes to commit (version already up to date)"
9970
fi
10071
101-
- name: Push branch
72+
- name: Push version updates
10273
run: |
10374
BRANCH="${{ steps.version.outputs.branch }}"
104-
git push origin "$BRANCH" --force-with-lease
75+
git push origin "$BRANCH"
10576
10677
- name: Create or update pull request
10778
uses: actions/github-script@v7

RELEASES.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Releasing ID7
22

3-
ID7 uses an automated release process powered by GitHub Actions. All you need to do is choose a version - a release PR is created for you. When that PR is approved, comment `/release` to trigger the finalization.
3+
ID7 uses an automated release process powered by GitHub Actions. All you need to do is choose a version - a release branch is created for you, and a PR is automatically generated. When that PR is approved, comment `/release` to trigger the finalization.
44

55
## Quick instructions
66

@@ -30,15 +30,15 @@ The workflow will:
3030
- ✓ Create a new `release/vX.Y.Z` branch
3131
- ✓ Create a pull request titled "Release vX.Y.Z"
3232

33-
### Step 2: Review and Approve (Manual)
33+
### Step 3: Review and Approve (Manual)
3434

3535
1. Review the pull request in **Pull Requests** tab
3636
2. Verify the version bump is correct in both files
3737
3. Request approval from maintainers
3838
4. Once approved, a bot comment will appear saying "Ready to Release"
3939
5. **Do not merge yet** — verify that all CI checks have passed
4040

41-
### Step 3: Trigger Release (Manual)
41+
### Step 4: Trigger Release (Manual)
4242

4343
When you're ready to release:
4444

@@ -48,30 +48,31 @@ When you're ready to release:
4848
- The PR is in a mergeable state (no conflicts, CI passed)
4949
3. If all checks pass, the **Finalize Release** workflow launches
5050

51-
### Step 4: Finalize Release (Automated)
51+
### Step 5: Finalize Release (Automated)
5252

5353
The **Finalize Release** workflow automatically:
5454

55-
- ✓ Creates a GitHub release with tag `vX.Y.Z`
55+
- ✓ Creates a GitHub release (as draft) with tag `vX.Y.Z`
5656
- ✓ Marks prerelease versions (e.g., `-rc.1`) appropriately
5757
- ✓ Runs `npm run build` to generate production artifacts
5858
- ✓ Uploads distribution ZIP files to the release
5959
- ✓ Publishes the package to npmjs.org with `npm publish --access=public`
60-
- ✓ Merges the PR to `main`
60+
- ✓ Publishes the GitHub release (moves from draft to public)
61+
- ✓ Automatically merges the PR to `main`
6162

6263
**Monitoring:** Watch the **Actions** tab > **Finalize Release** workflow.
6364

6465
### Handling Publish Failures
6566

6667
If NPM publish fails:
6768

68-
1. The GitHub release is **moved to draft** status (not published)
69+
1. The GitHub release **remains in draft** status (not published)
6970
2. A comment is posted on the PR with:
7071
- The error details
7172
- Steps to resolve (usually checking authentication)
7273
- Instructions to re-run or manually publish
7374

74-
The PR will **not be merged** on failure, allowing you to retry.
75+
The PR will **not be merged** on failure, allowing you to retry after fixing the issue.
7576
---
7677

7778
## Netlify Deploy

0 commit comments

Comments
 (0)