Skip to content

Commit c4ef8bc

Browse files
authored
[feat] refactor according to rules and prepare to release (#45)
* [feat] refactor according to rules and prepare to release * [feat] modify github workflows
1 parent 35da6c7 commit c4ef8bc

File tree

9 files changed

+689
-97
lines changed

9 files changed

+689
-97
lines changed

.github/workflows/check.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
components: rust-src, clippy, rustfmt
27+
targets: ${{ matrix.target }}
28+
29+
- name: Check rust version
30+
run: rustc --version --verbose
31+
32+
- name: Check code format
33+
run: cargo fmt --all -- --check
34+
35+
- name: Build
36+
run: cargo build --target ${{ matrix.target }} --all-features
37+
38+
- name: Run clippy
39+
run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings -A clippy::new_without_default
40+
41+
- name: Build documentation
42+
env:
43+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
44+
run: cargo doc --no-deps --target ${{ matrix.target }} --all-features

.github/workflows/ci.yml

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

.github/workflows/deploy.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
43+
- name: Build docs
44+
env:
45+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
46+
run: |
47+
cargo doc --no-deps --all-features
48+
printf '<meta http-equiv="refresh" content="0;url=axdevice_base/index.html">' > target/doc/index.html
49+
50+
- name: Upload artifact
51+
uses: actions/upload-pages-artifact@v3
52+
with:
53+
path: target/doc
54+
55+
deploy-doc:
56+
name: Deploy to GitHub Pages
57+
environment:
58+
name: github-pages
59+
url: ${{ steps.deployment.outputs.page_url }}
60+
runs-on: ubuntu-latest
61+
needs: build-doc
62+
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
63+
steps:
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

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

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
17+
- name: Run tests
18+
run: cargo test --all-features -- --nocapture
19+
20+
- name: Run doc tests
21+
run: cargo test --doc

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
## [0.1.0] - 2026-01-24
11+
12+
### Added
13+
14+
- Initial release of `axdevice_base` crate.
15+
- `BaseDeviceOps` trait: Core interface for all emulated devices.
16+
- `EmulatedDeviceConfig`: Configuration structure for device initialization.
17+
- `EmuDeviceType`: Re-exported device type enumeration from `axvmconfig`.
18+
- `map_device_of_type`: Helper function for runtime device type checking and casting.
19+
- Trait aliases for common device types:
20+
- `BaseMmioDeviceOps`: For MMIO (Memory-Mapped I/O) devices.
21+
- `BaseSysRegDeviceOps`: For system register devices (ARM).
22+
- `BasePortDeviceOps`: For port I/O devices (x86).
23+
- Support for multiple architectures: x86_64, AArch64, RISC-V64.
24+
- `no_std` compatible design.
25+
26+
[Unreleased]: https://github.com/arceos-hypervisor/axdevice_base/compare/v0.1.0...HEAD
27+
[0.1.0]: https://github.com/arceos-hypervisor/axdevice_base/releases/tag/v0.1.0

0 commit comments

Comments
 (0)