-
Notifications
You must be signed in to change notification settings - Fork 52
298 lines (256 loc) Β· 12 KB
/
Copy pathrelease.yml
File metadata and controls
298 lines (256 loc) Β· 12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
name: Release Package
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
packages: write
issues: read
pull-requests: read
jobs:
check-version:
runs-on: ubuntu-latest
outputs:
version-changed: ${{ steps.version-check.outputs.changed }}
current-version: ${{ steps.version-check.outputs.current-version }}
previous-version: ${{ steps.version-check.outputs.previous-version }}
is-valid-increment: ${{ steps.version-check.outputs.is-valid-increment }}
npm-exists: ${{ steps.npm-check.outputs.exists }}
should-publish: ${{ steps.publish-decision.outputs.should-publish }}
steps:
- name: Checkout current commit
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Get current version
id: current-version
run: |
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Get previous version
id: previous-version
run: |
# Get the previous commit
PREV_COMMIT=$(git rev-parse HEAD~1)
# Get package.json from previous commit
PREV_VERSION=$(git show $PREV_COMMIT:package.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin', 'utf8')).version")
echo "version=$PREV_VERSION" >> $GITHUB_OUTPUT
- name: Check if current version exists on NPM
id: npm-check
run: |
PACKAGE_NAME=$(node -p "require('./package.json').name")
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
echo "Checking if $PACKAGE_NAME@$CURRENT_VERSION exists on NPM..."
if npm view "$PACKAGE_NAME@$CURRENT_VERSION" version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "β
Version $CURRENT_VERSION already exists on NPM"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "β Version $CURRENT_VERSION does not exist on NPM"
fi
- name: Check version change and validate increment
id: version-check
run: |
CURRENT="${{ steps.current-version.outputs.version }}"
PREVIOUS="${{ steps.previous-version.outputs.version }}"
echo "current-version=$CURRENT" >> $GITHUB_OUTPUT
echo "previous-version=$PREVIOUS" >> $GITHUB_OUTPUT
if [ "$CURRENT" != "$PREVIOUS" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed from $PREVIOUS to $CURRENT"
# Install semver for version comparison
npm install -g semver
# Check if current version is greater than previous
if semver gt "$CURRENT" "$PREVIOUS"; then
echo "is-valid-increment=true" >> $GITHUB_OUTPUT
echo "β
Valid version increment: $PREVIOUS β $CURRENT"
else
echo "is-valid-increment=false" >> $GITHUB_OUTPUT
echo "β Invalid version increment: $PREVIOUS β $CURRENT"
echo "Current version must be greater than previous version"
exit 1
fi
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged: $CURRENT"
fi
- name: Decide whether to publish
id: publish-decision
run: |
VERSION_CHANGED="${{ steps.version-check.outputs.changed }}"
IS_VALID_INCREMENT="${{ steps.version-check.outputs.is-valid-increment }}"
NPM_EXISTS="${{ steps.npm-check.outputs.exists }}"
CURRENT_VERSION="${{ steps.current-version.outputs.version }}"
echo "π Publishing Decision Matrix:"
echo " Version Changed: $VERSION_CHANGED"
echo " Valid Increment: $IS_VALID_INCREMENT"
echo " Exists on NPM: $NPM_EXISTS"
echo " Current Version: $CURRENT_VERSION"
# Publish if:
# 1. Version changed AND it's a valid increment, OR
# 2. Current version doesn't exist on NPM (failed previous build)
if [[ "$VERSION_CHANGED" == "true" && "$IS_VALID_INCREMENT" == "true" ]] || [[ "$NPM_EXISTS" == "false" ]]; then
echo "should-publish=true" >> $GITHUB_OUTPUT
if [[ "$VERSION_CHANGED" == "true" ]]; then
echo "β
Will publish: Version increment detected"
else
echo "β
Will publish: Version missing from NPM (likely failed previous build)"
fi
else
echo "should-publish=false" >> $GITHUB_OUTPUT
echo "βοΈ Will skip: Version unchanged and already exists on NPM"
fi
build-and-publish:
needs: check-version
runs-on: ubuntu-latest
if: needs.check-version.outputs.should-publish == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: 'https://registry.npmjs.org'
- name: Setup Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
override: true
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
main/opengeometry/target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cache Node.js dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: npm ci
- name: Lint TypeScript
run: npm run lint:check
- name: Run build
run: npm run build
- name: Verify dist directory
run: |
echo "Checking dist directory contents:"
ls -la dist/
echo "Checking if package.json exists in dist:"
if [ -f "dist/package.json" ]; then
echo "β
package.json found in dist"
echo "Dist package version: $(node -p "require('./dist/package.json').version")"
else
echo "β package.json not found in dist"
exit 1
fi
- name: Run tests
run: npm test
- name: Final NPM existence check
id: final-npm-check
run: |
PACKAGE_NAME=$(node -p "require('./dist/package.json').name")
VERSION="${{ needs.check-version.outputs.current-version }}"
echo "π Final check before publishing..."
if npm view "$PACKAGE_NAME@$VERSION" version 2>/dev/null; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "β οΈ Version $VERSION now exists on NPM (may have been published by another process)"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "β
Version $VERSION confirmed not on NPM, proceeding with publish"
fi
- name: Publish to NPM
if: steps.final-npm-check.outputs.exists == 'false'
run: |
cd dist
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create GitHub Release
if: steps.final-npm-check.outputs.exists == 'false'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.check-version.outputs.current-version }}
name: Release v${{ needs.check-version.outputs.current-version }}
body: |
## Changes in v${{ needs.check-version.outputs.current-version }}
${{ needs.check-version.outputs.version-changed == 'true' && format('Version bumped from {0} to {1}', needs.check-version.outputs.previous-version, needs.check-version.outputs.current-version) || format('Recovery publish for version {0}', needs.check-version.outputs.current-version) }}
### Package Information
- **Package Name**: opengeometry
- **Version**: ${{ needs.check-version.outputs.current-version }}
- **NPM**: https://www.npmjs.com/package/opengeometry
### Installation
```bash
npm install opengeometry@${{ needs.check-version.outputs.current-version }}
```
### Build Information
- **Commit**: ${{ github.sha }}
- **Workflow**: ${{ github.run_id }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
if: steps.final-npm-check.outputs.exists == 'false'
run: |
echo "## π Release Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version**: ${{ needs.check-version.outputs.current-version }}" >> $GITHUB_STEP_SUMMARY
echo "**Status**: β
Successfully published to NPM" >> $GITHUB_STEP_SUMMARY
echo "**Package**: [opengeometry@${{ needs.check-version.outputs.current-version }}](https://www.npmjs.com/package/opengeometry)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Publish Reason" >> $GITHUB_STEP_SUMMARY
if [[ "${{ needs.check-version.outputs.version-changed }}" == "true" ]]; then
echo "- π Version increment: ${{ needs.check-version.outputs.previous-version }} β ${{ needs.check-version.outputs.current-version }}" >> $GITHUB_STEP_SUMMARY
else
echo "- π Recovery publish: Version was missing from NPM registry" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
echo "- Check the [NPM package page](https://www.npmjs.com/package/opengeometry)" >> $GITHUB_STEP_SUMMARY
echo "- Verify the [GitHub release](https://github.com/${{ github.repository }}/releases)" >> $GITHUB_STEP_SUMMARY
- name: Already Published Summary
if: steps.final-npm-check.outputs.exists == 'true'
run: |
echo "## β οΈ Publish Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Reason**: Version ${{ needs.check-version.outputs.current-version }} already exists on NPM" >> $GITHUB_STEP_SUMMARY
echo "**Package**: [opengeometry@${{ needs.check-version.outputs.current-version }}](https://www.npmjs.com/package/opengeometry)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "This likely means the package was published by another process while this build was running." >> $GITHUB_STEP_SUMMARY
skip-build:
needs: check-version
runs-on: ubuntu-latest
if: needs.check-version.outputs.should-publish == 'false'
steps:
- name: Skip message
run: |
echo "## βοΈ Build Skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Reason**: No version change and package already exists on NPM" >> $GITHUB_STEP_SUMMARY
echo "**Current Version**: ${{ needs.check-version.outputs.current-version }}" >> $GITHUB_STEP_SUMMARY
echo "**NPM Status**: β
Already published" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### To trigger a new release:" >> $GITHUB_STEP_SUMMARY
echo '```bash' >> $GITHUB_STEP_SUMMARY
echo 'npm version patch # for bug fixes' >> $GITHUB_STEP_SUMMARY
echo 'npm version minor # for new features' >> $GITHUB_STEP_SUMMARY
echo 'npm version major # for breaking changes' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY