-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (149 loc) · 5.47 KB
/
Copy pathrelease.yml
File metadata and controls
178 lines (149 loc) · 5.47 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
name: Release
on:
push:
tags:
- 'v*.*.*'
jobs:
build-linux:
name: Build – ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian
artifact: symphony.linux-x64-gnu.node
- target: x86_64-unknown-linux-musl
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
artifact: symphony.linux-x64-musl.node
- target: aarch64-unknown-linux-gnu
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64
artifact: symphony.linux-arm64-gnu.node
- target: aarch64-unknown-linux-musl
image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
artifact: symphony.linux-arm64-musl.node
steps:
- uses: actions/checkout@v4
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ matrix.target }}-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: ${{ matrix.target }}-cargo-
- name: Build (${{ matrix.target }})
uses: addnab/docker-run-action@v3
with:
image: ${{ matrix.image }}
options: >-
-v ${{ github.workspace }}:/build
-v ${{ env.HOME }}/.cargo/registry:/usr/local/cargo/registry
-v ${{ env.HOME }}/.cargo/git:/usr/local/cargo/git
-w /build
run: |
set -e
rustup update stable
npm ci --ignore-scripts
if [ "${{ matrix.target }}" = "aarch64-unknown-linux-musl" ]; then
rustup target add aarch64-unknown-linux-musl
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER=aarch64-linux-musl-gcc
export CC_aarch64_unknown_linux_musl=aarch64-linux-musl-gcc
fi
npm run build -- --target ${{ matrix.target }}
strip --strip-unneeded ${{ matrix.artifact }} 2>/dev/null || true
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: ${{ matrix.artifact }}
if-no-files-found: error
build-macos:
name: Build – macOS (arm64 + x64)
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install Rust targets
run: |
rustup target add aarch64-apple-darwin
rustup target add x86_64-apple-darwin
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: macos-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: macos-cargo-
- name: Install dependencies
run: npm install --ignore-scripts
- name: Build aarch64-apple-darwin
run: npm run build -- --target aarch64-apple-darwin
- name: Build x86_64-apple-darwin
run: npm run build -- --target x86_64-apple-darwin
- name: Upload aarch64 artifact
uses: actions/upload-artifact@v4
with:
name: symphony.darwin-arm64.node
path: symphony.darwin-arm64.node
if-no-files-found: error
- name: Upload x64 artifact
uses: actions/upload-artifact@v4
with:
name: symphony.darwin-x64.node
path: symphony.darwin-x64.node
if-no-files-found: error
publish:
name: Publish to npm
runs-on: ubuntu-latest
needs: [build-linux, build-macos]
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm install -g npm@latest && npm install --ignore-scripts
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move artifacts into npm/ packages
run: npx napi artifacts --dir artifacts --dist npm
- name: Compile TypeScript
run: tsc -p tsconfig.json || true
- name: Set optionalDependencies in package.json
run: |
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
pkg.optionalDependencies = {};
const dirs = fs.readdirSync('./npm').filter(d => fs.statSync('./npm/' + d).isDirectory());
for (const dir of dirs) {
const sub = JSON.parse(fs.readFileSync('./npm/' + dir + '/package.json', 'utf8'));
pkg.optionalDependencies[sub.name] = sub.version;
}
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, '\t') + '\n');
console.log('optionalDependencies:', JSON.stringify(pkg.optionalDependencies, null, 2));
"
- name: Publish platform packages
run: |
for dir in npm/*/; do
npm publish "$dir" --provenance --access public
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish main package
run: npm publish --provenance --access public --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}