Skip to content

Commit c4c8722

Browse files
committed
chore: workflows
1 parent b9c2f58 commit c4c8722

3 files changed

Lines changed: 79 additions & 116 deletions

File tree

.github/workflows/rust.yml

Lines changed: 75 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,112 @@
1-
# .github/workflows/rust.yml
2-
3-
name: Rust CI
1+
name: Build and Release
42

53
on:
64
push:
75
tags:
8-
- 'v*.*.*'
9-
10-
env:
11-
CARGO_TERM_COLOR: always # 让 cargo 输出带颜色,方便在日志中查看
6+
- "v*.*.*"
127

138
jobs:
14-
# --- 1. 测试和基础检查 ---
15-
test:
16-
name: Test Suite
17-
runs-on: ubuntu-latest
18-
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v4
21-
22-
- name: Install Rust
23-
uses: dtolnay/rust-toolchain@stable
24-
with:
25-
components: rustfmt, clippy
26-
27-
- name: Cache dependencies
28-
uses: actions/cache@v3
29-
with:
30-
path: |
31-
~/.cargo/bin/
32-
~/.cargo/registry/index/
33-
~/.cargo/registry/cache/
34-
~/.cargo/git/db/
35-
target/
36-
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
37-
restore-keys: |
38-
${{ runner.os }}-cargo-
39-
40-
- name: Check code formatting
41-
run: cargo fmt --all -- --check
42-
43-
- name: Run linter (Clippy)
44-
run: cargo clippy --all-targets --all-features -- -D warnings
45-
46-
- name: Run tests
47-
run: cargo test --verbose
48-
49-
# --- 2. 构建 Release ---
509
build:
51-
name: Build Release
52-
# 只有在推送标签时才运行此 job
53-
if: startsWith(github.ref, 'refs/tags/')
54-
needs: test # 依赖于 test job 成功
10+
runs-on: ${{ matrix.os }}
5511
strategy:
5612
matrix:
57-
# 定义要构建的目标平台
5813
include:
14+
# Linux x86_64(添加 ubuntu 后缀)
5915
- os: ubuntu-latest
6016
target: x86_64-unknown-linux-gnu
61-
artifact_name: fire-cli
62-
asset_name: fire-cli-linux-x86_64
63-
- os: windows-latest
64-
target: x86_64-pc-windows-msvc
65-
artifact_name: fire-cli.exe
66-
asset_name: fire-cli-windows-x86_64.exe
17+
asset_name: fire-linux-x86_64
18+
original_binary: fire-cli # 原始产物名
19+
renamed_binary: fire-cli-ubuntu # 带平台后缀的产物名
20+
# macOS x86_64(添加 macos 后缀)
6721
- os: macos-latest
6822
target: x86_64-apple-darwin
69-
artifact_name: fire-cli
70-
asset_name: fire-cli-macos-x86_64
71-
- os: macos-latest
72-
target: aarch64-apple-darwin
73-
artifact_name: fire-cli
74-
asset_name: fire-cli-macos-aarch64
23+
asset_name: fire-macos-x86_64
24+
original_binary: fire-cli
25+
renamed_binary: fire-cli-macos
26+
# Windows x86_64(保持原名)
27+
- os: windows-latest
28+
target: x86_64-pc-windows-msvc
29+
asset_name: fire-windows-x86_64.exe
30+
original_binary: fire-cli.exe
31+
renamed_binary: fire-cli.exe # 不修改
7532

76-
runs-on: ${{ matrix.os }}
7733
steps:
7834
- name: Checkout code
7935
uses: actions/checkout@v4
8036

81-
- name: Install Rust
82-
uses: dtolnay/rust-toolchain@stable
37+
- name: Set up Rust
38+
uses: actions-rs/toolchain@v1
8339
with:
84-
# 为每个目标平台添加对应的工具链
85-
targets: ${{ matrix.target }}
40+
toolchain: stable
41+
profile: minimal
42+
override: true
43+
target: ${{ matrix.target }}
8644

