Skip to content

Commit 4013b30

Browse files
authored
refactor: restructure code and CLI commands (#7)
1 parent c63c298 commit 4013b30

121 files changed

Lines changed: 4339 additions & 4998 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/build/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ runs:
1818
- name: Build release
1919
if: ${{ inputs.release == 'true' }}
2020
shell: bash
21-
run: cargo build --target ${{ inputs.target }} -r
21+
run: cargo build --release --target ${{ inputs.target }} -r

.github/actions/check/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ runs:
66
- name: Audit
77
shell: bash
88
run: |
9-
cargo install cargo-audit
9+
if ! command -v cargo-audit &> /dev/null; then
10+
cargo install cargo-audit
11+
fi
1012
cargo audit
1113
1214
- name: Fmt

.github/actions/make-archive/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ runs:
2020
if: runner.os == 'Windows'
2121
shell: pwsh
2222
run: |
23-
Compress-Archive ${{ inputs.files }} ${{ inputs.out }}
23+
Compress-Archive -Path "${{ inputs.files }}" -DestinationPath "${{ inputs.out }}"

.github/actions/test/action.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,4 @@ runs:
55
steps:
66
- name: Test dev
77
shell: bash
8-
run: cargo test --verbose
9-
10-
- name: Test release
11-
shell: bash
12-
run: cargo test --verbose --release
8+
run: cargo test

.github/workflows/build-dev.yml

Lines changed: 0 additions & 110 deletions
This file was deleted.

.github/workflows/build-release.yml

Lines changed: 0 additions & 102 deletions
This file was deleted.

.github/workflows/pr-check.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build / Development
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
jobs:
11+
commit-check:
12+
name: Commit Check
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0 # 必须,才能拿到完整 commit history
19+
20+
- name: Lint commits
21+
uses: wagoid/commitlint-github-action@v6
22+
23+
pr-check:
24+
needs: commit-check
25+
name: Pull Request Check
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1 # 浅克隆以加快速度
32+
persist-credentials: false
33+
34+
- name: Setup Rust toolchain
35+
uses: dsherret/rust-toolchain-file@v1
36+
37+
- name: Fmt
38+
run: cargo fmt --check
39+
40+
- name: Clippy
41+
run: cargo clippy -- -D warnings
42+
43+
- name: Test
44+
run: cargo test
45+
46+
- name: Build Dev
47+
run: cargo build

.github/workflows/release.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build / Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
12+
jobs:
13+
14+
prepare:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
version: ${{ steps.version.outputs.version }}
18+
should_release: ${{ steps.check.outputs.should_release }}
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Read version from Cargo.toml
24+
id: version
25+
run: |
26+
VERSION=$(grep '^version' Cargo.toml | sed 's/.*= "\(.*\)"/\1/')
27+
echo "version=$VERSION" >> $GITHUB_OUTPUT
28+
29+
- name: Check if release exists
30+
id: check
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
run: |
34+
TAG="v${{ steps.version.outputs.version }}"
35+
if gh release view "$TAG" >/dev/null 2>&1; then
36+
echo "should_release=false" >> $GITHUB_OUTPUT
37+
else
38+
echo "should_release=true" >> $GITHUB_OUTPUT
39+
fi
40+
41+
- name: Create and push tag
42+
if: steps.check.outputs.should_release == 'true'
43+
run: |
44+
TAG="v${{ steps.version.outputs.version }}"
45+
git tag "$TAG"
46+
git push origin "$TAG"
47+
48+
build-release:
49+
needs: prepare
50+
if: needs.prepare.outputs.should_release == 'true'
51+
name: ${{ matrix.targets.alias }}
52+
runs-on: ${{ matrix.targets.os }}
53+
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
targets:
58+
- { os: macos-latest, target: aarch64-apple-darwin, alias: aarch64-apple-darwin }
59+
- { os: macos-latest, target: x86_64-apple-darwin, alias: x86_64-apple-darwin }
60+
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu, alias: x86_64-unknown-linux-gnu }
61+
- { os: ubuntu-latest, target: x86_64-unknown-linux-musl,alias: x86_64-unknown-linux-musl}
62+
- { os: windows-latest, target: x86_64-pc-windows-msvc, alias: x86_64-pc-windows-msvc }
63+
64+
steps:
65+
- uses: actions/checkout@v4
66+
with:
67+
fetch-depth: 0
68+
69+
- uses: dsherret/rust-toolchain-file@v1
70+
71+
- name: Setup musl-tools
72+
if: matrix.targets.target == 'x86_64-unknown-linux-musl'
73+
shell: bash
74+
run: sudo apt -y install musl-tools
75+
76+
- name: Add target
77+
uses: ./.github/actions/add-target
78+
with:
79+
target: ${{ matrix.targets.target }}
80+
81+
- name: Setup Rust cache
82+
uses: Swatinem/rust-cache@v2
83+
with:
84+
prefix-key: ${{ matrix.targets.alias }}
85+
86+
- name: Run build
87+
uses: ./.github/actions/build
88+
with:
89+
target: ${{ matrix.targets.target }}
90+
release: true
91+
92+
- name: Archive binary
93+
uses: ./.github/actions/make-archive
94+
with:
95+
files: ./target/${{ matrix.targets.target }}/release/cnb${{ matrix.targets.target == 'x86_64-pc-windows-msvc' && '.exe' || '' }}
96+
out: cnb-${{ needs.prepare.outputs.version }}-${{ matrix.targets.target }}.zip
97+
98+
- name: Create GitHub release
99+
uses: softprops/action-gh-release@v2
100+
with:
101+
tag_name: v${{ needs.prepare.outputs.version }}
102+
files: cnb-${{ needs.prepare.outputs.version }}-${{ matrix.targets.target }}.zip

0 commit comments

Comments
 (0)