-
Notifications
You must be signed in to change notification settings - Fork 13
188 lines (171 loc) · 6.81 KB
/
release-node.yml
File metadata and controls
188 lines (171 loc) · 6.81 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Release — Node.js (npm)
on:
push:
tags: ['v[0-9]+.[0-9]+.[0-9]+']
workflow_dispatch:
inputs:
tag_name:
description: 'Tag name to publish (e.g. v0.2.2) — used for version sync'
required: true
default: 'v0.2.2'
permissions:
contents: write
id-token: write # required for npm Trusted Publisher (OIDC tokenless publish)
jobs:
build-native:
name: Build .node — ${{ matrix.target }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
node-platform: linux-x64-gnu
- target: aarch64-unknown-linux-gnu
runner: ubuntu-latest
node-platform: linux-arm64-gnu
use-zigbuild: true
- target: x86_64-apple-darwin
runner: macos-latest
node-platform: darwin-x64
- target: aarch64-apple-darwin
runner: macos-14
node-platform: darwin-arm64
- target: x86_64-pc-windows-msvc
runner: windows-latest
node-platform: win32-x64-msvc
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with: { targets: '${{ matrix.target }}' }
- uses: Swatinem/rust-cache@v2
- name: Install zig + cargo-zigbuild (for aarch64 Linux cross)
if: matrix.use-zigbuild
run: |
pip install ziglang
cargo install cargo-zigbuild --locked
- name: Build Rust binding
run: |
if [[ "${{ matrix.use-zigbuild }}" == "true" ]]; then
cargo zigbuild --release --target ${{ matrix.target }}.2.17 -p edgeparse-node
else
cargo build --release --target ${{ matrix.target }} -p edgeparse-node
fi
shell: bash
- name: Rename .node artifact
shell: bash
run: |
TARGET="${{ matrix.target }}"
if [[ "$TARGET" == *"windows"* ]]; then
SRC="target/${TARGET}/release/edgeparse_node.dll"
elif [[ "$TARGET" == *"apple"* ]]; then
SRC="target/${TARGET}/release/libedgeparse_node.dylib"
else
SRC="target/${TARGET}/release/libedgeparse_node.so"
fi
DEST="sdks/node/npm/${{ matrix.node-platform }}/edgeparse-node.${{ matrix.node-platform }}.node"
mkdir -p "sdks/node/npm/${{ matrix.node-platform }}"
cp "$SRC" "$DEST"
- uses: actions/upload-artifact@v4
with:
name: node-${{ matrix.node-platform }}
path: sdks/node/npm/${{ matrix.node-platform }}/
publish-npm:
name: Publish to npm
needs: build-native
runs-on: ubuntu-latest
environment: npm
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v4
with:
merge-multiple: true
path: sdks/node/npm/
- name: Sync version
env:
INPUT_TAG_NAME: ${{ inputs.tag_name }}
run: |
node -e "
const fs = require('fs');
const refName = process.env.INPUT_TAG_NAME || process.env.GITHUB_REF_NAME;
const version = refName.replace(/^v/, '');
const dirs = [
'sdks/node',
...fs.readdirSync('sdks/node/npm').map(d => \`sdks/node/npm/\${d}\`)
];
dirs.forEach(dir => {
const p = \`\${dir}/package.json\`;
if (fs.existsSync(p)) {
const pkg = JSON.parse(fs.readFileSync(p, 'utf8'));
// Update optionalDependencies versions
Object.keys(pkg.optionalDependencies || {}).forEach(k => {
pkg.optionalDependencies[k] = version;
});
pkg.version = version;
fs.writeFileSync(p, JSON.stringify(pkg, null, 2) + '\n');
}
});
console.log('Version synced to: ' + version);
"
- run: |
cd sdks/node
npm ci
npm run build:ts
- name: Ensure GitHub Release exists
env:
GH_TOKEN: ${{ github.token }}
INPUT_TAG_NAME: ${{ inputs.tag_name }}
run: |
TAG_NAME="${INPUT_TAG_NAME:-$GITHUB_REF_NAME}"
gh release view "$TAG_NAME" --repo "${{ github.repository }}" \
|| gh release create "$TAG_NAME" \
--repo "${{ github.repository }}" \
--title "$TAG_NAME" \
--generate-notes
- name: Pack npm tarballs
run: |
mkdir -p release-assets/node
for dir in sdks/node/npm/*/; do
(cd "$dir" && npm pack --pack-destination "$GITHUB_WORKSPACE/release-assets/node")
done
(cd sdks/node && npm pack --pack-destination "$GITHUB_WORKSPACE/release-assets/node")
- name: Upload npm tarballs to GitHub Release
env:
GH_TOKEN: ${{ github.token }}
INPUT_TAG_NAME: ${{ inputs.tag_name }}
run: |
TAG_NAME="${INPUT_TAG_NAME:-$GITHUB_REF_NAME}"
gh release upload "$TAG_NAME" release-assets/node/*.tgz \
--repo "${{ github.repository }}" --clobber
- name: Publish platform packages
run: |
for dir in sdks/node/npm/*/; do
OUTPUT=$((cd "$dir" && npm publish --provenance --access public) 2>&1) && echo "$OUTPUT" || {
echo "$OUTPUT"
if echo "$OUTPUT" | grep -Eq "cannot publish over the previously published versions|You cannot publish over the previously published version"; then
echo "::warning::Package already published for $dir — skipping."
elif echo "$OUTPUT" | grep -Eq "E403|403 Forbidden|You may not perform that action with these credentials"; then
echo "::warning::npm publish is unavailable for $dir with the current credentials — keeping the tarball on the GitHub Release instead."
else
exit 1
fi
}
done
- name: Publish edgeparse (main package)
run: |
cd sdks/node
OUTPUT=$(npm publish --provenance --access public 2>&1) && echo "$OUTPUT" || {
echo "$OUTPUT"
if echo "$OUTPUT" | grep -Eq "cannot publish over the previously published versions|You cannot publish over the previously published version"; then
echo "edgeparse already published at this version — skipping."
elif echo "$OUTPUT" | grep -Eq "E403|403 Forbidden|You may not perform that action with these credentials"; then
echo "::warning::npm publish is unavailable for the main package with the current credentials — keeping the tarball on the GitHub Release instead."
else
exit 1
fi
}