Skip to content

Commit 79a46a7

Browse files
authored
ci: optimize GitHub workflows with caching, concurrency, timeouts, and permissions (#41)
Closes #40
1 parent 8271dbd commit 79a46a7

7 files changed

Lines changed: 134 additions & 87 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,41 @@ name: Build and test code
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: [main]
6+
paths-ignore:
7+
- "**.md"
8+
- "LICENSE*"
9+
- ".github/workflows/docs.yml"
10+
- "katex-header.html"
611
pull_request:
7-
branches: [ "main" ]
12+
branches: [main]
13+
paths-ignore:
14+
- "**.md"
15+
- "LICENSE*"
16+
- ".github/workflows/docs.yml"
17+
- "katex-header.html"
18+
19+
permissions:
20+
contents: read
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
24+
cancel-in-progress: true
825

926
env:
1027
CARGO_TERM_COLOR: always
1128
CARGO_INCREMENTAL: 0
1229

1330
jobs:
1431
build:
32+
if: github.event.pull_request.draft == false
1533
runs-on: ubuntu-latest
34+
timeout-minutes: 30
1635
steps:
17-
- uses: actions/checkout@v4
18-
- name: Build
19-
run: cargo test --workspace --verbose --no-run
20-
- name: Run tests
21-
run: cargo test --workspace --verbose
36+
- uses: actions/checkout@v4
37+
- uses: dtolnay/rust-toolchain@stable
38+
- uses: Swatinem/rust-cache@v2
39+
- name: Build
40+
run: cargo test --workspace --verbose --no-run
41+
- name: Run tests
42+
run: cargo test --workspace --verbose

.github/workflows/coverage.yml

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

.github/workflows/dependency-audit.yml

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ name: Dependency security audit
33
on:
44
push:
55
paths:
6-
- '**/Cargo.toml'
7-
- '**/Cargo.lock'
6+
- "**/Cargo.toml"
7+
- "**/Cargo.lock"
8+
- "deny.toml"
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
15+
cancel-in-progress: true
816

917
env:
1018
CARGO_TERM_COLOR: always
@@ -14,28 +22,14 @@ jobs:
1422
security_audit:
1523
timeout-minutes: 10
1624
runs-on: ubuntu-latest
17-
permissions:
18-
contents: read
19-
checks: write
2025
steps:
2126
- name: Check out
2227
uses: actions/checkout@v4
2328

24-
- name: Cache audit-check build
25-
id: cache-audit-check
26-
uses: actions/cache@v4
27-
continue-on-error: false
28-
with:
29-
path: |
30-
~/.cargo/bin/
31-
~/.cargo/registry/index/
32-
~/.cargo/registry/cache/
33-
~/.cargo/git/db/
34-
target/
35-
key: ${{ runner.os }}-cargo-deny-${{ hashFiles('**/Cargo.lock') }}
36-
restore-keys: ${{ runner.os }}-cargo-deny
37-
38-
- name: Run audit-check action
39-
run: |
40-
which cargo-deny || cargo install cargo-deny
41-
cargo deny check
29+
- uses: dtolnay/rust-toolchain@stable
30+
31+
- name: Install cargo-deny
32+
uses: taiki-e/install-action@cargo-deny
33+
34+
- name: Run cargo deny
35+
run: cargo deny check

.github/workflows/docs.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,34 @@ name: Docs
55
on:
66
workflow_dispatch:
77

8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
cancel-in-progress: true
14+
815
jobs:
916
# TODO(template) remove docs publishing, when the crate is published to crates.io
1017
docs:
11-
permissions:
12-
contents: write
1318
name: Documentation
1419
runs-on: ubuntu-latest
20+
timeout-minutes: 15
1521
steps:
1622
- name: Checkout source code
1723
uses: actions/checkout@v4
1824
with:
1925
fetch-depth: 1
2026
persist-credentials: false
2127

28+
- uses: dtolnay/rust-toolchain@stable
29+
30+
- uses: Swatinem/rust-cache@v2
31+
2232
- name: Setup pages
2333
id: pages
2434
uses: actions/configure-pages@v5
2535

26-
- name: Clean docs folder
27-
run: cargo clean --doc
28-
2936
# Documentation with Latex support
3037
# TODO(template) if Latex is not needed
3138
# just remove katex-header.html at the root and RUSTDOCFLAGS here
@@ -49,8 +56,9 @@ jobs:
4956
name: github-pages
5057
url: ${{ steps.deployment.outputs.page_url }}
5158
runs-on: ubuntu-latest
59+
timeout-minutes: 5
5260
needs: docs
5361
steps:
5462
- name: Deploy to GitHub Pages
5563
id: deployment
56-
uses: actions/deploy-pages@v4
64+
uses: actions/deploy-pages@v4

.github/workflows/linter.yml

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,63 @@
11
name: Linter check
22

3-
on: push
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- "**.md"
8+
- "LICENSE*"
9+
- ".github/workflows/docs.yml"
10+
- "katex-header.html"
11+
pull_request:
12+
branches: [main]
13+
paths-ignore:
14+
- "**.md"
15+
- "LICENSE*"
16+
- ".github/workflows/docs.yml"
17+
- "katex-header.html"
18+
19+
permissions:
20+
contents: read
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
24+
cancel-in-progress: true
425

526
env:
627
CARGO_TERM_COLOR: always
728
CARGO_INCREMENTAL: 0
8-
# Make sure CI fails on all warnings, including Clippy lints
9-
RUSTFLAGS: "-Dwarnings"
1029

1130
jobs:
12-
linter_check:
31+
fmt:
1332
runs-on: ubuntu-latest
33+
timeout-minutes: 5
1434
steps:
1535
- uses: actions/checkout@v4
36+
- uses: dtolnay/rust-toolchain@stable
37+
with:
38+
components: rustfmt
1639
- name: Run Fmt
1740
run: cargo fmt --all -- --check
1841

42+
clippy:
43+
runs-on: ubuntu-latest
44+
timeout-minutes: 15
45+
env:
46+
# Make sure CI fails on all warnings, including Clippy lints
47+
RUSTFLAGS: "-Dwarnings"
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: dtolnay/rust-toolchain@stable
51+
with:
52+
components: clippy
53+
- uses: Swatinem/rust-cache@v2
1954
- name: Run Clippy
2055
run: cargo clippy --all-targets --all-features
2156

57+
typos:
58+
runs-on: ubuntu-latest
59+
timeout-minutes: 5
60+
steps:
61+
- uses: actions/checkout@v4
2262
- name: Check typos
2363
uses: crate-ci/typos@master

.github/workflows/ub-detection.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
name: UB (undefined behavior) detection
22

3-
on: push
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- "**.md"
8+
- "LICENSE*"
9+
- ".github/workflows/docs.yml"
10+
- "katex-header.html"
11+
pull_request:
12+
branches: [main]
13+
paths-ignore:
14+
- "**.md"
15+
- "LICENSE*"
16+
- ".github/workflows/docs.yml"
17+
- "katex-header.html"
18+
19+
permissions:
20+
contents: read
21+
22+
concurrency:
23+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
24+
cancel-in-progress: true
425

526
env:
627
CARGO_TERM_COLOR: always
@@ -16,9 +37,11 @@ jobs:
1637
runs-on: ubuntu-latest
1738
steps:
1839
- uses: actions/checkout@v4
19-
- run: |
20-
rustup +nightly component add miri
21-
cargo +nightly miri setup
22-
PROPTEST_DISABLE_FAILURE_PERSISTENCE=true \
23-
MIRIFLAGS="-Zmiri-env-forward=PROPTEST_DISABLE_FAILURE_PERSISTENCE -Zmiri-strict-provenance" \
24-
cargo +nightly miri test --lib
40+
- uses: dtolnay/rust-toolchain@nightly
41+
with:
42+
components: miri
43+
- uses: Swatinem/rust-cache@v2
44+
with:
45+
cache-on-failure: true
46+
- name: Run Miri
47+
run: MIRIFLAGS="-Zmiri-strict-provenance" cargo +nightly miri test --lib

template_crate/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod tests {
7171

7272
proptest! {
7373
#[test]
74+
#[cfg_attr(miri, ignore)]
7475
fn addition_proptest(a in 0_u8..20, b in 0_u8..20) {
7576
assert_eq!(
7677
a.checked_add(b),

0 commit comments

Comments
 (0)