Skip to content

Commit 21f2375

Browse files
committed
Add GitHub CI defaults
1 parent 2402792 commit 21f2375

5 files changed

Lines changed: 187 additions & 7 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 94 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,103 @@
1-
name: ci
1+
name: Rust CI
22

33
on:
4-
pull_request:
54
push:
6-
branches: [main]
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
CARGO_TERM_COLOR: always
16+
RUST_BACKTRACE: 1
717

818
jobs:
919
checks:
20+
name: Format, lint, test, and package
1021
runs-on: ubuntu-latest
22+
timeout-minutes: 30
1123
steps:
12-
- uses: actions/checkout@v4
13-
- uses: dtolnay/rust-toolchain@stable
24+
- name: Checkout repository
25+
uses: actions/checkout@v6
26+
27+
- name: Install Rust toolchain
28+
shell: bash
29+
run: scripts/ci_install_rust.sh
30+
31+
- name: Cache Rust build output
32+
uses: Swatinem/rust-cache@v2
33+
with:
34+
cache-on-failure: true
35+
36+
- name: Run checks
37+
run: scripts/checks.sh
38+
39+
platform:
40+
name: Platform tests (${{ matrix.os }})
41+
runs-on: ${{ matrix.os }}
42+
timeout-minutes: 20
43+
strategy:
44+
fail-fast: false
45+
matrix:
46+
os:
47+
- ubuntu-latest
48+
- macos-latest
49+
- windows-latest
50+
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v6
54+
55+
- name: Install Rust toolchain
56+
shell: bash
57+
run: scripts/ci_install_rust.sh
58+
59+
- name: Cache Rust build output
60+
uses: Swatinem/rust-cache@v2
1461
with:
15-
components: clippy, rustfmt
16-
- run: bash scripts/checks.sh
62+
cache-on-failure: true
63+
64+
- name: Test default features
65+
run: cargo test --all-targets
66+
67+
- name: Test all features
68+
run: cargo test --all-targets --all-features
69+
70+
- name: Check no_std library build
71+
run: cargo check --no-default-features --lib
72+
73+
target-build:
74+
name: no_std target build (${{ matrix.target }})
75+
runs-on: ubuntu-latest
76+
timeout-minutes: 20
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
target:
81+
- x86_64-unknown-linux-gnu
82+
- aarch64-unknown-linux-gnu
83+
- wasm32-unknown-unknown
84+
- thumbv7em-none-eabihf
85+
86+
steps:
87+
- name: Checkout repository
88+
uses: actions/checkout@v6
89+
90+
- name: Install Rust toolchain
91+
shell: bash
92+
run: scripts/ci_install_rust.sh
93+
94+
- name: Install Rust target
95+
run: rustup target add ${{ matrix.target }}
96+
97+
- name: Cache Rust build output
98+
uses: Swatinem/rust-cache@v2
99+
with:
100+
cache-on-failure: true
101+
102+
- name: Check no_std library build
103+
run: cargo check --no-default-features --lib --target ${{ matrix.target }}

‎Cargo.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ include = [
2121
"CONTRIBUTING.md",
2222
"LICENSE-APACHE",
2323
"LICENSE-MIT",
24+
"rust-toolchain.toml",
2425
"src/**/*.rs",
2526
"examples/**/*.rs",
2627
"scripts/checks.sh",
28+
"scripts/ci_install_rust.sh",
2729
]
2830

2931
[features]

‎SECURITY.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ Security-sensitive changes should include:
1111
- tests for default, `alloc`, `unsafe-wipe`, and all-features builds;
1212
- `SAFETY.md` updates for unsafe code;
1313
- `THREAT_MODEL.md` updates for guarantee or scope changes.
14+
15+
## GitHub Security Defaults
16+
17+
Enable GitHub CodeQL default setup in the repository security settings. Keep the
18+
checked-in CI workflow separate from CodeQL so GitHub owns SARIF upload
19+
permissions and there is no competing advanced CodeQL workflow in this repo.

‎rust-toolchain.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.79"
3+
components = ["clippy", "rustfmt"]

‎scripts/ci_install_rust.sh‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env sh
2+
set -eu
3+
4+
toolchain="$(
5+
sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml | sed -n '1p'
6+
)"
7+
8+
if [ -z "$toolchain" ]; then
9+
echo "ci rust: rust-toolchain.toml is missing a channel" >&2
10+
exit 1
11+
fi
12+
13+
add_cargo_path() {
14+
if [ -n "${GITHUB_PATH:-}" ]; then
15+
printf '%s\n' "$HOME/.cargo/bin" >> "$GITHUB_PATH"
16+
fi
17+
export PATH="$HOME/.cargo/bin:$PATH"
18+
}
19+
20+
add_ci_cargo_wrapper() {
21+
if [ -z "${GITHUB_PATH:-}" ]; then
22+
return
23+
fi
24+
25+
wrapper_dir="${RUNNER_TEMP:-/tmp}/sanitization-rust-bin"
26+
mkdir -p "$wrapper_dir"
27+
{
28+
printf '%s\n' '#!/usr/bin/env sh'
29+
printf '%s\n' 'case "${1:-}" in'
30+
printf '%s\n' ' +*)'
31+
printf '%s\n' ' toolchain="${1#+}"'
32+
printf '%s\n' ' shift'
33+
printf '%s\n' ' exec rustup run "$toolchain" cargo "$@"'
34+
printf '%s\n' ' ;;'
35+
printf '%s\n' 'esac'
36+
printf 'exec rustup run %s cargo "$@"\n' "$toolchain"
37+
} > "$wrapper_dir/cargo"
38+
chmod +x "$wrapper_dir/cargo"
39+
40+
printf '%s\n' "$wrapper_dir" >> "$GITHUB_PATH"
41+
export PATH="$wrapper_dir:$PATH"
42+
}
43+
44+
install_rustup() {
45+
case "$(uname -s)" in
46+
MINGW* | MSYS* | CYGWIN*)
47+
echo "ci rust: rustup/cargo is broken on Windows; use the runner Rust install" >&2
48+
exit 1
49+
;;
50+
*)
51+
echo "ci rust: installing rustup"
52+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
53+
| sh -s -- -y --profile minimal --default-toolchain none
54+
add_cargo_path
55+
;;
56+
esac
57+
}
58+
59+
add_cargo_path
60+
61+
if ! command -v rustup >/dev/null 2>&1; then
62+
install_rustup
63+
fi
64+
65+
if ! cargo --version >/dev/null 2>&1; then
66+
echo "ci rust: cargo proxy is not usable before toolchain setup; reinstalling rustup"
67+
install_rustup
68+
fi
69+
70+
rustup set profile minimal
71+
rustup toolchain install "$toolchain" --component clippy --component rustfmt
72+
rustup default "$toolchain"
73+
add_ci_cargo_wrapper
74+
75+
if ! cargo --version >/dev/null 2>&1; then
76+
echo "ci rust: cargo proxy is still not usable after toolchain setup" >&2
77+
exit 1
78+
fi
79+
80+
rustup show
81+
cargo --version
82+
rustc --version

0 commit comments

Comments
 (0)