Skip to content

Commit 7a408d7

Browse files
sipemuclaude
andcommitted
Move npm publish to separate workflow
- Create npm.yml with dedicated "Publish to npm" workflow - Add dry_run option for testing without actual publish - Add provenance support for npm publish - Remove npm publish from ci.yml (now in separate workflow) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent add4ff7 commit 7a408d7

File tree

2 files changed

+84
-40
lines changed

2 files changed

+84
-40
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ on:
77
branches: [main, master]
88
release:
99
types: [published]
10-
workflow_dispatch:
11-
inputs:
12-
publish_npm:
13-
description: 'Publish to npm'
14-
required: false
15-
type: boolean
16-
default: false
1710

1811
env:
1912
CARGO_TERM_COLOR: always
@@ -121,36 +114,3 @@ jobs:
121114
env:
122115
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
123116

124-
publish-npm:
125-
name: Publish to npm
126-
runs-on: ubuntu-latest
127-
needs: [test, clippy, fmt, docs, build-wasm]
128-
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.publish_npm)
129-
steps:
130-
- uses: actions/checkout@v4
131-
- uses: dtolnay/rust-toolchain@stable
132-
with:
133-
targets: wasm32-unknown-unknown
134-
- uses: Swatinem/rust-cache@v2
135-
- name: Install wasm-pack
136-
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
137-
- name: Build WASM package
138-
run: |
139-
cd crates/anofox-statistics-js
140-
wasm-pack build --target web --out-dir pkg
141-
- name: Update package.json for npm
142-
run: |
143-
cd crates/anofox-statistics-js/pkg
144-
# Update package name to 'anofox-statistics' for npm
145-
jq '.name = "anofox-statistics" | .homepage = "https://github.com/sipemu/anofox-statistics-rs" | .keywords += ["t-test", "shapiro-wilk", "anova", "mann-whitney", "wilcoxon", "chi-squared", "webassembly"]' package.json > package.json.tmp
146-
mv package.json.tmp package.json
147-
- uses: actions/setup-node@v4
148-
with:
149-
node-version: '20'
150-
registry-url: 'https://registry.npmjs.org'
151-
- name: Publish to npm
152-
run: |
153-
cd crates/anofox-statistics-js/pkg
154-
npm publish --access public
155-
env:
156-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/npm.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Publish to npm
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
dry_run:
9+
description: 'Dry run (skip actual publish)'
10+
required: false
11+
default: true
12+
type: boolean
13+
14+
env:
15+
CARGO_TERM_COLOR: always
16+
17+
jobs:
18+
build-wasm:
19+
name: Build WebAssembly
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Setup Rust
25+
uses: dtolnay/rust-toolchain@stable
26+
with:
27+
targets: wasm32-unknown-unknown
28+
29+
- name: Install wasm-pack
30+
run: cargo install wasm-pack
31+
32+
- name: Build WASM package
33+
run: wasm-pack build crates/anofox-statistics-js --target web --release
34+
35+
- name: Update package.json for npm
36+
run: |
37+
cd crates/anofox-statistics-js/pkg
38+
jq '.name = "anofox-statistics" | .homepage = "https://github.com/sipemu/anofox-statistics-rs" | .keywords += ["t-test", "shapiro-wilk", "anova", "mann-whitney", "wilcoxon", "chi-squared", "webassembly"]' package.json > package.json.tmp
39+
mv package.json.tmp package.json
40+
41+
- name: Copy README
42+
run: cp crates/anofox-statistics-js/README.md crates/anofox-statistics-js/pkg/
43+
44+
- name: Upload artifact
45+
uses: actions/upload-artifact@v4
46+
with:
47+
name: wasm-package
48+
path: crates/anofox-statistics-js/pkg/
49+
retention-days: 1
50+
51+
publish-npm:
52+
name: Publish to npm
53+
needs: [build-wasm]
54+
runs-on: ubuntu-latest
55+
permissions:
56+
contents: read
57+
id-token: write
58+
steps:
59+
- name: Download artifact
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: wasm-package
63+
path: pkg
64+
65+
- name: Setup Node.js
66+
uses: actions/setup-node@v4
67+
with:
68+
node-version: '20'
69+
registry-url: 'https://registry.npmjs.org'
70+
71+
- name: List package contents
72+
run: ls -la pkg/
73+
74+
- name: Publish (dry run)
75+
if: github.event_name == 'workflow_dispatch' && inputs.dry_run
76+
run: npm publish pkg/ --dry-run
77+
env:
78+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
79+
80+
- name: Publish
81+
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)
82+
run: npm publish pkg/ --provenance --access public
83+
env:
84+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)