Skip to content

Commit 29b4dd6

Browse files
author
e.khalilov
committed
ci: add manual npm publish workflow
1 parent 57cf652 commit 29b4dd6

1 file changed

Lines changed: 120 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Publish (manual)
2+
3+
env:
4+
DEBUG: napi:*
5+
APP_NAME: usb-hotplug
6+
MACOSX_DEPLOYMENT_TARGET: "10.13"
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
npm_tag:
12+
description: "npm dist-tag"
13+
required: true
14+
default: "latest"
15+
16+
jobs:
17+
build:
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
settings:
22+
- host: macos-latest
23+
target: aarch64-apple-darwin
24+
build: npx napi build --platform --release --target aarch64-apple-darwin --js-package-name @e-khalilov/usb-hotplug
25+
- host: macos-latest
26+
target: x86_64-apple-darwin
27+
build: npx napi build --platform --release --target x86_64-apple-darwin --js-package-name @e-khalilov/usb-hotplug
28+
- host: ubuntu-latest
29+
target: x86_64-unknown-linux-gnu
30+
build: npx napi build --platform --release --target x86_64-unknown-linux-gnu --use-napi-cross --js-package-name @e-khalilov/usb-hotplug
31+
- host: windows-latest
32+
target: x86_64-pc-windows-msvc
33+
build: npx napi build --platform --release --target x86_64-pc-windows-msvc --js-package-name @e-khalilov/usb-hotplug
34+
35+
name: Build ${{ matrix.settings.target }}
36+
runs-on: ${{ matrix.settings.host }}
37+
steps:
38+
- uses: actions/checkout@v4
39+
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v4
42+
with:
43+
node-version: 22
44+
45+
- name: Install Rust toolchain
46+
uses: dtolnay/rust-toolchain@stable
47+
with:
48+
targets: ${{ matrix.settings.target }}
49+
50+
- name: Install dependencies
51+
run: npm install
52+
53+
- name: Build
54+
run: ${{ matrix.settings.build }}
55+
shell: bash
56+
57+
- name: Upload artifact
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: bindings-${{ matrix.settings.target }}
61+
path: ${{ env.APP_NAME }}.*.node
62+
if-no-files-found: error
63+
64+
publish:
65+
name: Publish to npm
66+
runs-on: ubuntu-latest
67+
permissions:
68+
id-token: write
69+
needs:
70+
- build
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Setup Node.js
75+
uses: actions/setup-node@v4
76+
with:
77+
node-version: 22
78+
registry-url: https://registry.npmjs.org
79+
80+
- name: Install latest npm
81+
run: npm install -g npm@latest
82+
83+
- name: Install dependencies
84+
run: npm install
85+
86+
- name: Download all artifacts
87+
uses: actions/download-artifact@v4
88+
with:
89+
path: artifacts
90+
91+
- name: Move artifacts into npm/*
92+
run: npx napi artifacts
93+
94+
- name: List packages
95+
run: ls -R ./npm
96+
shell: bash
97+
98+
- name: Publish (unconditional)
99+
run: |
100+
set -u
101+
TAG="${{ github.event.inputs.npm_tag }}"
102+
echo "Publishing with dist-tag: $TAG"
103+
104+
# Publish each platform package explicitly.
105+
for dir in npm/*/; do
106+
echo "==> Publishing $dir"
107+
if npm publish "$dir" --access public --provenance --tag "$TAG"; then
108+
echo "published $dir"
109+
else
110+
echo "skip $dir (already published or no-op)"
111+
fi
112+
done
113+
114+
# Publish the root package. --ignore-scripts bypasses the
115+
# prepublishOnly (napi prepublish) hook entirely.
116+
echo "==> Publishing root package"
117+
npm publish --access public --provenance --tag "$TAG" --ignore-scripts
118+
env:
119+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
120+
NPM_CONFIG_PROVENANCE: true

0 commit comments

Comments
 (0)