Skip to content

Commit f27c249

Browse files
authored
NPM Publish Workflow (#1460)
Automate npm publishing via GitHub Actions when a new tag is pushed. Prebuilt binaries for both x64 and arm64 are built in parallel, bundled into the tarball, and published to npm with SLSA provenance attestation using OIDC trusted publishing (no long-lived npm token required). ### Changes **New: `.github/workflows/npm-publish.yml`** — Triggers on tag push or manual `workflow_dispatch` (with dry-run option). Calls `prebuild-linux-x64.yml` and `prebuild-linux-arm64.yml` as reusable sub-workflows in parallel. After both complete, the `publish` job downloads all prebuilt `.node` artifacts, runs `./scripts/npm-pack.sh` to create the tarball, and publishes via `npm publish --provenance --access public`. Security: fork protection (`if: github.repository == 'RobotWebTools/rclnodejs'`), concurrency guard, GitHub environment (`npm-publish`) for deployment protection, and `id-token: write` for OIDC trusted publishing. **Modified: `.github/workflows/prebuild-linux-arm64.yml`** — Replaced `push: tags: '*'` trigger with `workflow_call:` so it can be invoked as a reusable workflow from `npm-publish.yml`. `workflow_dispatch:` retained for manual runs. **Modified: `.github/workflows/prebuild-linux-x64.yml`** — Same change as arm64: replaced `push: tags:` with `workflow_call:`. Fix: #1459
1 parent dfe5e64 commit f27c249

3 files changed

Lines changed: 85 additions & 10 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: NPM Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
inputs:
9+
dry_run:
10+
description: 'Perform a dry run (skip actual publish)'
11+
required: true
12+
type: boolean
13+
default: true
14+
15+
# Ensure only one publish runs at a time
16+
concurrency:
17+
group: npm-publish
18+
cancel-in-progress: false
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
prebuild-x64:
25+
if: github.repository == 'RobotWebTools/rclnodejs'
26+
uses: ./.github/workflows/prebuild-linux-x64.yml
27+
28+
prebuild-arm64:
29+
if: github.repository == 'RobotWebTools/rclnodejs'
30+
uses: ./.github/workflows/prebuild-linux-arm64.yml
31+
32+
publish:
33+
needs: [prebuild-x64, prebuild-arm64]
34+
runs-on: ubuntu-latest
35+
environment: npm-publish
36+
permissions:
37+
contents: read
38+
id-token: write
39+
steps:
40+
- uses: actions/checkout@v6
41+
42+
- name: Setup Node.js
43+
uses: actions/setup-node@v6
44+
with:
45+
node-version: 24.x
46+
registry-url: 'https://registry.npmjs.org'
47+
48+
- name: Download x64 prebuilds
49+
uses: actions/download-artifact@v7
50+
with:
51+
pattern: prebuilt-linux-x64-*
52+
path: prebuilds/linux-x64
53+
merge-multiple: true
54+
55+
- name: Download arm64 prebuilds
56+
uses: actions/download-artifact@v7
57+
with:
58+
pattern: prebuilt-linux-arm64-*
59+
path: prebuilds/linux-arm64
60+
merge-multiple: true
61+
62+
- name: List prebuilds
63+
run: |
64+
echo "=== x64 prebuilds ==="
65+
ls -la prebuilds/linux-x64/
66+
echo "=== arm64 prebuilds ==="
67+
ls -la prebuilds/linux-arm64/
68+
69+
- name: Pack
70+
run: ./scripts/npm-pack.sh
71+
72+
- name: Publish
73+
run: |
74+
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
75+
echo "=== DRY RUN ==="
76+
npm publish --provenance --access public --dry-run ./dist/rclnodejs-*.tgz
77+
else
78+
npm publish --provenance --access public ./dist/rclnodejs-*.tgz
79+
fi

.github/workflows/prebuild-linux-arm64.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ name: Prebuild Linux ARM64
22

33
on:
44
workflow_dispatch:
5-
push:
6-
tags:
7-
- '*'
5+
workflow_call:
86

97
jobs:
108
prebuild:
@@ -46,7 +44,7 @@ jobs:
4644
with:
4745
required-ros-distributions: ${{ matrix.ros_distribution }}
4846

49-
- uses: actions/checkout@v5
47+
- uses: actions/checkout@v6
5048

5149
- name: Install dependencies
5250
shell: bash
@@ -61,7 +59,7 @@ jobs:
6159
npm run prebuild
6260
6361
- name: Upload prebuilt binary
64-
uses: actions/upload-artifact@v4
62+
uses: actions/upload-artifact@v7
6563
with:
6664
name: prebuilt-linux-arm64-node${{ matrix.node-version }}-${{ matrix.ubuntu_codename }}-${{ matrix.ros_distribution }}
6765
path: prebuilds/linux-arm64/*.node

.github/workflows/prebuild-linux-x64.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ name: Prebuild Linux x64
22

33
on:
44
workflow_dispatch:
5-
push:
6-
tags:
7-
- '*'
5+
workflow_call:
86

97
jobs:
108
prebuild:
@@ -46,7 +44,7 @@ jobs:
4644
with:
4745
required-ros-distributions: ${{ matrix.ros_distribution }}
4846

49-
- uses: actions/checkout@v5
47+
- uses: actions/checkout@v6
5048

5149
- name: Install dependencies
5250
shell: bash
@@ -61,7 +59,7 @@ jobs:
6159
npm run prebuild
6260
6361
- name: Upload prebuilt binary
64-
uses: actions/upload-artifact@v4
62+
uses: actions/upload-artifact@v7
6563
with:
6664
name: prebuilt-linux-x64-node${{ matrix.node-version }}-${{ matrix.ubuntu_codename }}-${{ matrix.ros_distribution }}
6765
path: prebuilds/linux-x64/*.node

0 commit comments

Comments
 (0)