name: CI

on:
  pull_request:
    paths:
      - ".github/workflows/ci.yml"
      - "**.zig"
  push:
    paths:
      - ".github/workflows/ci.yml"
      - "**.zig"
    branches:
      - main
  schedule:
    - cron: "0 0 * * *"
concurrency:
  # Cancels pending runs when a PR gets updated.
  group: ${{ github.head_ref || github.run_id }}-${{ github.actor }}
  cancel-in-progress: true

jobs:
  build:
    strategy:
      matrix:
        os: [
          ubuntu-latest,
          macos-latest,
          windows-latest,
        ]
    runs-on: ${{ matrix.os }}
    timeout-minutes: 15
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Zig
        uses: goto-bus-stop/setup-zig@v2
        with:
          version: master
      - name: Zig environment variables
        run: zig env
      - name: Build test executables
        run: zig build all_tests -Dci --verbose
  build_and_test:
    runs-on: [self-hosted, Linux, X64]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set up Zig
        uses: goto-bus-stop/setup-zig@v2
        with:
          version: master
      - name: Zig environment variables
        run: zig env
      - name: Build test executables
        run: zig build all_tests -Dci -Dci_native --verbose
      - name: Test with QEMU
        run: zig build test_all -Dci -Dci_native --verbose
