Skip to content

Commit fe886f8

Browse files
committed
ci: Auto cargo publish / npm publish
1 parent 2bcbc34 commit fe886f8

File tree

1 file changed

+81
-8
lines changed

1 file changed

+81
-8
lines changed

Diff for: .github/workflows/build.yaml

+81-8
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
name: Test
7373
strategy:
7474
matrix:
75-
platform: [ubuntu-latest, windows-latest, macos-latest]
75+
platform: [ ubuntu-latest, windows-latest, macos-latest ]
7676
fail-fast: false
7777
runs-on: ${{ matrix.platform }}
7878
steps:
@@ -249,22 +249,30 @@ jobs:
249249
components: rust-src
250250
- name: Cache Rust workspace
251251
uses: Swatinem/rust-cache@v2
252+
- name: Setup Node
253+
uses: actions/setup-node@v4
254+
with:
255+
node-version: lts/*
252256
- name: Install dependencies
253-
run: npm -C objdiff-wasm install
257+
run: npm -C objdiff-wasm ci
254258
- name: Build
255259
run: npm -C objdiff-wasm run build
260+
- name: Upload artifacts
261+
uses: actions/upload-artifact@v4
262+
with:
263+
name: wasm
264+
path: objdiff-wasm/dist/
265+
if-no-files-found: error
256266

257-
release:
258-
name: Release
267+
check-version:
268+
name: Check package versions
259269
if: startsWith(github.ref, 'refs/tags/')
260270
runs-on: ubuntu-latest
261-
needs: [build-cli, build-gui]
262-
permissions:
263-
contents: write
271+
needs: [ build-cli, build-gui ]
264272
steps:
265273
- name: Checkout
266274
uses: actions/checkout@v4
267-
- name: Check git tag against Cargo version
275+
- name: Check git tag against package versions
268276
shell: bash
269277
run: |
270278
set -eou pipefail
@@ -276,9 +284,24 @@ jobs:
276284
echo "::error::Git tag doesn't match the Cargo version! ($tag != $version)"
277285
exit 1
278286
fi
287+
version="v$(jq -r .version objdiff-wasm/package.json)"
288+
if [ "$tag" != "$version" ]; then
289+
echo "::error::Git tag doesn't match the npm version! ($tag != $version)"
290+
exit 1
291+
fi
292+
293+
release-github:
294+
name: Release (GitHub)
295+
if: startsWith(github.ref, 'refs/tags/')
296+
runs-on: ubuntu-latest
297+
needs: [ check-version ]
298+
permissions:
299+
contents: write
300+
steps:
279301
- name: Download artifacts
280302
uses: actions/download-artifact@v4
281303
with:
304+
pattern: objdiff-*
282305
path: artifacts
283306
- name: Rename artifacts
284307
working-directory: artifacts
@@ -308,3 +331,53 @@ jobs:
308331
files: out/*
309332
draft: true
310333
generate_release_notes: true
334+
335+
release-cargo:
336+
name: Release (Cargo)
337+
if: startsWith(github.ref, 'refs/tags/')
338+
runs-on: ubuntu-latest
339+
needs: [ check-version ]
340+
steps:
341+
- name: Checkout
342+
uses: actions/checkout@v4
343+
- name: Setup Rust toolchain
344+
uses: dtolnay/rust-toolchain@stable
345+
- name: Publish
346+
env:
347+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
348+
run: cargo publish -p objdiff-core --dry-run
349+
350+
release-npm:
351+
name: Release (npm)
352+
if: startsWith(github.ref, 'refs/tags/')
353+
runs-on: ubuntu-latest
354+
needs: [ check-version ]
355+
steps:
356+
- name: Checkout
357+
uses: actions/checkout@v4
358+
- name: Setup Node
359+
uses: actions/setup-node@v4
360+
with:
361+
node-version: lts/*
362+
registry-url: 'https://registry.npmjs.org'
363+
- name: Download artifacts
364+
uses: actions/download-artifact@v4
365+
with:
366+
name: wasm
367+
path: objdiff-wasm/dist
368+
- name: Publish
369+
working-directory: objdiff-wasm
370+
env:
371+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
372+
run: |
373+
set -euo pipefail
374+
version=$(jq -r '.version' package.json)
375+
tag="latest"
376+
# Check for prerelease by looking for a dash
377+
case "$version" in
378+
*-*)
379+
tag=$(echo "$version" | sed -e 's/^[^-]*-//' -e 's/\..*$//')
380+
;;
381+
esac
382+
echo "Publishing version $version with tag '$tag'..."
383+
npm publish --provenance --access public --tag "$tag" --dry-run

0 commit comments

Comments
 (0)