forked from zdz/ServerStatus-Rust
-
Notifications
You must be signed in to change notification settings - Fork 0
208 lines (182 loc) · 6.41 KB
/
release.yml
File metadata and controls
208 lines (182 loc) · 6.41 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
name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
jobs:
# --- macOS 编译 ---
macos:
runs-on: macos-latest
name: macos (${{ matrix.platform.target }})
permissions:
contents: write
strategy:
fail-fast: true
matrix:
platform:
- target: "aarch64-apple-darwin"
- target: "x86_64-apple-darwin"
steps:
- uses: actions/checkout@v4
- name: Install Protoc
run: brew install protobuf
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Build release
run: cargo build --release --locked --target ${{ matrix.platform.target }}
- name: Strip & UPX
continue-on-error: true
run: |
strip target/${{ matrix.platform.target }}/release/stat_server
strip target/${{ matrix.platform.target }}/release/stat_client
shell: bash
- name: Zip Release
uses: TheDoctor0/zip-release@0.7.6
with:
type: zip
filename: ServerStatus-${{ matrix.platform.target }}.zip
directory: ./
path: |
target/${{ matrix.platform.target }}/release/stat_server
target/${{ matrix.platform.target }}/release/stat_client
config.toml
- name: Upload binaries to GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
with:
tag_name: ${{ github.ref_name }}
files: ServerStatus-${{ matrix.platform.target }}.zip
generate_release_notes: true
draft: false
# --- Linux Musl 编译 ---
linux:
runs-on: ubuntu-latest
name: linux (${{ matrix.platform.target }})
permissions:
contents: write
strategy:
fail-fast: true
matrix:
platform:
- target: "x86_64-unknown-linux-musl"
- target: "aarch64-unknown-linux-musl"
container:
image: docker://ghcr.io/rust-cross/rust-musl-cross:${{ matrix.platform.target }}
steps:
- uses: actions/checkout@v4
- name: Install Protoc & Utils
run: |
apt-get update -y -qq
apt-get install -y -qq protobuf-compiler zip git llvm
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Build release
run: cargo build --release --locked --target ${{ matrix.platform.target }}
- name: Strip & UPX
continue-on-error: true
uses: svenstaro/upx-action@v2
with:
files: |
target/${{ matrix.platform.target }}/release/stat_server
target/${{ matrix.platform.target }}/release/stat_client
args: --best --lzma
- name: Zip Release
uses: TheDoctor0/zip-release@0.7.6
with:
type: zip
filename: ServerStatus-${{ matrix.platform.target }}.zip
directory: ./
path: |
target/${{ matrix.platform.target }}/release/stat_server
target/${{ matrix.platform.target }}/release/stat_client
config.toml
- name: Upload binaries to GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
with:
tag_name: ${{ github.ref_name }}
files: ServerStatus-${{ matrix.platform.target }}.zip
generate_release_notes: true
draft: false
# --- Windows & Android 编译 ---
windows-or-linux-others:
name: Cross build for ${{ matrix.platform.target }}
runs-on: ${{ matrix.platform.os }}
permissions:
contents: write
strategy:
matrix:
platform:
- os: ubuntu-latest
target: aarch64-linux-android
suffix: ""
use-cross: true
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
suffix: ""
use-cross: true
- os: windows-latest
target: x86_64-pc-windows-msvc
suffix: .exe
use-cross: false
steps:
- uses: actions/checkout@v4
- name: Install Protoc
run: |
if [ "${{ matrix.platform.os }}" = "windows-latest" ]; then
choco install protoc --no-progress
else
sudo apt-get update && sudo apt-get install -y protobuf-compiler
fi
shell: bash
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.platform.target }}
- name: Install Cross
if: matrix.platform.use-cross
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build release
run: |
if [ "${{ matrix.platform.use-cross }}" = "true" ]; then
cross build --locked --release --target=${{ matrix.platform.target }}
else
cargo build --locked --release --target=${{ matrix.platform.target }}
fi
shell: bash
- name: Strip & UPX
continue-on-error: true
uses: svenstaro/upx-action@v2
with:
files: |
target/${{ matrix.platform.target }}/release/stat_server${{matrix.platform.suffix}}
target/${{ matrix.platform.target }}/release/stat_client${{matrix.platform.suffix}}
args: --best --lzma
# 修复:显式拷贝文件到统一目录,避免 Windows 打包找不到路径
- name: Prepare Assets
run: |
mkdir -p ./assets/
cp target/${{ matrix.platform.target }}/release/stat_server${{matrix.platform.suffix}} ./assets/
cp target/${{ matrix.platform.target }}/release/stat_client${{matrix.platform.suffix}} ./assets/
cp config.toml ./assets/
shell: bash
- name: Zip Release
uses: TheDoctor0/zip-release@0.7.6
with:
type: zip
filename: ServerStatus-${{ matrix.platform.target }}.zip
directory: ./assets/
path: .
- name: Upload binaries to GitHub Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
with:
tag_name: ${{ github.ref_name }}
files: ./assets/ServerStatus-${{ matrix.platform.target }}.zip
generate_release_notes: true
draft: false