Skip to content

Commit 918a2fc

Browse files
committed
feat: add ci workflow include check, deploy, test and test.
1 parent 5e9dbc5 commit 918a2fc

4 files changed

Lines changed: 238 additions & 14 deletions

File tree

.github/workflows/check.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
targets: x86_64-unknown-linux-gnu
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Install Rust toolchain
20+
uses: dtolnay/rust-toolchain@master
21+
with:
22+
toolchain: nightly-2025-08-15
23+
components: rust-src, clippy, rustfmt
24+
targets: ${{ matrix.targets }}
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.targets }}
34+
35+
- name: Run clippy
36+
run: cargo clippy --target ${{ matrix.targets }} -- -D warnings
37+
38+
- name: Build documentation
39+
run: cargo doc --no-deps --target ${{ matrix.targets }}

.github/workflows/deploy.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
jobs:
22+
quality-check:
23+
uses: ./.github/workflows/check.yml
24+
25+
test:
26+
uses: ./.github/workflows/test.yml
27+
28+
build-doc:
29+
name: Build documentation
30+
runs-on: ubuntu-latest
31+
needs: quality-check
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
36+
- name: Install Rust toolchain
37+
uses: dtolnay/rust-toolchain@master
38+
with:
39+
toolchain: nightly-2025-08-15
40+
components: rust-src
41+
42+
- name: Build docs
43+
run: cargo doc --no-deps --target x86_64-unknown-linux-gnu
44+
45+
- name: Create index redirect
46+
run: |
47+
printf '<meta http-equiv="refresh" content="0;url=any_uart/index.html">' > target/x86_64-unknown-linux-gnu/doc/index.html
48+
49+
- name: Upload artifact
50+
uses: actions/upload-pages-artifact@v3
51+
with:
52+
path: target/x86_64-unknown-linux-gnu/doc
53+
54+
deploy-doc:
55+
name: Deploy to GitHub Pages
56+
environment:
57+
name: github-pages
58+
url: ${{ steps.deployment.outputs.page_url }}
59+
runs-on: ubuntu-latest
60+
needs: build-doc
61+
steps:
62+
- name: Deploy to GitHub Pages
63+
id: deployment
64+
uses: actions/deploy-pages@v4

.github/workflows/release.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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: Create GitHub Release
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
draft: false
67+
prerelease: ${{ contains(github.ref_name, '-pre.') }}
68+
body: |
69+
## ${{ github.ref_name }}
70+
71+
- [Documentation](https://docs.rs/any-uart)
72+
- [crates.io](https://crates.io/crates/any-uart)
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
76+
publish-crates:
77+
name: Publish to crates.io
78+
runs-on: ubuntu-latest
79+
needs: check
80+
81+
steps:
82+
- name: Checkout code
83+
uses: actions/checkout@v4
84+
with:
85+
fetch-depth: 0
86+
87+
- name: Validate tag and branch (HEAD-based)
88+
shell: bash
89+
run: |
90+
set -e
91+
92+
TAG="${{ github.ref_name }}"
93+
TAG_COMMIT=$(git rev-list -n 1 "$TAG")
94+
95+
git fetch origin main dev
96+
97+
MAIN_HEAD=$(git rev-parse origin/main)
98+
DEV_HEAD=$(git rev-parse origin/dev)
99+
100+
echo "Tag: $TAG"
101+
echo "Tag commit: $TAG_COMMIT"
102+
echo "main HEAD: $MAIN_HEAD"
103+
echo "dev HEAD: $DEV_HEAD"
104+
105+
if [[ "$TAG" == *-pre.* ]]; then
106+
if [ "$TAG_COMMIT" != "$DEV_HEAD" ]; then
107+
echo "❌ prerelease tag must be created from dev HEAD"
108+
exit 1
109+
fi
110+
echo "✅ prerelease tag validated on dev"
111+
else
112+
if [ "$TAG_COMMIT" != "$MAIN_HEAD" ]; then
113+
echo "❌ stable release tag must be created from main HEAD"
114+
exit 1
115+
fi
116+
echo "✅ stable release tag validated on main"
117+
fi
118+
119+
- name: Install Rust toolchain
120+
uses: dtolnay/rust-toolchain@master
121+
with:
122+
toolchain: nightly-2025-08-15
123+
124+
- name: Publish to crates.io
125+
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
name: Check, Build and Test
1+
name: Test
22

33
on:
4+
workflow_call:
45
push:
5-
branches:
6-
- master
6+
branches: dev
77
pull_request:
8-
branches:
9-
- master
10-
11-
env:
12-
CARGO_TERM_COLOR: always
8+
branches: dev
139

1410
jobs:
15-
ci:
11+
test:
12+
name: Test
1613
runs-on: ubuntu-latest
1714
steps:
18-
- uses: actions/checkout@v4
15+
- name: Checkout code
16+
uses: actions/checkout@v4
1917

2018
- name: Install qemu-system
21-
run: sudo apt update && sudo apt install qemu-system -y
19+
run: sudo apt update && sudo apt install qemu-system -y
2220
- name: Install libudev-dev
2321
run: sudo apt update && sudo apt install libudev-dev -y
2422
- name: Install toolchain
@@ -28,7 +26,7 @@ jobs:
2826

2927
- uses: Swatinem/rust-cache@v2
3028
with:
31-
workspaces: "."
29+
workspaces: "."
3230

3331
- name: Install cargo-binutils
3432
run: cargo install cargo-binutils
@@ -46,5 +44,3 @@ jobs:
4644

4745
- name: Test
4846
run: cargo test -p hello --test test -- --show-output
49-
50-

0 commit comments

Comments
 (0)