87-
- name: Cache dependencies
88-
uses: actions/cache@v3
89-
with:
90-
path: |
91-
~/.cargo/bin/
92-
~/.cargo/registry/index/
93-
~/.cargo/registry/cache/
94-
~/.cargo/git/db/
95-
target/
96-
key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
97-
restore-keys: |
98-
${{ runner.os }}-${{ matrix.target }}-cargo-
99-
100-
- name: Build for target
45+
# 构建产物
46+
- name: Build project
10147
run: cargo build --release --target ${{ matrix.target }}
102-
103-
- name: Strip binary (Unix)
104-
# 在 Linux 和 macOS 上,strip 可以减小二进制文件大小
105-
if: matrix.os != 'windows-latest'
106-
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
107-
48+
env:
49+
RUST_BACKTRACE: full
50+
51+
# 调试:查看构建产物原始名称
52+
- name: Debug build output (original)
53+
run: |
54+
echo "=== 构建目录: target/${{ matrix.target }}/release ==="
55+
ls -la target/${{ matrix.target }}/release/
56+
shell: bash
57+
58+
# 重命名产物(仅 Ubuntu 和 macOS)
59+
- name: Rename binary with platform suffix
60+
if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest'
61+
run: |
62+
# 重命名原始产物为带平台后缀的名称
63+
mv target/${{ matrix.target }}/release/${{ matrix.original_binary }} \
64+
target/${{ matrix.target }}/release/${{ matrix.renamed_binary }}
65+
shell: bash
66+
67+
# 调试:确认重命名后的产物
68+
- name: Debug build output (renamed)
69+
run: |
70+
echo "=== 重命名后构建目录: target/${{ matrix.target }}/release ==="
71+
ls -la target/${{ matrix.target }}/release/
72+
shell: bash
73+
74+
# 上传重命名后的产物
10875
- name: Upload artifact
109-
# 将构建好的二进制文件作为 GitHub Actions 的 artifact 保存
110-
uses: actions/upload-artifact@v3
76+
uses: actions/upload-artifact@v4
11177
with:
11278
name: ${{ matrix.asset_name }}
113-
path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
79+
path: target/${{ matrix.target }}/release/${{ matrix.renamed_binary }} # 上传重命名后的文件
80+
if-no-files-found: error
11481

115-
# --- 3. 发布 Release ---
11682
release:
117-
name: Release
118-
# 只有在推送标签时才运行
119-
if: startsWith(github.ref, 'refs/tags/')
120-
needs: [test, build] # 依赖于 test 和 build job 成功
12183
runs-on: ubuntu-latest
84+
needs: build
12285
steps:
123-
- name: Checkout code
124-
uses: actions/checkout@v4
125-
12686
- name: Download all artifacts
127-
# 从 build job 下载所有构建好的二进制文件
128-
uses: actions/download-artifact@v3
87+
uses: actions/download-artifact@v4
12988
with:
13089
path: artifacts
13190

132-
- name: Display structure of downloaded files
133-
run: ls -R artifacts/
91+
# 验证最终产物路径(带后缀)
92+
- name: Debug artifacts structure
93+
run: |
94+
sudo apt-get install -y tree
95+
echo "=== 最终 artifacts 目录结构 ==="
96+
tree artifacts
97+
shell: bash
13498

135-
- name: Create Release
136-
# 使用 GitHub CLI 创建一个 Release
137-
id: create_release
138-
uses: actions/create-release@v1
139-
env:
140-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99+
- name: Create GitHub Release
100+
uses: softprops/action-gh-release@v2
141101
with:
142-
tag_name: ${{ github.ref_name }} # 使用推送的标签名
143-
release_name: Release ${{ github.ref_name }}
144-
draft: false # 是否是草稿
145-
prerelease: false # 是否是预发布版本
146-
147-
- name: Upload Release Assets
148-
# 将下载的 artifacts 作为附件上传到刚刚创建的 Release
149-
uses: softprops/action-gh-release@v1
102+
tag_name: ${{ github.ref }}
103+
name: Release ${{ github.ref_name }}
104+
body: |
105+
## Changes in this Release
106+
- detail to see [CHANGELOG](https://github.com/xiaoxustudio/fire-cli/blob/master/CHANGELOG.md)
107+
files: |
108+
artifacts/fire-linux-x86_64/fire-cli-ubuntu
109+
artifacts/fire-macos-x86_64/fire-cli-macos
110+
artifacts/fire-windows-x86_64.exe/fire-cli.exe
150111
env:
151112
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
152-
with:
153-
files: artifacts/**/*

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Changelog
2+
3+
## [v1.0.0] - 2025-10-22
4+
- 初始版本发布

github

Whitespace-only changes.

0 commit comments

Comments
 (0)