Skip to content

Commit c09d486

Browse files
committed
ci: refactor workflows for modular CI/CD pipeline
1 parent b93a5b0 commit c09d486

File tree

5 files changed

+284
-59
lines changed

5 files changed

+284
-59
lines changed

.github/workflows/check.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
- aarch64-unknown-none-softfloat
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Install Rust toolchain
21+
uses: dtolnay/rust-toolchain@nightly
22+
with:
23+
components: rust-src, clippy, rustfmt
24+
targets: ${{ matrix.target }}
25+
26+
- name: Check rust version
27+
run: rustc --version --verbose
28+
29+
- name: Check code format
30+
run: cargo fmt --all -- --check
31+
32+
- name: Build
33+
run: cargo build --target ${{ matrix.target }} --all-features
34+
35+
- name: Run clippy
36+
run: cargo clippy --target ${{ matrix.target }} --all-features -- -D warnings
37+
38+
- name: Build documentation
39+
env:
40+
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
41+
run: cargo doc --no-deps --target ${{ matrix.target }} --all-features

.github/workflows/ci.yml

Lines changed: 0 additions & 59 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=axhvc/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/axhvc)
87+
- [crates.io](https://crates.io/crates/axhvc)
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

0 commit comments

Comments
 (0)