-
Notifications
You must be signed in to change notification settings - Fork 16
158 lines (144 loc) · 5.16 KB
/
Copy pathrelease-node.yml
File metadata and controls
158 lines (144 loc) · 5.16 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
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.1) — used for version sync'
required: true
default: 'v0.2.1'
permissions:
contents: read
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: Publish platform packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
for dir in sdks/node/npm/*/; do
OUTPUT=$((cd "$dir" && npm publish --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."
else
exit 1
fi
}
done
- name: Publish edgeparse (main package)
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd sdks/node
OUTPUT=$(npm publish --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."
else
exit 1
fi
}