|
| 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 |
0 commit comments