Skip to content

Commit 4965060

Browse files
drakehanguyenDrakeNguyen
andauthored
Refactor release workflow to verify package.json version against release tag and update documentation on version update process. Implemented a warning system for version mismatches and clarified the update-before-tagging approach in RELEASES.md. (#37)
Co-authored-by: DrakeNguyen <drake.ha.nguyen@gmail.com>
1 parent 7ec039c commit 4965060

2 files changed

Lines changed: 82 additions & 30 deletions

File tree

.github/workflows/release.yml

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,42 +185,33 @@ jobs:
185185
id: deployment
186186
uses: actions/deploy-pages@v4
187187

188-
- name: Sync package.json version to main branch
188+
- name: Verify package.json version matches tag
189189
if: success()
190-
continue-on-error: true # Don't fail the workflow if this step fails
190+
continue-on-error: true
191191
run: |
192192
VERSION="${{ steps.tag_version.outputs.version }}"
193+
TAG_NAME="${{ steps.tag_version.outputs.tag_name }}"
193194
194-
# Configure git
195-
git config --local user.email "action@github.com"
196-
git config --local user.name "GitHub Action"
197-
198-
# Fetch main branch and check it out
199-
git fetch origin main
200-
git checkout main
201-
202-
# Check if package.json needs updating
195+
# Check version in package.json from the tag
203196
CURRENT_VERSION=$(node -p "require('./package.json').version")
197+
204198
if [ "$CURRENT_VERSION" = "$VERSION" ]; then
205-
echo "✅ package.json already has version $VERSION, no commit needed"
206-
exit 0
199+
echo "✅ package.json version ($CURRENT_VERSION) matches release tag ($TAG_NAME)"
200+
echo "✅ Version sync verified - following Approach 1 (Update Before Tagging)"
201+
else
202+
echo "⚠️ WARNING: package.json version ($CURRENT_VERSION) does not match release tag ($TAG_NAME)"
203+
echo ""
204+
echo "📋 Recommended workflow (Approach 1):"
205+
echo " 1. Update package.json version to $VERSION"
206+
echo " 2. Commit and push (via PR if branch is protected)"
207+
echo " 3. Then create the release tag"
208+
echo ""
209+
echo "💡 For this release, the tag was created but package.json is out of sync."
210+
echo " Please manually update package.json to $VERSION to keep them in sync."
211+
echo ""
212+
echo "⚠️ This is a warning only - the release will continue."
207213
fi
208214
209-
# Update package.json version
210-
node -e "
211-
const fs = require('fs');
212-
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
213-
pkg.version = '$VERSION';
214-
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
215-
console.log('Updated package.json version to', '$VERSION');
216-
"
217-
218-
# Commit and push
219-
git add package.json
220-
git commit -m "chore: update version to $VERSION [skip ci]"
221-
git push origin main
222-
echo "✅ Committed and pushed updated package.json to main"
223-
224215
- name: Upload build artifacts
225216
if: success()
226217
uses: actions/upload-artifact@v4

docs/RELEASES.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ Before creating a release, update:
2525
}
2626
```
2727

28+
### Version Update Workflow (Approach 1: Update Before Tagging)
29+
30+
This project follows **Approach 1** (Update Before Tagging), the industry standard used by most open-source projects:
31+
32+
**Workflow:**
33+
1. Update `package.json` version
34+
2. Commit and push (via PR if branch is protected)
35+
3. After PR is merged, create the release tag
36+
37+
**Why this approach:**
38+
- ✅ Tag already includes correct version in package.json
39+
- ✅ No post-release sync needed
40+
- ✅ Clean git history
41+
- ✅ Works perfectly with protected branches
42+
- ✅ Industry standard (used by React, Next.js, etc.)
43+
44+
**Important:** Always update `package.json` **before** creating the release tag. The workflow will verify version sync and warn if they don't match.
45+
2846
2. **CHANGELOG.md**: Add release notes for the new version
2947
```markdown
3048
## [0.1.0] - 2026-01-05
@@ -46,16 +64,33 @@ Before creating a release, update:
4664
}
4765
```
4866

49-
### Step 2: Commit Changes
67+
### Step 2: Commit and Push Version Update
68+
69+
**If your branch is protected (requires PR):**
70+
```bash
71+
# Create a branch for the version update
72+
git checkout -b chore/bump-version-to-0.1.0
73+
74+
# Commit changes
75+
git add package.json CHANGELOG.md
76+
git commit -m "chore: bump version to 0.1.0"
77+
78+
# Push and create PR
79+
git push origin chore/bump-version-to-0.1.0
80+
# Then create PR on GitHub and merge it
81+
```
5082

83+
**If your branch is not protected:**
5184
```bash
52-
git add package.json CHANGELOG.md next.config.js
85+
git add package.json CHANGELOG.md
5386
git commit -m "chore: bump version to 0.1.0"
5487
git push origin main
5588
```
5689

5790
### Step 3: Create and Push Version Tag
5891

92+
**Important:** Only create the tag **after** the version update PR is merged (or pushed if not protected).
93+
5994
```bash
6095
# Create annotated tag
6196
git tag -a v0.1.0 -m "Release version 0.1.0"
@@ -221,6 +256,32 @@ These are set automatically during the release build.
221256
2. Check workflow permissions
222257
3. Verify CHANGELOG.md exists and has the version section
223258

259+
### Version Mismatch Warning
260+
261+
If you see a warning that `package.json` version doesn't match the release tag:
262+
263+
1. **This means**: The tag was created before `package.json` was updated
264+
2. **Solution**: Update `package.json` manually to match the tag:
265+
```bash
266+
# Checkout main branch
267+
git checkout main
268+
269+
# Update package.json version to match tag (e.g., 0.1.0)
270+
# Edit package.json: "version": "0.1.0"
271+
272+
# Commit and push (via PR if branch is protected)
273+
git add package.json
274+
git commit -m "chore: update version to 0.1.0"
275+
git push origin main # or create PR
276+
```
277+
278+
3. **Prevention**: Always follow the workflow:
279+
- Update `package.json` first
280+
- Commit and merge PR
281+
- Then create the release tag
282+
283+
4. **Note**: The workflow will continue successfully even if versions don't match (warning only), since the git tag is the source of truth for versioning.
284+
224285
### Build Artifacts
225286

226287
Build artifacts are uploaded to GitHub Actions and kept for 30 days. You can download them from the workflow run.

0 commit comments

Comments
 (0)