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
name: Cross-platform Release
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+.[0-9]+'
env:
CARGO_TERM_COLOR: always
jobs:
build:
strategy:
matrix:
include:
# Linux
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
use-cross: true
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
use-cross: true
# macOS
- os: macos-latest
target: x86_64-apple-darwin
use-cross: false
- os: macos-latest
target: aarch64-apple-darwin
use-cross: false
# Windows
- os: windows-latest
target: x86_64-pc-windows-msvc
use-cross: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (for Linux cross-compilation)
if: ${{ matrix.use-cross }}
uses: taiki-e/install-action@v2
with:
tool: cross
- name: Get crate info (name & version)
id: crate_info
shell: bash
run: |
NAME=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].name')
VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
echo "name=$NAME" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Build binary
shell: bash
run: |
if ${{ matrix.use-cross }}; then
cross build --target ${{ matrix.target }} --release
else
cargo build --target ${{ matrix.target }} --release
fi
- name: Package binary with standard naming
shell: bash
env:
CRATE_NAME: ${{ steps.crate_info.outputs.name }}
VERSION: ${{ steps.crate_info.outputs.version }}
TARGET: ${{ matrix.target }}
run: |
set -e
cd target/${TARGET}/release
BINARY_NAME="$CRATE_NAME"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
FILENAME="${CRATE_NAME}-${VERSION}-${TARGET}"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
7z a "../../../${FILENAME}.zip" "$BINARY_NAME"
else
tar czf "../../../${FILENAME}.tar.gz" "$BINARY_NAME"
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.target }}
path: |
${{ steps.crate_info.outputs.name }}-${{ steps.crate_info.outputs.version }}-${{ matrix.target }}.tar.gz
${{ steps.crate_info.outputs.name }}-${{ steps.crate_info.outputs.version }}-${{ matrix.target }}.zip
publish:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Flatten artifacts directory (optional but cleaner)
run: |
mkdir -p release-assets
find ./artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec mv {} ./release-assets/ \;
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: ./release-assets/*