Skip to content

Commit 2d9f1aa

Browse files
committed
add ci
Signed-off-by: Tin Lai <tin@tinyiu.com>
1 parent 6e69733 commit 2d9f1aa

File tree

6 files changed

+878
-0
lines changed

6 files changed

+878
-0
lines changed

.github/workflows/ci.yml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
11+
cancel-in-progress: true
12+
13+
permissions: {}
14+
15+
env:
16+
# Cargo env vars
17+
CARGO_INCREMENTAL: 0
18+
CARGO_NET_RETRY: 10
19+
CARGO_TERM_COLOR: always
20+
RUSTUP_MAX_RETRIES: 10
21+
22+
jobs:
23+
plan:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
test-code: ${{ !contains(github.event.pull_request.labels.*.name, 'test:skip') && (steps.changed.outputs.any_code_changed == 'true' || github.ref == 'refs/heads/main') }}
27+
save-rust-cache: ${{ github.ref == 'refs/heads/main' || steps.changed.outputs.cache_changed == 'true' }}
28+
# Run benchmarks only if Rust code changed
29+
run-bench: ${{ !contains(github.event.pull_request.labels.*.name, 'test:skip') && (steps.changed.outputs.rust_code_changed == 'true' || github.ref == 'refs/heads/main') }}
30+
steps:
31+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
32+
with:
33+
fetch-depth: 0
34+
persist-credentials: false
35+
36+
- name: "Determine changed files"
37+
id: changed
38+
shell: bash
39+
run: |
40+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha || 'origin/main' }}...HEAD)
41+
42+
ANY_CODE_CHANGED=false
43+
CACHE_CHANGED=false
44+
RUST_CODE_CHANGED=false
45+
46+
while IFS= read -r file; do
47+
# Check if cache-relevant files changed (Cargo files, toolchain, workflows)
48+
if [[ "${file}" == "Cargo.lock" || "${file}" == "Cargo.toml" || "${file}" == "rust-toolchain.toml" || "${file}" == ".cargo/config.toml" || "${file}" =~ ^crates/.*/Cargo\.toml$ || "${file}" =~ ^\.github/workflows/.*\.yml$ ]]; then
49+
echo "Detected cache-relevant change: ${file}"
50+
CACHE_CHANGED=true
51+
fi
52+
53+
# Check if Rust code changed (for benchmarks)
54+
if [[ "${file}" =~ \.rs$ ]] || [[ "${file}" =~ Cargo\.toml$ ]] || [[ "${file}" == "Cargo.lock" ]] || [[ "${file}" == "rust-toolchain.toml" ]] || [[ "${file}" =~ ^\.cargo/ ]]; then
55+
echo "Detected Rust code change: ${file}"
56+
RUST_CODE_CHANGED=true
57+
fi
58+
59+
if [[ "${file}" =~ ^docs/ ]]; then
60+
echo "Skipping ${file} (matches docs/ pattern)"
61+
continue
62+
fi
63+
if [[ "${file}" =~ ^mkdocs.*\.yml$ ]]; then
64+
echo "Skipping ${file} (matches mkdocs*.yml pattern)"
65+
continue
66+
fi
67+
if [[ "${file}" =~ \.md$ ]]; then
68+
echo "Skipping ${file} (matches *.md pattern)"
69+
continue
70+
fi
71+
72+
echo "Detected code change in: ${file}"
73+
ANY_CODE_CHANGED=true
74+
75+
done <<< "${CHANGED_FILES}"
76+
echo "any_code_changed=${ANY_CODE_CHANGED}" >> "${GITHUB_OUTPUT}"
77+
echo "cache_changed=${CACHE_CHANGED}" >> "${GITHUB_OUTPUT}"
78+
echo "rust_code_changed=${RUST_CODE_CHANGED}" >> "${GITHUB_OUTPUT}"
79+
80+
lint:
81+
name: "lint"
82+
timeout-minutes: 10
83+
runs-on: ubuntu-latest
84+
steps:
85+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
86+
with:
87+
persist-credentials: false
88+
- name: "Install Rustfmt"
89+
run: rustup component add rustfmt
90+
- name: "rustfmt"
91+
run: cargo fmt --all --check
92+
- name: Run prek checks
93+
uses: j178/prek-action@564dda4cfa5e96aafdc4a5696c4bf7b46baae5ac # v1.1.0
94+
env:
95+
PREK_SKIP: cargo-fmt,cargo-clippy
96+
97+
check-release:
98+
name: "check release"
99+
needs: plan
100+
timeout-minutes: 10
101+
runs-on: ubuntu-latest
102+
env:
103+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
104+
steps:
105+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
106+
with:
107+
persist-credentials: false
108+
109+
- name: Install dist
110+
shell: bash
111+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.30.4/cargo-dist-installer.sh | sh"
112+
113+
- name: Run dist plan
114+
run: |
115+
dist plan --output-format=json > plan-dist-manifest.json
116+
echo "dist plan completed successfully"
117+
cat plan-dist-manifest.json
118+
119+
cargo-clippy-linux:
120+
name: "cargo clippy | ubuntu"
121+
needs: plan
122+
if: ${{ needs.plan.outputs.test-code == 'true' }}
123+
timeout-minutes: 10
124+
runs-on: ubuntu-latest
125+
steps:
126+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
127+
with:
128+
persist-credentials: false
129+
- uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
130+
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
131+
with:
132+
save-if: ${{ needs.plan.outputs.save-rust-cache == 'true' }}
133+
134+
- name: "Install Rust toolchain"
135+
run: rustup component add clippy
136+
- name: "Clippy"
137+
run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
138+
139+
# cargo-clippy-windows:
140+
# name: "cargo clippy | windows"
141+
# needs: plan
142+
# if: ${{ needs.plan.outputs.test-code == 'true' }}
143+
# timeout-minutes: 15
144+
# runs-on: windows-latest
145+
# steps:
146+
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
147+
# with:
148+
# persist-credentials: false
149+
#
150+
# # - name: Create Dev Drive
151+
# # run: ${{ github.workspace }}/.github/workflows/setup-dev-drive.ps1
152+
#
153+
# # actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
154+
# - name: Copy Git Repo to Dev Drive
155+
# run: |
156+
# Copy-Item -Path "${{ github.workspace }}" -Destination "$Env:PREK_WORKSPACE" -Recurse
157+
#
158+
# - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
159+
# with:
160+
# workspaces: ${{ env.PREK_WORKSPACE }}
161+
# save-if: ${{ needs.plan.outputs.save-rust-cache == 'true' }}
162+
#
163+
# - name: "Install Rust toolchain"
164+
# run: rustup component add clippy
165+
#
166+
# - name: "Clippy"
167+
# working-directory: ${{ env.PREK_WORKSPACE }}
168+
# run: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings
169+
170+
cargo-shear:
171+
name: "cargo shear"
172+
needs: plan
173+
if: ${{ needs.plan.outputs.test-code == 'true' }}
174+
timeout-minutes: 10
175+
runs-on: ubuntu-latest
176+
steps:
177+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
178+
with:
179+
persist-credentials: false
180+
- name: "Install cargo shear"
181+
uses: taiki-e/install-action@7e574ed8bb89811282a11aecb3fe1d043bf5bf0e # v2.67.15
182+
with:
183+
tool: cargo-shear
184+
- run: cargo shear
185+
186+
cargo-test:
187+
needs: plan
188+
if: ${{ needs.plan.outputs.test-code == 'true' }}
189+
timeout-minutes: 5
190+
runs-on: ubuntu-latest
191+
name: "cargo test"
192+
steps:
193+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
194+
with:
195+
persist-credentials: false
196+
- uses: rui314/setup-mold@725a8794d15fc7563f59595bd9556495c0564878 # v1
197+
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
198+
with:
199+
save-if: ${{ needs.plan.outputs.save-rust-cache == 'true' }}
200+
201+
- name: "Install Rust toolchain"
202+
run: rustup component add llvm-tools-preview
203+
204+
- name: "Install cargo nextest"
205+
uses: taiki-e/install-action@7e574ed8bb89811282a11aecb3fe1d043bf5bf0e # v2.67.15
206+
with:
207+
tool: cargo-nextest
208+
209+
- name: "Install cargo-llvm-cov"
210+
uses: taiki-e/install-action@7e574ed8bb89811282a11aecb3fe1d043bf5bf0e # v2.67.15
211+
with:
212+
tool: cargo-llvm-cov
213+
214+
- name: "Cargo testuv"
215+
run: |
216+
echo "::group::Test cargo nextest"
217+
cargo llvm-cov nextest
218+
echo "::endgroup::"
219+
220+
cargo llvm-cov report --lcov --output-path lcov.info
221+
222+
- name: "Upload coverage reports to Codecov"
223+
uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
224+
with:
225+
token: ${{ secrets.CODECOV_TOKEN }}
226+
files: lcov.info

0 commit comments

Comments
 (0)