Skip to content

Commit edbe4f3

Browse files
committed
Add GitHub CI configuration
Run Rust and JSON schema tests against all commits. Set Rust MSRV to 1.63 Imported from https://github.com/landlock-lsm/rust-landlock/blob/main/.github/workflows/rust.yml Signed-off-by: Mickaël Salaün <mic@digikod.net>
1 parent 3afa733 commit edbe4f3

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed

.github/workflows/rust.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Rust checks
2+
3+
permissions: {}
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
env:
12+
CARGO_TERM_COLOR: always
13+
RUSTDOCFLAGS: -D warnings
14+
RUSTFLAGS: -D warnings
15+
16+
# Ubuntu versions: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
17+
18+
jobs:
19+
commit_list:
20+
runs-on: ubuntu-22.04
21+
steps:
22+
23+
- uses: actions/checkout@v4
24+
with:
25+
fetch-depth: 0
26+
27+
- name: Get commit list (push)
28+
id: get_commit_list_push
29+
if: ${{ github.event_name == 'push' }}
30+
run: |
31+
echo "id0=$GITHUB_SHA" > $GITHUB_OUTPUT
32+
echo "List of tested commits:" > $GITHUB_STEP_SUMMARY
33+
sed -n 's,^id[0-9]\+=\(.*\),- https://github.com/landlock-lsm/landlockconfig/commit/\1,p' -- $GITHUB_OUTPUT >> $GITHUB_STEP_SUMMARY
34+
35+
- name: Get commit list (PR)
36+
id: get_commit_list_pr
37+
if: ${{ github.event_name == 'pull_request' }}
38+
run: |
39+
git rev-list --reverse refs/remotes/origin/${{ github.base_ref }}..${{ github.event.pull_request.head.sha }} | awk '{ print "id" NR "=" $1 }' > $GITHUB_OUTPUT
40+
git diff --quiet ${{ github.event.pull_request.head.sha }} ${{ github.sha }} || echo "id0=$GITHUB_SHA" >> $GITHUB_OUTPUT
41+
echo "List of tested commits:" > $GITHUB_STEP_SUMMARY
42+
sed -n 's,^id[0-9]\+=\(.*\),- https://github.com/landlock-lsm/landlockconfig/commit/\1,p' -- $GITHUB_OUTPUT >> $GITHUB_STEP_SUMMARY
43+
44+
outputs:
45+
commits: ${{ toJSON(steps.*.outputs.*) }}
46+
47+
ubuntu_22_schema:
48+
runs-on: ubuntu-22.04
49+
needs: commit_list
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
54+
steps:
55+
56+
- uses: actions/checkout@v4
57+
with:
58+
ref: ${{ matrix.commit }}
59+
60+
- name: Install check-jsonschema
61+
run: |
62+
sudo apt update
63+
sudo apt install -y python3-jsonschema
64+
65+
- name: Check JSON schema
66+
run: ./schema/check.sh examples/mini-write-tmp.json
67+
68+
ubuntu_22_rust_msrv:
69+
runs-on: ubuntu-22.04
70+
needs: commit_list
71+
strategy:
72+
fail-fast: false
73+
matrix:
74+
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
75+
steps:
76+
77+
- uses: actions/checkout@v4
78+
with:
79+
ref: ${{ matrix.commit }}
80+
81+
- name: Get MSRV
82+
run: sed -n 's/^rust-version = "\([0-9.]\+\)"$/RUST_TOOLCHAIN=\1/p' Cargo.toml >> $GITHUB_ENV
83+
84+
- name: Install Rust MSRV
85+
run: |
86+
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
87+
rustup default ${{ env.RUST_TOOLCHAIN }}
88+
rustup update ${{ env.RUST_TOOLCHAIN }}
89+
90+
- name: Build
91+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo build --verbose
92+
93+
- name: Build tests
94+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo build --tests --verbose
95+
96+
- name: Run tests
97+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo test --verbose
98+
99+
ubuntu_22_rust_stable:
100+
runs-on: ubuntu-22.04
101+
needs: commit_list
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
106+
steps:
107+
108+
- name: Install Rust stable
109+
run: |
110+
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
111+
rustup default stable
112+
rustup component add rustfmt clippy
113+
rustup update
114+
115+
- uses: actions/checkout@v4
116+
with:
117+
ref: ${{ matrix.commit }}
118+
119+
- name: Build
120+
run: rustup run stable cargo build --verbose
121+
122+
- name: Run tests
123+
run: rustup run stable cargo test --verbose
124+
125+
- name: Check format
126+
run: rustup run stable cargo fmt --all -- --check
127+
128+
- name: Check source with Clippy
129+
run: rustup run stable cargo clippy -- --deny warnings
130+
131+
- name: Check tests with Clippy
132+
run: rustup run stable cargo clippy --tests -- --deny warnings
133+
134+
- name: Check documentation
135+
run: rustup run stable cargo doc --no-deps

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "landlockconfig"
33
version = "0.1.0"
44
edition = "2021"
5+
rust-version = "1.66"
56
description = "Sandboxer library leveraging Landlock with JSON configuration"
67
homepage = "https://landlock.io"
78
repository = "https://github.com/landlock-lsm/island"

0 commit comments

Comments
 (0)