name: validate

on:
  push:
    branches:
      - 'master'
      - 'releases/v*'
  pull_request:

jobs:
  prepare:
    runs-on: ubuntu-latest
    outputs:
      targets: ${{ steps.targets.outputs.matrix }}
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Targets matrix
        id: targets
        run: |
          echo "matrix=$(docker buildx bake validate --print | jq -cr '.group.validate.targets')" >> $GITHUB_OUTPUT

  validate:
    runs-on: ubuntu-latest
    needs:
      - prepare
    strategy:
      fail-fast: false
      matrix:
        target: ${{ fromJson(needs.prepare.outputs.targets) }}
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Validate
        uses: docker/bake-action@v2
        with:
          targets: ${{ matrix.target }}
