-
Notifications
You must be signed in to change notification settings - Fork 0
480 lines (419 loc) · 17.3 KB
/
Copy pathrelease.yml
File metadata and controls
480 lines (419 loc) · 17.3 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
name: Release Packages
permissions:
contents: write
on:
release:
types: [created]
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Optimize compilation speed and binary size (moved to .cargo/config.toml)
# RUSTFLAGS: "-C link-arg=-s"
jobs:
# Automatically create a GitHub Release when a tag is pushed
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
# Only run this job when a tag is pushed, not when a release is created
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract tag name
id: extract-tag
shell: bash
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
echo "VERSION=${TAG_NAME#v}" >> $GITHUB_OUTPUT
- name: Check if release exists
id: check-release
uses: octokit/request-action@v2.x
with:
route: GET /repos/${{ github.repository }}/releases/tags/${{ steps.extract-tag.outputs.TAG_NAME }}
owner: ${{ github.repository_owner }}
repo: ${{ github.repository.name }}
tag: ${{ steps.extract-tag.outputs.TAG_NAME }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Create GitHub Release
id: create-release
if: steps.check-release.outputs.status != '200'
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract-tag.outputs.TAG_NAME }}
name: Release ${{ steps.extract-tag.outputs.TAG_NAME }}
draft: false
prerelease: false
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Build binaries for all platforms
build-binaries:
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
continue-on-error: true # Continue workflow even if this job fails
needs: [create-release]
if: |
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) ||
github.event_name == 'release'
strategy:
fail-fast: false
matrix:
include:
# Linux targets
- name: Linux x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
short_target: linux-x86_64
- name: Linux ARM64
os: ubuntu-latest
target: aarch64-unknown-linux-gnu
short_target: linux-arm64
use_cross: true
- name: Linux ARM32 (armv7)
os: ubuntu-latest
target: armv7-unknown-linux-gnueabihf
short_target: linux-armv7
use_cross: true
- name: Linux ARM32 (Raspberry Pi)
os: ubuntu-latest
target: arm-unknown-linux-gnueabihf
short_target: linux-arm
use_cross: true
- name: Linux x86 (32-bit)
os: ubuntu-latest
target: i686-unknown-linux-gnu
short_target: linux-i686
use_cross: true
- name: Linux RISC-V 64-bit
os: ubuntu-latest
target: riscv64gc-unknown-linux-gnu
short_target: linux-riscv64
use_cross: true
- name: Linux MUSL x86_64
os: ubuntu-latest
target: x86_64-unknown-linux-musl
short_target: linux-musl-x86_64
# Windows targets
- name: Windows x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
short_target: windows-x86_64
is_windows: true
- name: Windows x86 (32-bit)
os: windows-latest
target: i686-pc-windows-msvc
short_target: windows-i686
is_windows: true
# macOS targets
- name: macOS x86_64
os: macos-latest
target: x86_64-apple-darwin
short_target: macos-x86_64
- name: macOS ARM64
os: macos-latest
target: aarch64-apple-darwin
short_target: macos-arm64
# Android targets
- name: Android ARM64
os: ubuntu-latest
target: aarch64-linux-android
short_target: android-arm64
use_cross: true
- name: Android ARM32
os: ubuntu-latest
target: armv7-linux-androideabi
short_target: android-arm
use_cross: true
- name: Android x86_64
os: ubuntu-latest
target: x86_64-linux-android
short_target: android-x86_64
use_cross: true
- name: Android x86
os: ubuntu-latest
target: i686-linux-android
short_target: android-x86
use_cross: true
# BSD targets
- name: FreeBSD x86_64
os: ubuntu-latest
target: x86_64-unknown-freebsd
short_target: freebsd-x86_64
use_cross: true
- name: NetBSD x86_64
os: ubuntu-latest
target: x86_64-unknown-netbsd
short_target: netbsd-x86_64
use_cross: true
# - name: OpenBSD x86_64
# os: ubuntu-latest
# target: x86_64-unknown-openbsd
# short_target: openbsd-x86_64
# use_cross: true
# Additional exotic targets
- name: WASM (WebAssembly)
os: ubuntu-latest
target: wasm32-unknown-unknown
short_target: wasm
use_cross: false
# - name: WASI (WebAssembly System Interface)
# os: ubuntu-latest
# target: wasm32-wasi
# short_target: wasi
# use_cross: false
- name: PowerPC 64-bit LE
os: ubuntu-latest
target: powerpc64le-unknown-linux-gnu
short_target: linux-ppc64le
use_cross: true
- name: IBM Z (s390x)
os: ubuntu-latest
target: s390x-unknown-linux-gnu
short_target: linux-s390x
use_cross: true
# - name: MIPS 64-bit
# os: ubuntu-latest
# target: mips64-unknown-linux-gnuabi64
# short_target: linux-mips64
# use_cross: true
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Extract version (for release naming)
- name: Extract version
id: extract-version
shell: bash
run: |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "VERSION_NUM=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
# Extract binary name from Cargo.toml
- name: Extract binary name
id: extract-binary
shell: bash
run: |
BINARY_NAME=$(grep '^name =' Cargo.toml | head -1 | awk '{print $3}' | tr -d '"')
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_OUTPUT
echo "Binary name is $BINARY_NAME"
# Install Linux dependencies
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config
if [[ "${{ matrix.target }}" == *"musl"* ]]; then
sudo apt-get install -y musl-tools
fi
# Set up Rust toolchain
- name: Install Rust (default)
if: matrix.target != 'x86_64-unknown-openbsd' && matrix.target != 'wasm32-wasi' && matrix.target != 'mips64-unknown-linux-gnuabi64'
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
# Set up nightly Rust toolchain for Tier 3 platforms
- name: Install Rust (Tier 3 platforms - nightly)
if: matrix.target == 'x86_64-unknown-openbsd' || matrix.target == 'wasm32-wasi' || matrix.target == 'mips64-unknown-linux-gnuabi64'
uses: dtolnay/rust-toolchain@nightly
with:
targets: ${{ matrix.target }}
# Setup Rust cache with better granularity
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
key: ${{ matrix.target }}
# Install Cross for cross-compilation targets
- name: Install Cross
if: matrix.use_cross == true
uses: taiki-e/install-action@v2
with:
tool: cross
# Cache Cross Docker images
- name: Cache Cross Docker images
if: matrix.use_cross == true
uses: actions/cache@v4
with:
path: ~/.docker
key: ${{ runner.os }}-docker-${{ matrix.target }}-${{ hashFiles('Cross.toml') }}
restore-keys: |
${{ runner.os }}-docker-${{ matrix.target }}-
${{ runner.os }}-docker-
# Set up Cross configuration (optional linker)
- name: Set up Cross configuration
if: matrix.use_cross == true
run: |
echo "[target.${{ matrix.target }}]" > Cross.toml
echo "linker = 'gcc'" >> Cross.toml
# Add LTO for smaller binaries
echo "[profile.release]" >> Cross.toml
echo "lto = true" >> Cross.toml
echo "codegen-units = 1" >> Cross.toml
echo "opt-level = 's'" >> Cross.toml
# Build the binary
- name: Build with Cross (Linux cross-compilation)
id: cross-build
if: matrix.os == 'ubuntu-latest' && matrix.use_cross == true
run: cross build --release --target ${{ matrix.target }}
continue-on-error: true # Don't fail the entire job if cross build fails
- name: Build with Cargo (native builds)
id: cargo-build
if: matrix.os != 'ubuntu-latest' || matrix.use_cross != true
run: cargo build --release --target ${{ matrix.target }}
shell: bash
continue-on-error: true # Don't fail the entire job if cargo build fails
# Check if build succeeded
- name: Check if build succeeded
id: check-build
shell: bash
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
FILE_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}.exe"
else
FILE_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}"
fi
if [[ -f "$FILE_PATH" && -s "$FILE_PATH" ]]; then
echo "build_succeeded=true" >> $GITHUB_OUTPUT
echo "✅ Build succeeded for ${{ matrix.name }}"
else
echo "build_succeeded=false" >> $GITHUB_OUTPUT
echo "❌ Build failed for ${{ matrix.name }}"
fi
# Validate binary (only if build succeeded)
- name: Validate binary
if: steps.check-build.outputs.build_succeeded == 'true'
shell: bash
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
FILE_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}.exe"
else
FILE_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}"
fi
# Check that file exists and has non-zero size
if [[ -f "$FILE_PATH" && -s "$FILE_PATH" ]]; then
echo "✅ Binary successfully built: $FILE_PATH"
ls -la "$FILE_PATH"
else
echo "❌ Failed to build binary or binary has zero size"
exit 1
fi
# Prepare artifacts (only if build succeeded)
- name: Create tarball (Linux/macOS)
if: runner.os != 'Windows' && steps.check-build.outputs.build_succeeded == 'true'
shell: bash
run: |
mkdir -p release
BINARY_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}"
cp $BINARY_PATH release/
cp LICENSE install.sh manifest.toml README.md release/ || echo "LICENSE or README.md not found, skipping"
# Add version info file
echo "Version: ${{ steps.extract-version.outputs.VERSION }}" > release/VERSION
echo "Build Date: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> release/VERSION
echo "Git Commit: $(git rev-parse HEAD)" >> release/VERSION
cd release
tar czf ../${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.tar.gz *
cd ..
shasum -a 256 ${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.tar.gz > ${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.tar.gz.sha256
- name: Create zip (Windows)
if: runner.os == 'Windows' && steps.check-build.outputs.build_succeeded == 'true'
shell: bash
run: |
mkdir release
BINARY_PATH="target/${{ matrix.target }}/release/${{ steps.extract-binary.outputs.BINARY_NAME }}${{ matrix.is_windows && '.exe' || '' }}"
cp $BINARY_PATH release/
cp LICENSE install.sh manifest.toml README.md release/ || echo "LICENSE or README.md not found, skipping"
# Add version info file
echo "Version: ${{ steps.extract-version.outputs.VERSION }}" > release/VERSION
echo "Build Date: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> release/VERSION
echo "Git Commit: $(git rev-parse HEAD)" >> release/VERSION
cd release
7z a -tzip ../${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.zip *
cd ..
certutil -hashfile ${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.zip SHA256 > ${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.zip.sha256
# Cleanup the certutil output to just the hash
sed -i -e '1d' -e '3d' ${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.zip.sha256
# Upload to GitHub Release (only if build succeeded)
- name: Upload to GitHub Release
if: steps.check-build.outputs.build_succeeded == 'true'
uses: softprops/action-gh-release@v2
with:
files: |
${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.${{ runner.os == 'Windows' && 'zip' || 'tar.gz' }}
${{ steps.extract-binary.outputs.BINARY_NAME }}-${{ matrix.short_target }}.${{ runner.os == 'Windows' && 'zip' || 'tar.gz' }}.sha256
tag_name: ${{ steps.extract-version.outputs.VERSION }} # Use extracted VERSION
fail_on_unmatched_files: false
make_latest: false
append_body: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Restore Cargo.lock from git if changed
- name: Restore Cargo.lock from git if changed
run: git checkout -- Cargo.lock
if: always()
# Job to summarize all builds
build-summary:
name: Build Summary
runs-on: ubuntu-latest
needs: build-binaries
if: always() # Always run this job, even if previous jobs failed
steps:
- name: Summary
run: |
echo "# Build Summary" >> $GITHUB_STEP_SUMMARY
echo "The build process has completed. Some platforms may have failed but the workflow continued." >> $GITHUB_STEP_SUMMARY
cargo-publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: build-binaries
# Only publish on tags
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
- name: Setup Rust cache
uses: Swatinem/rust-cache@v2
- name: Extract tag version (without 'v' prefix)
id: extract_version
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
echo "TAG_VERSION=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "Tag version: $TAG_VERSION"
- name: Extract Cargo.toml version
id: cargo_version
run: |
CARGO_VERSION=$(grep '^version =' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_OUTPUT
echo "Cargo.toml version: $CARGO_VERSION"
- name: Verify versions match
run: |
TAG_VERSION="${{ steps.extract_version.outputs.TAG_VERSION }}"
CARGO_VERSION="${{ steps.cargo_version.outputs.CARGO_VERSION }}"
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "::error::Version mismatch! Tag version ($TAG_VERSION) does not match Cargo.toml version ($CARGO_VERSION)"
echo "Please use the bump-version.sh script before tagging: ./scripts/bump-version.sh $TAG_VERSION"
exit 1
else
echo "✅ Versions match. Proceeding with publish."
fi
- name: Check if crate exists
id: check_crate
run: |
VERSION=${{ steps.extract_version.outputs.TAG_VERSION }}
EXISTS=$(cargo search ${{ steps.extract-binary.outputs.BINARY_NAME }} --limit 1 | grep -c "${{ steps.extract-binary.outputs.BINARY_NAME }} = \"$VERSION\"" || true)
echo "exists=$EXISTS" >> $GITHUB_OUTPUT
- name: Publish crate
if: steps.check_crate.outputs.exists == '0'
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}