Skip to content

Commit 31ec90e

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 31ec90e

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

.github/workflows/rust.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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: Check JSON schema
61+
run: ./schema/check.sh examples/mini-write-tmp.json
62+
63+
ubuntu_22_rust_msrv:
64+
runs-on: ubuntu-22.04
65+
needs: commit_list
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
70+
steps:
71+
72+
- uses: actions/checkout@v4
73+
with:
74+
ref: ${{ matrix.commit }}
75+
76+
- name: Get MSRV
77+
run: sed -n 's/^rust-version = "\([0-9.]\+\)"$/RUST_TOOLCHAIN=\1/p' Cargo.toml >> $GITHUB_ENV
78+
79+
- name: Install Rust MSRV
80+
run: |
81+
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
82+
rustup default ${{ env.RUST_TOOLCHAIN }}
83+
rustup update ${{ env.RUST_TOOLCHAIN }}
84+
85+
- name: Build
86+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo build --verbose
87+
88+
- name: Build tests
89+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo build --tests --verbose
90+
91+
- name: Run tests
92+
run: rustup run ${{ env.RUST_TOOLCHAIN }} cargo test --verbose
93+
94+
ubuntu_22_rust_stable:
95+
runs-on: ubuntu-22.04
96+
needs: commit_list
97+
strategy:
98+
fail-fast: false
99+
matrix:
100+
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
101+
steps:
102+
103+
- name: Install Rust stable
104+
run: |
105+
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
106+
rustup default stable
107+
rustup component add rustfmt clippy
108+
rustup update
109+
110+
- uses: actions/checkout@v4
111+
with:
112+
ref: ${{ matrix.commit }}
113+
114+
- name: Build
115+
run: rustup run stable cargo build --verbose
116+
117+
- name: Run tests
118+
run: rustup run stable cargo test --verbose
119+
120+
- name: Check format
121+
run: rustup run stable cargo fmt --all -- --check
122+
123+
- name: Check source with Clippy
124+
run: rustup run stable cargo clippy -- --deny warnings
125+
126+
- name: Check tests with Clippy
127+
run: rustup run stable cargo clippy --tests -- --deny warnings
128+
129+
- name: Check documentation
130+
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.63"
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)