vmtest 0.18.0

Helps run your tests in virtual machines
Documentation
# This job builds test kernels and uploads them to the `test-assets` dummy
# release as assets.
#
# It works by looking at the tests/KERNELS file in the repository and checks
# it against all the already-uploaded kernels.

name: Kernels

on:
  push:
    branches: [ "master" ]
    paths:
      - 'tests/KERNELS'
      - 'tests/kernels/**'

concurrency:
  # Ensure only a single instance of this job is run at any time
  group: ${{ github.ref }}

permissions:
  contents: write

jobs:
  build-upload:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Calculate needed kernels
      id: calculate
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        existing=$(gh release view test_assets --json assets --jq '.[][].name')

        # Begin multiline output parameter
        echo "NEEDED_KERNELS<<MULTILINE_EOF" >> "$GITHUB_OUTPUT"

        echo "$existing" | python3 -c '
        import sys

        # Calculate kernels that have already been uploaded
        existing = {line.strip() for line in sys.stdin}
        with open("./tests/KERNELS", "r") as f:
            lines = {line.strip() for line in f if line.strip()}

        # Print to stdout kernel we need to build and upload
        for line in lines:
            parts = line.split()
            name = f"bzImage-{parts[0]}-{parts[1]}"
            if name not in existing:
                print(line)
        ' | tee -a "$GITHUB_OUTPUT"

        # End multiline output parameter
        echo "MULTILINE_EOF" >> "$GITHUB_OUTPUT"

    - name: Build needed kernels
      run: |
        while IFS= read -r args; do
            echo "Building: ${args}"
            # NB: we want to word split here
            ./scripts/build_kernel.sh $args
        done <<< "${{ steps.calculate.outputs.NEEDED_KERNELS }}"

    - name: Upload freshly built kernels
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        for kernel in bzImage-*; do
          gh release upload test_assets "$kernel"
        done