-
Notifications
You must be signed in to change notification settings - Fork 85
115 lines (100 loc) · 3.49 KB
/
Copy pathnpm-publish.yml
File metadata and controls
115 lines (100 loc) · 3.49 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
name: NPM Publish
on:
push:
tags:
# Match release tags (e.g. 1.9.0, 2.0.0) and prerelease tags
# (e.g. 2.0.0-beta.0, 1.9.0-alpha.0, 2.0.0-rc.1).
- '[0-9]+.[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+-*'
workflow_dispatch:
inputs:
dry_run:
description: 'Perform a dry run (skip actual publish)'
required: true
type: boolean
default: true
# Ensure only one publish runs at a time
concurrency:
group: npm-publish
cancel-in-progress: false
permissions:
contents: read
jobs:
prebuild-x64:
if: github.repository == 'RobotWebTools/rclnodejs'
uses: ./.github/workflows/prebuild-linux-x64.yml
prebuild-arm64:
if: github.repository == 'RobotWebTools/rclnodejs'
uses: ./.github/workflows/prebuild-linux-arm64.yml
publish:
needs: [prebuild-x64, prebuild-arm64]
runs-on: ubuntu-latest
environment: npm-publish
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24.x
registry-url: 'https://registry.npmjs.org'
- name: Download x64 prebuilds
uses: actions/download-artifact@v7
with:
pattern: prebuilt-linux-x64-*
path: prebuilds/linux-x64
merge-multiple: true
- name: Download arm64 prebuilds
uses: actions/download-artifact@v7
with:
pattern: prebuilt-linux-arm64-*
path: prebuilds/linux-arm64
merge-multiple: true
- name: List prebuilds
run: |
echo "=== x64 prebuilds ==="
ls -la prebuilds/linux-x64/
echo "=== arm64 prebuilds ==="
ls -la prebuilds/linux-arm64/
- name: Install dependencies
# --ignore-scripts skips install/postinstall (native build + message
# generation need a sourced ROS env, which this job doesn't have) while
# still installing devDependencies such as tsup needed for build:dist.
run: npm install --ignore-scripts
- name: Build dist (ESM/CJS bundles)
# npm-pack.sh packs with --ignore-scripts, so the prepack hook that
# normally runs build:dist is skipped. dist/ is git-ignored and absent
# on a fresh checkout, so build it explicitly before packing — the
# published package's main/module/exports all point at ./dist/*.
run: npm run build:dist
- name: Pack
run: ./scripts/npm-pack.sh
- name: Determine dist-tag
id: dist_tag
run: |
TAG=$(node -p "
const v = require('./package.json').version;
const pre = v.split('-')[1];
!pre ? 'latest' : (pre.split('.')[0].replace(/[0-9]+$/, '') || 'next')
")
if [[ -z "$TAG" ]]; then
echo "::error::Failed to determine dist-tag"
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "Resolved dist-tag: $TAG"
- name: Publish
run: |
TAG="${{ steps.dist_tag.outputs.tag }}"
if [[ -z "$TAG" ]]; then
echo "::error::dist-tag is empty, aborting publish"
exit 1
fi
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
echo "=== DRY RUN ==="
npm publish --provenance --access public --tag "$TAG" --dry-run ./pack/rclnodejs-*.tgz
else
npm publish --provenance --access public --tag "$TAG" ./pack/rclnodejs-*.tgz
fi