name: vmtest Build

on:
  schedule:
    - cron: '16 6 * * MON'
  workflow_dispatch:

jobs:
  build:
    strategy:
      matrix:
        flavor: [default, alternative, tiny]
        arch: [x86_64, aarch64, ppc64, s390x, arm]
      fail-fast: false
      max-parallel: 5
    runs-on: ubuntu-22.04
    permissions:
      contents: write
    env:
      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install dwarves libelf-dev
          pip install aiohttp uritemplate
      - name: Build and upload ${{ matrix.arch }} ${{ matrix.flavor }} kernels
        run: python3 -m vmtest.manage --kernel-directory build/vmtest/linux.git --build-directory build/vmtest/kbuild -K -a ${{ matrix.arch }} -f ${{ matrix.flavor }}
      - name: Upload kernel build logs
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: kernel-build-logs-${{ matrix.arch }}-${{ matrix.flavor }}
          path: build/vmtest/kbuild/*.log
          if-no-files-found: ignore
  test:
    needs: build
    uses: ./.github/workflows/ci.yml
    with:
      test_all_python_versions: true
      test_all_kernel_flavors: true
