|
1 | | -name: Test, Version, and Release |
| 1 | +name: Auto Release on Version Change |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | 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 |
17 | 12 |
|
18 | 13 | jobs: |
19 | | - test: |
20 | | - name: Test |
| 14 | + check-and-release: |
| 15 | + name: Check Version and Release |
21 | 16 | runs-on: ubuntu-latest |
22 | | - |
23 | | - strategy: |
24 | | - matrix: |
25 | | - node-version: [20.x, 22.x, 23.x, 24.x] |
26 | | - |
| 17 | + |
27 | 18 | steps: |
28 | 19 | - name: Checkout |
29 | 20 | 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' |
32 | 42 | uses: actions/setup-node@v4 |
33 | 43 | with: |
34 | | - node-version: ${{ matrix.node-version }} |
| 44 | + node-version: '20.x' |
35 | 45 | cache: 'npm' |
36 | | - |
| 46 | + registry-url: 'https://registry.npmjs.org' |
| 47 | + |
37 | 48 | - name: Install dependencies |
| 49 | + if: steps.version_check.outputs.should_release == 'true' |
38 | 50 | run: npm ci |
39 | | - |
| 51 | + |
40 | 52 | - name: Lint |
| 53 | + if: steps.version_check.outputs.should_release == 'true' |
41 | 54 | run: npm run lint |
42 | | - |
43 | | - - name: Type check |
44 | | - run: npm run type-check |
45 | | - |
| 55 | + |
46 | 56 | - name: Build |
| 57 | + if: steps.version_check.outputs.should_release == 'true' |
47 | 58 | run: npm run build |
48 | | - |
| 59 | + |
49 | 60 | - name: Test |
| 61 | + if: steps.version_check.outputs.should_release == 'true' |
50 | 62 | 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' |
54 | 70 | uses: codecov/codecov-action@v5 |
55 | 71 | with: |
56 | 72 | token: ${{ secrets.CODECOV_TOKEN }} |
57 | 73 | files: ./coverage/lcov.info |
58 | 74 | fail_ci_if_error: true |
59 | | - flags: unittests |
60 | | - name: codecov-umbrella |
| 75 | + flags: release |
| 76 | + name: codecov-release |
61 | 77 | verbose: true |
62 | 78 |
|
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' |
89 | 85 | run: | |
90 | 86 | git config --local user.email "action@github.com" |
91 | 87 | 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 }} |
123 | 90 |
|
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 | | - |
155 | 91 | - name: Publish to NPM |
| 92 | + if: steps.version_check.outputs.should_release == 'true' |
156 | 93 | run: | |
157 | 94 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc |
158 | | - npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN |
159 | | - npm whoami |
160 | 95 | npm publish --access public |
161 | 96 | env: |
162 | 97 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
163 | | - |
| 98 | + |
164 | 99 | - 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 | + |
169 | 103 | - name: Generate changelog |
| 104 | + if: steps.version_check.outputs.should_release == 'true' |
170 | 105 | id: release_notes |
171 | 106 | run: | |
172 | 107 | NOTES="$RUNNER_TEMP/release_notes.md" |
173 | 108 | { |
174 | | - echo "## 🎉 SomonScript ${{ needs.version.outputs.new_version }}"; |
| 109 | + echo "## 🎉 SomonScript ${{ steps.version_check.outputs.version }}"; |
175 | 110 | echo ""; |
176 | 111 | echo "### ✨ What's New"; |
177 | 112 | echo ""; |
178 | 113 |
|
179 | 114 | LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo ""); |
180 | 115 | if [ -n "$LAST_TAG" ]; then |
181 | 116 | 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; |
183 | 119 | 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 }}"; |
188 | 121 | fi |
189 | 122 |
|
| 123 | + echo ""; |
190 | 124 | echo ""; |
191 | 125 | echo "### 📦 Installation"; |
| 126 | + echo ""; |
192 | 127 | echo '```bash'; |
193 | 128 | echo 'npm install -g @lindentech/somon-script'; |
194 | 129 | echo '```'; |
195 | 130 | } > "$NOTES" |
196 | 131 | echo "path=$NOTES" >> "$GITHUB_OUTPUT" |
197 | 132 |
|
198 | 133 | - name: Create GitHub Release |
| 134 | + if: steps.version_check.outputs.should_release == 'true' |
199 | 135 | uses: softprops/action-gh-release@v1 |
200 | 136 | 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 }}" |
203 | 139 | body_path: ${{ steps.release_notes.outputs.path }} |
204 | | - files: | |
205 | | - *.tgz |
| 140 | + files: '*.tgz' |
206 | 141 | draft: false |
207 | 142 | prerelease: false |
208 | | - |
| 143 | + |
209 | 144 | - name: Summary |
| 145 | + if: steps.version_check.outputs.should_release == 'true' |
210 | 146 | run: | |
211 | | - echo "🎉 Release ${{ needs.version.outputs.new_version }} completed!" |
| 147 | + echo "🎉 Release ${{ steps.version_check.outputs.version }} completed successfully!" |
| 148 | + echo "" |
212 | 149 | echo "✅ Tests passed" |
213 | | - echo "✅ Version incremented automatically" |
214 | 150 | echo "✅ Git tag created and pushed" |
215 | | - echo "✅ GitHub release created" |
| 151 | + echo "✅ NPM package published" |
216 | 152 | 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