Skip to content

Commit 1eb2bfb

Browse files
committed
Merge branch 'dev'
2 parents d39798f + a51a89d commit 1eb2bfb

File tree

3 files changed

+195
-3
lines changed

3 files changed

+195
-3
lines changed

.claude/settings.local.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
"Bash(cargo test:*)",
1414
"Bash(../../target/release/mdz pack:*)",
1515
"Bash(cat:*)",
16-
"Bash(python3:*)"
16+
"Bash(python3:*)",
17+
"Bash(mkdir:*)",
18+
"Bash(git add:*)",
19+
"Bash(git commit:*)"
1720
]
1821
}
1922
}

.github/workflows/release.yml

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
11+
jobs:
12+
# 测试所有平台和 Rust 版本
13+
test:
14+
name: Test
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ubuntu-latest, windows-latest, macos-latest]
19+
rust: [stable, beta]
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install Rust
24+
uses: dtolnay/rust-toolchain@master
25+
with:
26+
toolchain: ${{ matrix.rust }}
27+
28+
- name: Cache dependencies
29+
uses: actions/cache@v4
30+
with:
31+
path: |
32+
~/.cargo/registry
33+
~/.cargo/git
34+
target
35+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
36+
37+
- name: Run tests
38+
run: cargo test --verbose --all-features
39+
40+
- name: Run clippy
41+
run: cargo clippy --all-features -- -D warnings
42+
43+
# 发布到 crates.io
44+
publish:
45+
name: Publish to crates.io
46+
runs-on: ubuntu-latest
47+
needs: test
48+
steps:
49+
- uses: actions/checkout@v4
50+
51+
- name: Install Rust
52+
uses: dtolnay/rust-toolchain@stable
53+
54+
- name: Cache dependencies
55+
uses: actions/cache@v4
56+
with:
57+
path: |
58+
~/.cargo/registry
59+
~/.cargo/git
60+
target
61+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
62+
63+
- name: Extract version from tag
64+
id: version
65+
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
66+
67+
- name: Verify version matches
68+
run: |
69+
# 检查库版本是否匹配标签
70+
LIB_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "mdz-rs") | .version')
71+
if [ "$LIB_VERSION" != "${{ steps.version.outputs.VERSION }}" ]; then
72+
echo "Version mismatch: tag is ${{ steps.version.outputs.VERSION }}, but library version is $LIB_VERSION"
73+
exit 1
74+
fi
75+
76+
- name: Publish mdz-rs to crates.io
77+
run: cargo publish -p mdz-rs --token ${{ secrets.CRATES_IO_TOKEN }}
78+
79+
- name: Wait for mdz-rs to be available
80+
run: sleep 30
81+
82+
- name: Publish mdz to crates.io
83+
run: cargo publish -p mdz --token ${{ secrets.CRATES_IO_TOKEN }}
84+
85+
# 构建 GitHub Releases
86+
release:
87+
name: Create GitHub Release
88+
runs-on: ubuntu-latest
89+
needs: publish
90+
steps:
91+
- uses: actions/checkout@v4
92+
93+
- name: Install Rust
94+
uses: dtolnay/rust-toolchain@stable
95+
with:
96+
targets: x86_64-unknown-linux-musl,x86_64-pc-windows-gnu,x86_64-apple-darwin
97+
98+
- name: Cache dependencies
99+
uses: actions/cache@v4
100+
with:
101+
path: |
102+
~/.cargo/registry
103+
~/.cargo/git
104+
target
105+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
106+
107+
- name: Build for Linux
108+
run: |
109+
sudo apt-get update
110+
sudo apt-get install musl-tools
111+
cargo build --release --target x86_64-unknown-linux-musl
112+
113+
- name: Build for Windows
114+
run: cargo build --release --target x86_64-pc-windows-gnu
115+
116+
- name: Build for macOS
117+
run: cargo build --release --target x86_64-apple-darwin
118+
119+
- name: Prepare release assets
120+
run: |
121+
mkdir -p release
122+
123+
# Linux binary
124+
cp target/x86_64-unknown-linux-musl/release/mdz release/mdz-linux-x86_64
125+
tar -C release -czf release/mdz-linux-x86_64.tar.gz mdz-linux-x86_64
126+
127+
# Windows binary
128+
cp target/x86_64-pc-windows-gnu/release/mdz.exe release/mdz-windows-x86_64.exe
129+
cd release && zip -r mdz-windows-x86_64.zip mdz-windows-x86_64.exe && cd ..
130+
131+
# macOS binary
132+
cp target/x86_64-apple-darwin/release/mdz release/mdz-macos-x86_64
133+
tar -C release -czf release/mdz-macos-x86_64.tar.gz mdz-macos-x86_64
134+
135+
- name: Extract changelog
136+
id: changelog
137+
run: |
138+
if [ -f CHANGELOG.md ]; then
139+
# 提取最新版本的 changelog
140+
awk '/^## \[/ { if (found) exit; found=1; next } found' CHANGELOG.md > CHANGELOG_LATEST.md
141+
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
142+
cat CHANGELOG_LATEST.md >> $GITHUB_OUTPUT
143+
echo "EOF" >> $GITHUB_OUTPUT
144+
else
145+
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
146+
echo "See [README.md](README.md) for usage information." >> $GITHUB_OUTPUT
147+
echo "EOF" >> $GITHUB_OUTPUT
148+
fi
149+
150+
- name: Create Release
151+
uses: softprops/action-gh-release@v2
152+
with:
153+
tag_name: ${{ github.ref_name }}
154+
name: MDZ ${{ github.ref_name }}
155+
body: |
156+
## MDZ ${{ github.ref_name }}
157+
158+
${{ steps.changelog.outputs.CHANGELOG }}
159+
160+
### Installation
161+
162+
#### Cargo
163+
```bash
164+
cargo install mdz
165+
```
166+
167+
#### Binary Downloads
168+
169+
Download the appropriate binary for your platform:
170+
- Linux: `mdz-linux-x86_64.tar.gz`
171+
- Windows: `mdz-windows-x86_64.zip`
172+
- macOS: `mdz-macos-x86_64.tar.gz`
173+
174+
After downloading, extract the archive and place the `mdz` binary in your PATH.
175+
176+
### Verification
177+
178+
You can verify the installation by running:
179+
```bash
180+
mdz --version
181+
```
182+
files: |
183+
release/mdz-linux-x86_64.tar.gz
184+
release/mdz-windows-x86_64.zip
185+
release/mdz-macos-x86_64.tar.gz
186+
draft: false
187+
prerelease: false
188+
env:
189+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)