Skip to content

Commit 22fdaea

Browse files
hky1999aarkegzCopilot
authored
[feat] refactor according to rules and prepare to release (#8)
* [feat] refactor according to rules and prepare to release * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * [feat] modify github workflows --------- Co-authored-by: Su Mingxian <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent aae42f5 commit 22fdaea

File tree

15 files changed

+1136
-115
lines changed

15 files changed

+1136
-115
lines changed

.github/workflows/check.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Quality Checks
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
check:
8+
name: Quality Checks
9+
runs-on: ubuntu-latest
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
target:
14+
- x86_64-unknown-linux-gnu
15+
- x86_64-unknown-none
16+
- riscv64gc-unknown-none-elf
17+
- aarch64-unknown-none-softfloat
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Install Rust toolchain
24+
uses: dtolnay/rust-toolchain@nightly
25+
with:
26+
toolchain: nightly-2025-05-20
27+
components: rust-src, clippy, rustfmt
28+
targets: ${{ matrix.target }}
29+
30+
- name: Check rust version
31+
run: rustc --version --verbose
32+
33+
- name: Check code format
34+
run: cargo fmt --all -- --check
35+
36+
- name: Build
37+
run: cargo build --target ${{ matrix.target }} --all-features
38+
39+
- name: Run clippy
40+
run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings -A clippy::new_without_default
41+
42+
- name: Build documentation
43+
env:
44+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
45+
run: cargo doc --no-deps --target ${{ matrix.target }} --all-features

.github/workflows/ci.yml

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

.github/workflows/deploy.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- 'v*'
9+
- 'v*-pre.*'
10+
pull_request:
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: 'pages'
19+
cancel-in-progress: false
20+
21+
env:
22+
CARGO_TERM_COLOR: always
23+
RUST_BACKTRACE: 1
24+
25+
jobs:
26+
quality-check:
27+
uses: ./.github/workflows/check.yml
28+
29+
test:
30+
uses: ./.github/workflows/test.yml
31+
32+
build-doc:
33+
name: Build documentation
34+
runs-on: ubuntu-latest
35+
needs: quality-check
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Install Rust toolchain
41+
uses: dtolnay/rust-toolchain@nightly
42+
with:
43+
toolchain: nightly-2025-05-20
44+
45+
- name: Build docs
46+
env:
47+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
48+
run: |
49+
cargo doc --no-deps --all-features
50+
printf '<meta http-equiv="refresh" content="0;url=axvisor_api/index.html">' > target/doc/index.html
51+
52+
- name: Upload artifact
53+
uses: actions/upload-pages-artifact@v3
54+
with:
55+
path: target/doc
56+
57+
deploy-doc:
58+
name: Deploy to GitHub Pages
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
runs-on: ubuntu-latest
63+
needs: build-doc
64+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
65+
steps:
66+
- name: Deploy to GitHub Pages
67+
id: deployment
68+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
- 'v*.*.*-pre.*'
8+
9+
permissions:
10+
contents: write
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
RUST_BACKTRACE: 1
15+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
16+
17+
jobs:
18+
check:
19+
uses: ./.github/workflows/check.yml
20+
21+
test:
22+
uses: ./.github/workflows/test.yml
23+
needs: check
24+
25+
create-release:
26+
name: Create GitHub Release
27+
runs-on: ubuntu-latest
28+
needs: check
29+
30+
steps:
31+
- name: Checkout code
32+
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Validate tag and branch (HEAD-based)
37+
shell: bash
38+
run: |
39+
set -e
40+
41+
TAG="${{ github.ref_name }}"
42+
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
43+
44+
git fetch origin main dev
45+
46+
MAIN_HEAD=$(git rev-parse origin/main)
47+
DEV_HEAD=$(git rev-parse origin/dev)
48+
49+
echo "Tag: $TAG"
50+
echo "Tag commit: $TAG_COMMIT"
51+
echo "main HEAD: $MAIN_HEAD"
52+
echo "dev HEAD: $DEV_HEAD"
53+
54+
if [[ "$TAG" == *-pre.* ]]; then
55+
if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
56+
echo "❌ prerelease tag must be created from dev HEAD"
57+
exit 1
58+
fi
59+
echo "✅ prerelease tag validated on dev"
60+
else
61+
if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
62+
echo "❌ stable release tag must be created from main HEAD"
63+
exit 1
64+
fi
65+
echo "✅ stable release tag validated on main"
66+
fi
67+
68+
- name: Verify version consistency
69+
run: |
70+
# Extract version from git tag (remove 'v' prefix)
71+
TAG_VERSION="${{ github.ref_name }}"
72+
TAG_VERSION="${TAG_VERSION#v}"
73+
# Extract version from Cargo.toml using cargo metadata
74+
CARGO_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "axvisor_api") | .version')
75+
echo "Git tag version: $TAG_VERSION"
76+
echo "Cargo.toml version: $CARGO_VERSION"
77+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
78+
echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
79+
exit 1
80+
fi
81+
echo "Version check passed!"
82+
83+
- name: Create GitHub Release
84+
uses: softprops/action-gh-release@v2
85+
with:
86+
draft: false
87+
prerelease: ${{ contains(github.ref_name, '-pre.') }}
88+
body: |
89+
## ${{ github.ref_name }}
90+
91+
- [Documentation](https://docs.rs/axvisor_api)
92+
- [crates.io](https://crates.io/crates/axvisor_api)
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
96+
publish-crates:
97+
name: Publish to crates.io
98+
runs-on: ubuntu-latest
99+
needs: check
100+
101+
steps:
102+
- name: Checkout code
103+
uses: actions/checkout@v4
104+
with:
105+
fetch-depth: 0
106+
107+
- name: Validate tag and branch (HEAD-based)
108+
shell: bash
109+
run: |
110+
set -e
111+
112+
TAG="${{ github.ref_name }}"
113+
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
114+
115+
git fetch origin main dev
116+
117+
MAIN_HEAD=$(git rev-parse origin/main)
118+
DEV_HEAD=$(git rev-parse origin/dev)
119+
120+
echo "Tag: $TAG"
121+
echo "Tag commit: $TAG_COMMIT"
122+
echo "main HEAD: $MAIN_HEAD"
123+
echo "dev HEAD: $DEV_HEAD"
124+
125+
if [[ "$TAG" == *-pre.* ]]; then
126+
if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
127+
echo "❌ prerelease tag must be created from dev HEAD"
128+
exit 1
129+
fi
130+
echo "✅ prerelease tag validated on dev"
131+
else
132+
if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
133+
echo "❌ stable release tag must be created from main HEAD"
134+
exit 1
135+
fi
136+
echo "✅ stable release tag validated on main"
137+
fi
138+
139+
- name: Verify version consistency
140+
run: |
141+
# Extract version from git tag (remove 'v' prefix)
142+
TAG_VERSION="${{ github.ref_name }}"
143+
TAG_VERSION="${TAG_VERSION#v}"
144+
# Extract version from Cargo.toml using cargo metadata
145+
CARGO_VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "axvisor_api") | .version')
146+
echo "Git tag version: $TAG_VERSION"
147+
echo "Cargo.toml version: $CARGO_VERSION"
148+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
149+
echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
150+
exit 1
151+
fi
152+
echo "Version check passed!"
153+
154+
- name: Install Rust toolchain
155+
uses: dtolnay/rust-toolchain@nightly
156+
with:
157+
toolchain: nightly-2025-05-20
158+
159+
# Workspace crates must be published in dependency order
160+
- name: Dry run publish (axvisor_api_proc)
161+
run: cargo publish --dry-run -p axvisor_api_proc
162+
163+
- name: Dry run publish (axvisor_api)
164+
run: cargo publish --dry-run -p axvisor_api
165+
166+
- name: Publish axvisor_api_proc to crates.io
167+
run: cargo publish -p axvisor_api_proc --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
168+
169+
# Wait for crates.io to index the proc-macro crate
170+
- name: Wait for crates.io indexing
171+
run: sleep 30
172+
173+
- name: Publish axvisor_api to crates.io
174+
run: cargo publish -p axvisor_api --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
test:
8+
name: Test
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Install Rust toolchain
15+
uses: dtolnay/rust-toolchain@nightly
16+
with:
17+
toolchain: nightly-2025-05-20
18+
19+
- name: Run tests
20+
run: cargo test --all-features -- --nocapture
21+
22+
- name: Run doc tests
23+
run: cargo test --doc --all-features

0 commit comments

Comments
 (0)