Skip to content

Commit a70df01

Browse files
committed
refactor: streamline version release workflow to trigger only on package.json changes
1 parent 599c2a1 commit a70df01

4 files changed

Lines changed: 86 additions & 946 deletions

File tree

Lines changed: 86 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,159 @@
1-
name: Test, Version, and Release
1+
name: Auto Release on Version Change
22

33
on:
44
push:
55
branches: [main]
6-
workflow_dispatch:
7-
inputs:
8-
version_type:
9-
description: 'Version increment type'
10-
required: false
11-
default: 'patch'
12-
type: choice
13-
options:
14-
- patch
15-
- minor
16-
- major
6+
paths:
7+
- 'package.json' # Only trigger when package.json changes (version bump)
8+
9+
permissions:
10+
contents: write
11+
id-token: write
1712

1813
jobs:
19-
test:
20-
name: Test
14+
check-and-release:
15+
name: Check Version and Release
2116
runs-on: ubuntu-latest
22-
23-
strategy:
24-
matrix:
25-
node-version: [20.x, 22.x, 23.x, 24.x]
26-
17+
2718
steps:
2819
- name: Checkout
2920
uses: actions/checkout@v4
30-
31-
- name: Setup Node.js ${{ matrix.node-version }}
21+
with:
22+
fetch-depth: 0 # Need full history for changelog
23+
24+
- name: Check if version needs release
25+
id: version_check
26+
run: |
27+
VERSION=$(node -p "require('./package.json').version")
28+
echo "Current version: $VERSION"
29+
30+
# Check if this version already has a tag
31+
if git tag | grep -q "^v$VERSION$"; then
32+
echo "✅ Version v$VERSION already released, skipping"
33+
echo "should_release=false" >> $GITHUB_OUTPUT
34+
else
35+
echo "🆕 New version detected: v$VERSION - will release"
36+
echo "should_release=true" >> $GITHUB_OUTPUT
37+
echo "version=v$VERSION" >> $GITHUB_OUTPUT
38+
fi
39+
40+
- name: Setup Node.js
41+
if: steps.version_check.outputs.should_release == 'true'
3242
uses: actions/setup-node@v4
3343
with:
34-
node-version: ${{ matrix.node-version }}
44+
node-version: '20.x'
3545
cache: 'npm'
36-
46+
registry-url: 'https://registry.npmjs.org'
47+
3748
- name: Install dependencies
49+
if: steps.version_check.outputs.should_release == 'true'
3850
run: npm ci
39-
51+
4052
- name: Lint
53+
if: steps.version_check.outputs.should_release == 'true'
4154
run: npm run lint
42-
43-
- name: Type check
44-
run: npm run type-check
45-
55+
4656
- name: Build
57+
if: steps.version_check.outputs.should_release == 'true'
4758
run: npm run build
48-
59+
4960
- name: Test
61+
if: steps.version_check.outputs.should_release == 'true'
5062
run: npm run test:ci
51-
52-
- name: Upload coverage reports to Codecov
53-
if: matrix.node-version == '20.x'
63+
64+
- name: Test examples
65+
if: steps.version_check.outputs.should_release == 'true'
66+
run: npm run audit:examples
67+
68+
- name: Upload coverage to Codecov
69+
if: steps.version_check.outputs.should_release == 'true'
5470
uses: codecov/codecov-action@v5
5571
with:
5672
token: ${{ secrets.CODECOV_TOKEN }}
5773
files: ./coverage/lcov.info
5874
fail_ci_if_error: true
59-
flags: unittests
60-
name: codecov-umbrella
75+
flags: release
76+
name: codecov-release
6177
verbose: true
6278

