-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (186 loc) · 6.81 KB
/
release.yml
File metadata and controls
222 lines (186 loc) · 6.81 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
name: Release
on:
push:
tags:
- 'v*'
env:
CARGO_TERM_COLOR: always
jobs:
# 运行测试以确保发布版本质量
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build binaries
run: cargo build --verbose --all-features
- name: Run tests
run: cargo test --verbose --all-features
- name: Run clippy
run: cargo clippy --all-features -- -D warnings
# 发布到 crates.io
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Extract version from tag
id: version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Verify version matches
run: |
# 检查库版本是否匹配标签
LIB_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "mdz-rs") | .version')
if [ "$LIB_VERSION" != "${{ steps.version.outputs.VERSION }}" ]; then
echo "Version mismatch: tag is ${{ steps.version.outputs.VERSION }}, but library version is $LIB_VERSION"
exit 1
fi
- name: Publish mdz-rs to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
echo "Checking if mdz-rs ${{ steps.version.outputs.VERSION }} exists..."
if cargo publish --dry-run -p mdz-rs 2>&1 | grep -q "already exists"; then
echo "mdz-rs ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
elif cargo publish --dry-run -p mdz-rs; then
echo "Publishing mdz-rs to crates.io..."
cargo publish -p mdz-rs
else
echo "Failed to check mdz-rs publish status"
exit 1
fi
- name: Wait for mdz-rs to be available
run: |
if cargo publish --dry-run -p mdz-rs 2>&1 | grep -q "already exists"; then
echo "mdz-rs version already exists, no need to wait"
else
echo "New mdz-rs version published, waiting..."
sleep 30
fi
- name: Publish mdz to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
echo "Checking if mdz ${{ steps.version.outputs.VERSION }} exists..."
if cargo publish --dry-run -p mdz 2>&1 | grep -q "already exists"; then
echo "mdz ${{ steps.version.outputs.VERSION }} already exists, skipping publish"
elif cargo publish --dry-run -p mdz; then
echo "Publishing mdz to crates.io..."
cargo publish -p mdz
else
echo "Failed to check mdz publish status"
exit 1
fi
# 构建 GitHub Releases
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: publish
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-unknown-linux-musl,x86_64-pc-windows-gnu,x86_64-apple-darwin
- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build for Linux
run: |
sudo apt-get update
sudo apt-get install musl-tools
cargo build --release --target x86_64-unknown-linux-musl
- name: Build for Windows
run: cargo build --release --target x86_64-pc-windows-gnu
- name: Build for macOS
run: cargo build --release --target x86_64-apple-darwin
- name: Prepare release assets
run: |
mkdir -p release
# Linux binary
cp target/x86_64-unknown-linux-musl/release/mdz release/mdz-linux-x86_64
tar -C release -czf release/mdz-linux-x86_64.tar.gz mdz-linux-x86_64
# Windows binary
cp target/x86_64-pc-windows-gnu/release/mdz.exe release/mdz-windows-x86_64.exe
cd release && zip -r mdz-windows-x86_64.zip mdz-windows-x86_64.exe && cd ..
# macOS binary
cp target/x86_64-apple-darwin/release/mdz release/mdz-macos-x86_64
tar -C release -czf release/mdz-macos-x86_64.tar.gz mdz-macos-x86_64
- name: Extract changelog
id: changelog
run: |
if [ -f CHANGELOG.md ]; then
# 提取最新版本的 changelog
awk '/^## \[/ { if (found) exit; found=1; next } found' CHANGELOG.md > CHANGELOG_LATEST.md
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
cat CHANGELOG_LATEST.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "See [README.md](README.md) for usage information." >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: MDZ ${{ github.ref_name }}
body: |
## MDZ ${{ github.ref_name }}
${{ steps.changelog.outputs.CHANGELOG }}
### Installation
#### Cargo
```bash
cargo install mdz
```
#### Binary Downloads
Download the appropriate binary for your platform:
- Linux: `mdz-linux-x86_64.tar.gz`
- Windows: `mdz-windows-x86_64.zip`
- macOS: `mdz-macos-x86_64.tar.gz`
After downloading, extract the archive and place the `mdz` binary in your PATH.
### Verification
You can verify the installation by running:
```bash
mdz --version
```
files: |
release/mdz-linux-x86_64.tar.gz
release/mdz-windows-x86_64.zip
release/mdz-macos-x86_64.tar.gz
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}