name: Linux kernel CI

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Install GCC
      run: |
        sudo apt-get update
        sudo apt-get install -y gcc-13
    - name: Linux kernel build
      run: make -C linux_kernel CC=gcc-13
    - name: Load leancrypto kernel module
      run: mkdir dmesg-logs && sudo insmod linux_kernel/leancrypto.ko || sudo dmesg > dmesg-logs/leancrypto.dmesg
    - name: Linux kernel test
      run: for i in linux_kernel/*.ko; do if [ "$i" != "linux_kernel/leancrypto.ko" ]; then sudo insmod $i || sudo dmesg > dmesg-logs/$(basename $i).dmesg; fi; done
    - name: Archive test logs
      if: always()
      uses: actions/upload-artifact@v4
      with:
        name: meson-logs
        path: dmesg-logs
