Skip to content

Commit e3a1418

Browse files
committed
ci: refactor workflows for modular CI/CD pipeline
1 parent 6a6a3f6 commit e3a1418

File tree

5 files changed

+247
-120
lines changed

5 files changed

+247
-120
lines changed

.github/config.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"targets": [
3+
"x86_64-unknown-none"
4+
],
5+
"rust_components": [
6+
"rust-src",
7+
"clippy",
8+
"rustfmt"
9+
]
10+
}

.github/workflows/check.yml

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,42 @@
11
name: Quality Checks
22

33
on:
4+
push:
5+
branches:
6+
- '**'
7+
tags-ignore:
8+
- '**'
9+
pull_request:
410
workflow_call:
511

612
jobs:
13+
load-config:
14+
name: Load CI Configuration
15+
runs-on: ubuntu-latest
16+
outputs:
17+
targets: ${{ steps.config.outputs.targets }}
18+
rust_components: ${{ steps.config.outputs.rust_components }}
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Load configuration
24+
id: config
25+
run: |
26+
TARGETS=$(jq -c '.targets' .github/config.json)
27+
COMPONENTS=$(jq -r '.rust_components | join(", ")' .github/config.json)
28+
29+
echo "targets=$TARGETS" >> $GITHUB_OUTPUT
30+
echo "rust_components=$COMPONENTS" >> $GITHUB_OUTPUT
31+
732
check:
8-
name: Quality Checks
33+
name: Check
934
runs-on: ubuntu-latest
35+
needs: load-config
1036
strategy:
1137
fail-fast: false
1238
matrix:
13-
target:
14-
- x86_64-unknown-linux-gnu
15-
- x86_64-unknown-none
39+
target: ${{ fromJson(needs.load-config.outputs.targets) }}
1640

1741
steps:
1842
- name: Checkout code
@@ -21,7 +45,7 @@ jobs:
2145
- name: Install Rust toolchain
2246
uses: dtolnay/rust-toolchain@nightly
2347
with:
24-
components: rust-src, clippy, rustfmt
48+
components: ${{ needs.load-config.outputs.rust_components }}
2549
targets: ${{ matrix.target }}
2650

2751
- name: Check rust version

.github/workflows/deploy.yml

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ name: Deploy
22

33
on:
44
push:
5-
branches:
6-
- '**'
7-
tags-ignore:
8-
- 'v*'
9-
- 'v*-pre.*'
10-
pull_request:
5+
tags:
6+
- 'v[0-9]+.[0-9]+.[0-9]+'
117

128
permissions:
139
contents: read
@@ -23,16 +19,63 @@ env:
2319
RUST_BACKTRACE: 1
2420

2521
jobs:
26-
quality-check:
22+
verify-tag:
23+
name: Verify Tag
24+
runs-on: ubuntu-latest
25+
outputs:
26+
should_deploy: ${{ steps.check.outputs.should_deploy }}
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 0
32+
33+
- name: Check if tag is on main or master branch
34+
id: check
35+
run: |
36+
git fetch origin main master || true
37+
BRANCHES=$(git branch -r --contains ${{ github.ref }})
38+
39+
if echo "$BRANCHES" | grep -qE 'origin/(main|master)'; then
40+
echo "✓ Tag is on main or master branch"
41+
echo "should_deploy=true" >> $GITHUB_OUTPUT
42+
else
43+
echo "✗ Tag is not on main or master branch, skipping deployment"
44+
echo "Tag is on: $BRANCHES"
45+
echo "should_deploy=false" >> $GITHUB_OUTPUT
46+
fi
47+
48+
- name: Verify version consistency
49+
if: steps.check.outputs.should_deploy == 'true'
50+
run: |
51+
# Extract version from git tag (remove 'v' prefix)
52+
TAG_VERSION="${{ github.ref_name }}"
53+
TAG_VERSION="${TAG_VERSION#v}"
54+
# Extract version from Cargo.toml
55+
CARGO_VERSION=$(grep -m1 '^version' Cargo.toml | sed 's/.*"\(.*\)"/\1/')
56+
echo "Git tag version: $TAG_VERSION"
57+
echo "Cargo.toml version: $CARGO_VERSION"
58+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
59+
echo "ERROR: Version mismatch! Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
60+
exit 1
61+
fi
62+
echo "✓ Version check passed!"
63+
64+
check:
2765
uses: ./.github/workflows/check.yml
66+
needs: verify-tag
67+
if: needs.verify-tag.outputs.should_deploy == 'true'
2868

2969
test:
3070
uses: ./.github/workflows/test.yml
71+
needs: verify-tag
72+
if: needs.verify-tag.outputs.should_deploy == 'true'
3173

32-
build-doc:
74+
build:
3375
name: Build documentation
3476
runs-on: ubuntu-latest
35-
needs: quality-check
77+
needs: [verify-tag, check, test]
78+
if: needs.verify-tag.outputs.should_deploy == 'true'
3679
steps:
3780
- name: Checkout code
3881
uses: actions/checkout@v4
@@ -44,22 +87,39 @@ jobs:
4487
env:
4588
RUSTDOCFLAGS: -D rustdoc::broken_intra_doc_links -D missing-docs
4689
run: |
90+
# Build documentation
4791
cargo doc --no-deps --all-features
48-
printf '<meta http-equiv="refresh" content="0;url=axhvc/index.html">' > target/doc/index.html
92+
93+
# Auto-detect documentation directory
94+
# Check if doc exists in target/doc or target/*/doc
95+
if [ -d "target/doc" ]; then
96+
DOC_DIR="target/doc"
97+
else
98+
# Find doc directory under target/*/doc pattern
99+
DOC_DIR=$(find target -type d -name doc -path "target/*/doc" | head -n 1)
100+
if [ -z "$DOC_DIR" ]; then
101+
echo "Error: Could not find documentation directory"
102+
exit 1
103+
fi
104+
fi
105+
106+
echo "Documentation found in: $DOC_DIR"
107+
printf '<meta http-equiv="refresh" content="0;url=%s/index.html">' $(cargo tree | head -1 | cut -d' ' -f1) > "${DOC_DIR}/index.html"
108+
echo "DOC_DIR=${DOC_DIR}" >> $GITHUB_ENV
49109
50110
- name: Upload artifact
51111
uses: actions/upload-pages-artifact@v3
52112
with:
53-
path: target/doc
113+
path: ${{ env.DOC_DIR }}
54114

55-
deploy-doc:
115+
deploy:
56116
name: Deploy to GitHub Pages
57117
environment:
58118
name: github-pages
59119
url: ${{ steps.deployment.outputs.page_url }}
60120
runs-on: ubuntu-latest
61-
needs: build-doc
62-
if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
121+
needs: [verify-tag, build]
122+
if: needs.verify-tag.outputs.should_deploy == 'true'
63123
steps:
64124
- name: Deploy to GitHub Pages
65125
id: deployment

0 commit comments

Comments
 (0)