Skip to content

Commit

Permalink
ci: Build and add kernels to cache
Browse files Browse the repository at this point in the history
Ease maintenance of landlock-test-tools and avoid adding new built
artifacts for each major kernel release.

We now use the latest versions according to landlock-lsm/linux branches
for each meaningful kernel.

To simplify the new ubuntu_22_rust_stable, don't run tests against the
local kernel, which is already done with ubuntu_22_rust_msrv.

Reorder install, clone and build steps in ubuntu_22_rust_stable to clean
up the working directory.

Signed-off-by: Mickaël Salaün <[email protected]>
  • Loading branch information
l0kod committed Sep 4, 2024
1 parent 3c0665c commit ec1c1c6
Showing 1 changed file with 84 additions and 25 deletions.
109 changes: 84 additions & 25 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,68 @@ jobs:
outputs:
commits: ${{ toJSON(steps.*.outputs.*) }}

kernel_list:
runs-on: ubuntu-22.04
outputs:
kernels: ${{ toJSON(steps.id.outputs.*) }}
steps:

- name: Identify latest Linux versions
id: id
run: |
echo "List of tested kernels:" > $GITHUB_STEP_SUMMARY
abi=0
for version in 5.10 5.15 6.1 6.4 6.7; do
commit="$(git ls-remote https://github.com/landlock-lsm/linux refs/heads/linux-${version}.y | awk 'NR == 1 { print $1 }')"
if [[ -z "${commit}" ]]; then
echo "ERROR: Failed to fetch Linux ${version}" >&2
exit 1
fi
echo "kernel_${abi}={ \"version\":\"${version}\", \"abi\":\"${abi}\", \"commit\":\"${commit}\" }" >> $GITHUB_OUTPUT
echo "- [Linux ${version}.y](https://github.com/landlock-lsm/linux/commit/${commit}) with Landlock ABI ${abi}" >> $GITHUB_STEP_SUMMARY
let abi++ || :
done
get_kernels:
runs-on: ubuntu-22.04
needs: kernel_list
strategy:
fail-fast: false
matrix:
kernel: ${{ fromJSON(needs.kernel_list.outputs.kernels) }}
steps:

- name: Cache Linux ${{ fromJSON(matrix.kernel).version}}.y
id: cache_linux
uses: actions/cache@v4
with:
path: linux-${{ fromJSON(matrix.kernel).version }}
key: linux-${{ fromJSON(matrix.kernel).commit }}

- name: Clone Landlock test tools
if: steps.cache_linux.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: landlock-lsm/landlock-test-tools
ref: ${{ env.LANDLOCK_TEST_TOOLS_COMMIT }}
path: landlock-test-tools

- name: Clone Linux ${{ fromJSON(matrix.kernel).version}}.y
if: steps.cache_linux.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: landlock-lsm/linux
ref: ${{ fromJSON(matrix.kernel).commit }}
path: linux

- name: Build Linux ${{ fromJSON(matrix.kernel).version}}.y
if: steps.cache_linux.outputs.cache-hit != 'true'
run: |
cp landlock-test-tools/kernels/config-${{ fromJSON(matrix.kernel).version}} linux/.config
cd linux
../landlock-test-tools/kernels/make-uml.sh
mv linux ../linux-${{ fromJSON(matrix.kernel).version}}
ubuntu_22_rust_msrv:
runs-on: ubuntu-22.04
needs: commit_list
Expand Down Expand Up @@ -130,20 +192,23 @@ jobs:

ubuntu_22_rust_stable:
runs-on: ubuntu-22.04
needs: commit_list
needs: [commit_list, kernel_list, get_kernels]
strategy:
fail-fast: false
matrix:
commit: ${{ fromJSON(needs.commit_list.outputs.commits) }}
kernel: ${{ fromJSON(needs.kernel_list.outputs.kernels) }}
env:
LANDLOCK_CRATE_TEST_ABI: 3
# $CARGO is used by landlock-test-tools/test-rust.sh
CARGO: rustup run stable cargo
steps:

- uses: actions/checkout@v4
with:
ref: ${{ matrix.commit }}
- name: Install Rust stable
run: |
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
rustup default stable
rustup update
- name: Clone Landlock test tools
uses: actions/checkout@v4
Expand All @@ -152,26 +217,20 @@ jobs:
ref: ${{ env.LANDLOCK_TEST_TOOLS_COMMIT }}
path: landlock-test-tools

- name: Install Rust stable
run: |
rm ~/.cargo/bin/{cargo-fmt,rustfmt} || :
rustup default stable
rustup update
- name: Run tests against the local kernel (Landlock ABI ${{ env.LANDLOCK_CRATE_TEST_ABI }})
run: $CARGO test --verbose

- name: Run tests against Linux 5.10
run: ./landlock-test-tools/test-rust.sh linux-5.10 0

- name: Run tests against Linux 5.15
run: ./landlock-test-tools/test-rust.sh linux-5.15 1

- name: Run tests against Linux 6.1
run: ./landlock-test-tools/test-rust.sh linux-6.1 2
- name: Clone rust-landlock
uses: actions/checkout@v4
with:
ref: ${{ matrix.commit }}
path: rust-landlock

- name: Run tests against Linux 6.4
run: ./landlock-test-tools/test-rust.sh linux-6.4 3
- name: Get Linux ${{ fromJSON(matrix.kernel).version}}.y
uses: actions/cache/restore@v4
with:
path: linux-${{ fromJSON(matrix.kernel).version }}
key: linux-${{ fromJSON(matrix.kernel).commit }}
fail-on-cache-miss: true

- name: Run tests against Linux 6.7
run: ./landlock-test-tools/test-rust.sh linux-6.7 4
- name: Run tests against Linux ${{ fromJSON(matrix.kernel).version }}.y
run: |
cd rust-landlock
../landlock-test-tools/test-rust.sh ../linux-${{ fromJSON(matrix.kernel).version }} ${{ fromJSON(matrix.kernel).abi }}

0 comments on commit ec1c1c6

Please sign in to comment.