-
Notifications
You must be signed in to change notification settings - Fork 3
222 lines (189 loc) · 6.65 KB
/
npm-publish.yml
File metadata and controls
222 lines (189 loc) · 6.65 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
name: Publish npm packages
on:
release:
types: [published]
workflow_dispatch:
inputs:
dry_run:
description: "Dry run (skip actual publish)"
required: false
default: false
type: boolean
env:
CARGO_TERM_COLOR: always
jobs:
build-binaries:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux x64 (glibc)
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
npm-suffix: linux-x64-gnu
cross: false
# Linux x64 (musl)
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
npm-suffix: linux-x64-musl
cross: true
# Linux ARM64
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
npm-suffix: linux-arm64-gnu
cross: true
# macOS x64 (Intel) - cross-compile from ARM64 runner
- os: macos-latest
target: x86_64-apple-darwin
npm-suffix: darwin-x64
cross: false
# macOS ARM64 (Apple Silicon)
- os: macos-latest
target: aarch64-apple-darwin
npm-suffix: darwin-arm64
cross: false
# Windows x64
- os: windows-latest
target: x86_64-pc-windows-msvc
npm-suffix: win32-x64-msvc
cross: false
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
if: matrix.cross
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Build binary (cargo)
if: ${{ !matrix.cross }}
run: cargo build --release --target ${{ matrix.target }} -p yoop
- name: Build binary (cross)
if: matrix.cross
run: cross build --release --target ${{ matrix.target }} -p yoop
- name: Prepare artifact (Unix)
if: runner.os != 'Windows'
run: |
mkdir -p artifacts
cp target/${{ matrix.target }}/release/yoop artifacts/
chmod +x artifacts/yoop
- name: Prepare artifact (Windows)
if: runner.os == 'Windows'
run: |
mkdir -p artifacts
cp target/${{ matrix.target }}/release/yoop.exe artifacts/
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.npm-suffix }}
path: artifacts/
if-no-files-found: error
publish-npm:
name: Publish to npm
needs: build-binaries
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # For npm provenance
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: https://registry.npmjs.org
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Sync versions
run: node scripts/sync-versions.js
- name: Copy binaries to npm packages
run: |
# Linux x64 (glibc)
mkdir -p npm/@sanchxt/yoop-linux-x64-gnu/bin
cp artifacts/binary-linux-x64-gnu/yoop npm/@sanchxt/yoop-linux-x64-gnu/bin/
chmod +x npm/@sanchxt/yoop-linux-x64-gnu/bin/yoop
# Linux x64 (musl)
mkdir -p npm/@sanchxt/yoop-linux-x64-musl/bin
cp artifacts/binary-linux-x64-musl/yoop npm/@sanchxt/yoop-linux-x64-musl/bin/
chmod +x npm/@sanchxt/yoop-linux-x64-musl/bin/yoop
# Linux ARM64
mkdir -p npm/@sanchxt/yoop-linux-arm64-gnu/bin
cp artifacts/binary-linux-arm64-gnu/yoop npm/@sanchxt/yoop-linux-arm64-gnu/bin/
chmod +x npm/@sanchxt/yoop-linux-arm64-gnu/bin/yoop
# macOS x64
mkdir -p npm/@sanchxt/yoop-darwin-x64/bin
cp artifacts/binary-darwin-x64/yoop npm/@sanchxt/yoop-darwin-x64/bin/
chmod +x npm/@sanchxt/yoop-darwin-x64/bin/yoop
# macOS ARM64
mkdir -p npm/@sanchxt/yoop-darwin-arm64/bin
cp artifacts/binary-darwin-arm64/yoop npm/@sanchxt/yoop-darwin-arm64/bin/
chmod +x npm/@sanchxt/yoop-darwin-arm64/bin/yoop
# Windows x64
mkdir -p npm/@sanchxt/yoop-win32-x64-msvc/bin
cp artifacts/binary-win32-x64-msvc/yoop.exe npm/@sanchxt/yoop-win32-x64-msvc/bin/
- name: Publish platform packages
if: ${{ github.event.inputs.dry_run != 'true' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
# Publish all platform packages (skip if already published)
for pkg in npm/@sanchxt/yoop-*; do
pkg_name=$(basename $pkg)
echo "Publishing $pkg_name..."
cd "$pkg"
# Try to publish, capture output
if output=$(npm publish --access public --provenance 2>&1); then
echo " Published successfully"
else
if echo "$output" | grep -q "cannot publish over"; then
echo " Already published, skipping..."
else
echo "$output"
exit 1
fi
fi
cd - > /dev/null
done
- name: Wait for registry propagation
if: ${{ github.event.inputs.dry_run != 'true' }}
run: sleep 15
- name: Publish main package
if: ${{ github.event.inputs.dry_run != 'true' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
working-directory: npm/yoop
run: |
echo "Publishing yoop..."
if output=$(npm publish --access public --provenance 2>&1); then
echo "Published successfully!"
else
if echo "$output" | grep -q "cannot publish over"; then
echo "Already published, skipping..."
else
echo "$output"
exit 1
fi
fi
- name: Dry run - show what would be published
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo "=== DRY RUN - Would publish: ==="
echo ""
for pkg in npm/@sanchxt/yoop-*; do
echo "Package: $(basename $pkg)"
cat "$pkg/package.json" | grep -E '"(name|version)"'
ls -la "$pkg/bin/" 2>/dev/null || echo " (no binary yet)"
echo ""
done
echo "Main package: yoop"
cat npm/yoop/package.json | grep -E '"(name|version)"'