-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (135 loc) · 5.32 KB
/
release.yml
File metadata and controls
152 lines (135 loc) · 5.32 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
name: Rust Build, Test and Release
on:
push:
tags:
- 'v*'
env:
BINARY_NAME: proxy-convert
RUST_BACKTRACE: 1
jobs:
build:
name: Build ${{ matrix.target }}
runs-on: ${{ matrix.runner || matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Linux glibc + musl static
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
# macOS
- os: macos-14
target: x86_64-apple-darwin
- os: macos-14
target: aarch64-apple-darwin
# Windows (aarch64 使用 windows-11-arm runner,os 名称仍为 windows-latest)
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: windows-latest
target: aarch64-pc-windows-msvc
runner: windows-11-arm
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
targets: ${{ matrix.target }}
- name: Cache cargo
uses: Swatinem/rust-cache@v2.8.2
with:
key: ${{ matrix.target }}
shared-key: release
- name: Install Linux deps (glibc cross)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross binutils-aarch64-linux-gnu
- name: Set env for Linux aarch64 cross (glibc)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'aarch64-unknown-linux-gnu'
run: |
echo "CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
echo "CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++" >> $GITHUB_ENV
echo "AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar" >> $GITHUB_ENV
echo "RANLIB_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ranlib" >> $GITHUB_ENV
echo "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
- name: Install musl (Linux static, x86_64 only)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt-get update && sudo apt-get install -y musl-tools
- name: Set env for musl (x86_64)
if: matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-musl'
run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> $GITHUB_ENV
- name: Build
run: cargo build --release --target ${{ matrix.target }} --verbose
- name: Test binary
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
else
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
fi
if [ ! -f "$exe" ]; then
echo "Binary not found: $exe"
exit 1
fi
# Only run binary on native target (cross-compiled binaries cannot run on host)
if [ "${{ matrix.os }}" = "ubuntu-latest" ] && [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
"$exe" --version
elif [ "${{ matrix.os }}" = "windows-latest" ] && { [ "${{ matrix.target }}" = "x86_64-pc-windows-msvc" ] || [ "${{ matrix.target }}" = "aarch64-pc-windows-msvc" ]; }; then
"$exe" --version
elif [ "${{ matrix.os }}" = "macos-14" ] && [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then
"$exe" --version
else
echo "Skipping execution (cross-compiled target)."
fi
- name: Package
shell: bash
run: |
if [ "${{ matrix.os }}" = "windows-latest" ]; then
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe"
out="${{ env.BINARY_NAME }}-${{ matrix.target }}.zip"
mkdir -p release
cp "$exe" release/
(cd release && 7z a "$out" "${{ env.BINARY_NAME }}.exe")
else
exe="target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}"
out="${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz"
mkdir -p release
cp "$exe" release/
(cd release && tar czvf "$out" "${{ env.BINARY_NAME }}")
fi
echo "PACKAGE_PATH=release/$out" >> $GITHUB_ENV
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target }}
path: ${{ env.PACKAGE_PATH }}
release:
name: Create Release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
draft: false
prerelease: false
files: |
artifacts/*/*.tar.gz
artifacts/*/*.zip