63-
version:
64-
name: Version Increment
65-
runs-on: ubuntu-latest
66-
needs: test
67-
permissions:
68-
contents: write
69-
outputs:
70-
new_version: ${{ steps.version.outputs.new_version }}
71-
72-
steps:
73-
- name: Checkout
74-
uses: actions/checkout@v4
75-
with:
76-
fetch-depth: 0
77-
token: ${{ secrets.GITHUB_TOKEN }}
78-
79-
- name: Setup Node.js
80-
uses: actions/setup-node@v4
81-
with:
82-
node-version: '20.x'
83-
cache: 'npm'
84-
85-
- name: Install dependencies
86-
run: npm ci
87-
88-
- name: Configure Git
79+
- name: Create package
80+
if: steps.version_check.outputs.should_release == 'true'
81+
run: npm pack
82+
83+
- name: Create and push tag
84+
if: steps.version_check.outputs.should_release == 'true'
8985
run: |
9086
git config --local user.email "action@github.com"
9187
git config --local user.name "GitHub Action"
92-
93-
- name: Determine version type
94-
id: version_type
95-
run: |
96-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
97-
echo "type=${{ inputs.version_type }}" >> $GITHUB_OUTPUT
98-
else
99-
echo "type=patch" >> $GITHUB_OUTPUT
100-
fi
101-
102-
- name: Increment version
103-
id: version
104-
run: |
105-
# Use npm version with lifecycle script for automatic jsr.json synchronization
106-
echo "Running npm version ${{ steps.version_type.outputs.type }}..."
107-
npm version ${{ steps.version_type.outputs.type }} --no-git-tag-version
108-
109-
# Get the new version from package.json (more reliable than parsing npm output)
110-
NEW_VERSION="v$(node -p 'require("./package.json").version')"
111-
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
112-
echo "📦 New version: $NEW_VERSION"
113-
114-
- name: Commit and tag version
115-
run: |
116-
git add package.json package-lock.json jsr.json
117-
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}
118-
119-
Co-authored-by: Ona <no-reply@ona.com>"
120-
git tag ${{ steps.version.outputs.new_version }}
121-
git push origin main
122-
git push origin ${{ steps.version.outputs.new_version }}
88+
git tag ${{ steps.version_check.outputs.version }} -m "Release ${{ steps.version_check.outputs.version }}"
89+
git push origin ${{ steps.version_check.outputs.version }}
12390
124-
release:
125-
name: Release
126-
runs-on: ubuntu-latest
127-
needs: version
128-
permissions:
129-
contents: write
130-
id-token: write # Required for JSR OIDC authentication
131-
132-
steps:
133-
- name: Checkout
134-
uses: actions/checkout@v4
135-
with:
136-
ref: ${{ needs.version.outputs.new_version }}
137-
fetch-depth: 0
138-
139-
- name: Setup Node.js
140-
uses: actions/setup-node@v4
141-
with:
142-
node-version: '20.x'
143-
cache: 'npm'
144-
registry-url: 'https://registry.npmjs.org'
145-
146-
- name: Install dependencies
147-
run: npm ci
148-
149-
- name: Build
150-
run: npm run build
151-
152-
- name: Create package
153-
run: npm pack
154-
15591
- name: Publish to NPM
92+
if: steps.version_check.outputs.should_release == 'true'
15693
run: |
15794
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
158-
npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN
159-
npm whoami
16095
npm publish --access public
16196
env:
16297
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
163-
98+
16499
- name: Publish to JSR
165-
run: |
166-
git status --short
167-
npx jsr publish --allow-slow-types
168-
100+
if: steps.version_check.outputs.should_release == 'true'
101+
run: npx jsr publish --allow-slow-types
102+
169103
- name: Generate changelog
104+
if: steps.version_check.outputs.should_release == 'true'
170105
id: release_notes
171106
run: |
172107
NOTES="$RUNNER_TEMP/release_notes.md"
173108
{
174-
echo "## 🎉 SomonScript ${{ needs.version.outputs.new_version }}";
109+
echo "## 🎉 SomonScript ${{ steps.version_check.outputs.version }}";
175110
echo "";
176111
echo "### ✨ What's New";
177112
echo "";
178113
179114
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "");
180115
if [ -n "$LAST_TAG" ]; then
181116
echo "Changes since $LAST_TAG:";
182-
git log --pretty=format:"- %s" "$LAST_TAG"..HEAD^;
117+
echo "";
118+
git log --pretty=format:"- %s" "$LAST_TAG"..HEAD;
183119
else
184-
echo "- Automatic version increment to ${{ needs.version.outputs.new_version }}";
185-
echo "- Comprehensive architecture with union type support";
186-
echo "- Type-safe compilation";
187-
echo "- Modular design";
120+
echo "- Initial release of ${{ steps.version_check.outputs.version }}";
188121
fi
189122
123+
echo "";
190124
echo "";
191125
echo "### 📦 Installation";
126+
echo "";
192127
echo '```bash';
193128
echo 'npm install -g @lindentech/somon-script';
194129
echo '```';
195130
} > "$NOTES"
196131
echo "path=$NOTES" >> "$GITHUB_OUTPUT"
197132
198133
- name: Create GitHub Release
134+
if: steps.version_check.outputs.should_release == 'true'
199135
uses: softprops/action-gh-release@v1
200136
with:
201-
tag_name: ${{ needs.version.outputs.new_version }}
202-
name: "SomonScript ${{ needs.version.outputs.new_version }}"
137+
tag_name: ${{ steps.version_check.outputs.version }}
138+
name: "SomonScript ${{ steps.version_check.outputs.version }}"
203139
body_path: ${{ steps.release_notes.outputs.path }}
204-
files: |
205-
*.tgz
140+
files: '*.tgz'
206141
draft: false
207142
prerelease: false
208-
143+
209144
- name: Summary
145+
if: steps.version_check.outputs.should_release == 'true'
210146
run: |
211-
echo "🎉 Release ${{ needs.version.outputs.new_version }} completed!"
147+
echo "🎉 Release ${{ steps.version_check.outputs.version }} completed successfully!"
148+
echo ""
212149
echo "✅ Tests passed"
213-
echo "✅ Version incremented automatically"
214150
echo "✅ Git tag created and pushed"
215-
echo "✅ GitHub release created"
151+
echo "✅ NPM package published"
216152
echo "✅ JSR package published"
217-
echo "⏳ NPM publishing pending (24-hour restriction)"
153+
echo "✅ GitHub release created"
154+
echo ""
155+
echo "📦 View release: https://github.com/${{ github.repository }}/releases/tag/${{ steps.version_check.outputs.version }}"
156+
157+
- name: Skip message
158+
if: steps.version_check.outputs.should_release == 'false'
159+
run: echo "ℹ️ No new version to release, skipping workflow"

0 commit comments

Comments
 (0)