-
Notifications
You must be signed in to change notification settings - Fork 5
348 lines (301 loc) · 11.6 KB
/
Copy pathrelease.yml
File metadata and controls
348 lines (301 loc) · 11.6 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
name: Release
permissions:
contents: write
id-token: write
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
# Check if native binaries are cached, build only if needed
prepare-native:
runs-on: ubuntu-latest
outputs:
native-hash: ${{ steps.hash.outputs.hash }}
cache-hit: ${{ steps.cache-check.outputs.cache-hit }}
steps:
- uses: actions/checkout@v4
- name: Calculate native source hash
id: hash
run: |
HASH=$(find native/src native/Cargo.toml native/Cargo.lock native/build.rs -type f -exec sha256sum {} \; 2>/dev/null | sort | sha256sum | cut -d' ' -f1)
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "Native source hash: $HASH"
- name: Check cache for pre-built binaries
id: cache-check
uses: actions/cache/restore@v4
with:
path: native-binaries-flat
key: native-${{ steps.hash.outputs.hash }}
lookup-only: true
# Build native modules only if not cached
build-native:
needs: prepare-native
if: needs.prepare-native.outputs.cache-hit != 'true'
strategy:
fail-fast: false
matrix:
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: pnpm
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross-compilation tools (Linux ARM64)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- run: pnpm install
- name: Build native module
run: |
cd native
pnpm napi build --platform --release --target ${{ matrix.target }}
env:
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.target }}
path: native/*.node
if-no-files-found: error
# Collect freshly built binaries and cache them
cache-new-binaries:
needs: [prepare-native, build-native]
if: needs.prepare-native.outputs.cache-hit != 'true'
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: native-binaries
- name: Flatten directory structure
run: |
mkdir -p native-binaries-flat
find native-binaries -name "*.node" -exec cp {} native-binaries-flat/ \;
ls -la native-binaries-flat/
- name: Cache native binaries for future releases
uses: actions/cache/save@v4
with:
path: native-binaries-flat
key: native-${{ needs.prepare-native.outputs.native-hash }}
# Publish platform-specific npm packages (only if native code changed)
publish-native:
needs: [prepare-native, build-native, cache-new-binaries]
# Only run if native code changed (cache miss means we built new binaries)
if: always() && !failure() && !cancelled() && needs.prepare-native.outputs.cache-hit != 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
cache: pnpm
- run: pnpm install
# Try to restore from cache first
- name: Restore cached binaries
id: cache-restore
if: needs.prepare-native.outputs.cache-hit == 'true'
uses: actions/cache/restore@v4
with:
path: native-binaries-flat
key: native-${{ needs.prepare-native.outputs.native-hash }}
- name: Copy cached binaries to native/
if: steps.cache-restore.outputs.cache-hit == 'true'
run: |
cp native-binaries-flat/*.node native/
ls -la native/*.node
# Or download freshly built artifacts
- name: Download build artifacts
if: needs.prepare-native.outputs.cache-hit != 'true'
uses: actions/download-artifact@v4
with:
path: native/artifacts
- name: Move artifacts to native/
if: needs.prepare-native.outputs.cache-hit != 'true'
run: |
cd native
for dir in artifacts/bindings-*; do
cp "$dir"/*.node . 2>/dev/null || true
done
ls -la *.node
- name: Update native package version
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
cd native
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.version = '$VERSION';
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
- name: Create npm packages
run: |
cd native
pnpm napi create-npm-dirs
ls -la npm/
- name: Copy binaries to npm packages
run: |
cd native
for node_file in *.node; do
platform=$(echo "$node_file" | sed 's/graphql-lint\.//' | sed 's/\.node//')
target_dir="npm/$platform"
if [ -d "$target_dir" ]; then
cp "$node_file" "$target_dir/"
echo "Copied $node_file to $target_dir/"
else
echo "Warning: $target_dir not found for $node_file"
fi
done
- name: Add repository to platform packages
run: |
cd native
for pkg in npm/*/package.json; do
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('$pkg', 'utf8'));
pkg.repository = {
type: 'git',
url: 'https://github.com/productdevbook/nitro-graphql'
};
fs.writeFileSync('$pkg', JSON.stringify(pkg, null, 2) + '\n');
"
done
- name: Determine npm tag
id: npm-tag
run: |
if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish platform packages
run: |
cd native
for pkg in npm/*/; do
if [ -f "$pkg/package.json" ]; then
echo "Publishing $pkg"
cd "$pkg"
pnpm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} --no-git-checks || true
cd ../..
fi
done
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Publish main package
release:
needs: [prepare-native, publish-native]
# Always run (publish-native might be skipped if native code unchanged)
if: always() && !failure() && !cancelled()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
registry-url: 'https://registry.npmjs.org'
cache: pnpm
- run: pnpm install
- name: Determine native package version
id: native-version
run: |
RELEASE_VERSION="${{ github.ref_name }}"
RELEASE_VERSION="${RELEASE_VERSION#v}"
# Determine npm tag based on release version
if [[ "$RELEASE_VERSION" == *"-beta"* ]] || [[ "$RELEASE_VERSION" == *"-rc"* ]] || [[ "$RELEASE_VERSION" == *"-alpha"* ]]; then
NPM_TAG="beta"
else
NPM_TAG="latest"
fi
# If native code changed, use current release version
# If not changed, get published version from appropriate npm tag
if [ "${{ needs.prepare-native.outputs.cache-hit }}" == "true" ]; then
echo "Native code unchanged, fetching published version from @${NPM_TAG} tag..."
NATIVE_VERSION=$(npm view nitro-graphql-linux-x64-gnu@${NPM_TAG} version 2>/dev/null || echo "$RELEASE_VERSION")
echo "Using existing native version: $NATIVE_VERSION"
else
echo "Native code changed, using release version: $RELEASE_VERSION"
NATIVE_VERSION="$RELEASE_VERSION"
fi
echo "version=$NATIVE_VERSION" >> $GITHUB_OUTPUT
- name: Add native package dependencies
run: |
NATIVE_VERSION="${{ steps.native-version.outputs.version }}"
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
pkg.optionalDependencies = {
'nitro-graphql-darwin-arm64': '$NATIVE_VERSION',
'nitro-graphql-darwin-x64': '$NATIVE_VERSION',
'nitro-graphql-linux-x64-gnu': '$NATIVE_VERSION',
'nitro-graphql-linux-arm64-gnu': '$NATIVE_VERSION',
'nitro-graphql-win32-x64-msvc': '$NATIVE_VERSION'
};
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n');
"
echo "optionalDependencies set to version: $NATIVE_VERSION"
cat package.json | grep -A 6 optionalDependencies
- run: pnpm tsdown
- name: Determine npm tag
id: npm-tag
run: |
if [[ "${{ github.ref_name }}" == *"-beta"* ]] || [[ "${{ github.ref_name }}" == *"-rc"* ]] || [[ "${{ github.ref_name }}" == *"-alpha"* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: pnpm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Get previous tag
id: prev-tag
run: |
PREV_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
echo "tag=$PREV_TAG" >> $GITHUB_OUTPUT
- name: Generate changelog
run: |
if [ -n "${{ steps.prev-tag.outputs.tag }}" ]; then
pnpm dlx changelogithub --from ${{ steps.prev-tag.outputs.tag }}
else
pnpm dlx changelogithub
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
echo "## Release Complete 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Version:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Native Version:** ${{ steps.native-version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.prepare-native.outputs.cache-hit }}" == "true" ]; then
echo "**Native Build:** ⏭️ Skipped (unchanged, using cached)" >> $GITHUB_STEP_SUMMARY
else
echo "**Native Build:** ✅ Built & Published" >> $GITHUB_STEP_SUMMARY
fi
echo "**Cache Key:** \`native-${{ needs.prepare-native.outputs.native-hash }}\`" >> $GITHUB_STEP_SUMMARY