name: ci

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on:
  schedule:
    - cron: '0 10 * * *'
  push:
    branches:
      - 'master'
      - 'releases/v*'
    tags:
      - 'v*'
  pull_request:

jobs:
  default:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Set up QEMU
        id: qemu
        uses: ./
      -
        name: Available platforms
        run: echo ${{ steps.qemu.outputs.platforms }}

  main:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        image:
          - tonistiigi/binfmt:latest
          - tonistiigi/binfmt:master
        platforms:
          - all
          - arm64,riscv64,arm
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Set up QEMU
        id: qemu
        uses: ./
        with:
          image: ${{ matrix.image }}
          platforms: ${{ matrix.platforms }}
      -
        name: Available platforms
        run: echo ${{ steps.qemu.outputs.platforms }}

  error:
    runs-on: ubuntu-latest
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Stop docker
        run: |
          sudo systemctl stop docker docker.socket
      -
        name: Set up QEMU
        id: qemu
        continue-on-error: true
        uses: ./
      -
        name: Check
        run: |
          echo "${{ toJson(steps.qemu) }}"
          if [ "${{ steps.qemu.outcome }}" != "failure" ] || [ "${{ steps.qemu.conclusion }}" != "success" ]; then
            echo "::error::Should have failed"
            exit 1
          fi

  cache-image:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        cache:
          - true
          - false
    steps:
      -
        name: Checkout
        uses: actions/checkout@v4
      -
        name: Set up QEMU
        id: qemu
        uses: ./
        with:
          image: tonistiigi/binfmt:master
          cache-image: ${{ matrix.cache }}
      -
        name: Available platforms
        run: echo ${{ steps.qemu.outputs.platforms }}