name: Verify All Examples

on:
  workflow_dispatch:
  push:
    tags:
      - v*
  schedule:
    # Run once a day at 3:00 AM EST
    - cron: "0 8 * * *"

jobs:
  setup:
    name: Get Examples
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.set-matrix.outputs.matrix }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Install JQ Tool
        uses: mbround18/install-jq@v1

      - name: Set Matrix
        id: set-matrix
        run: |
          examples=$(ls examples | 
          awk '{print "examples/" $0}' | 
          grep -v examples/README.md | 
          grep -v examples/Makefile.toml | 
          grep -v examples/cargo-make | 
          grep -v examples/gtk | 
          jq -R -s -c 'split("\n")[:-1]')
          echo "Example Directories: $examples"
          echo "matrix={\"directory\":$examples}" >> "$GITHUB_OUTPUT"

  matrix-job:
    name: Verify
    needs: [setup]
    strategy:
      matrix: ${{ fromJSON(needs.setup.outputs.matrix) }}
      fail-fast: false
    uses: ./.github/workflows/run-cargo-make-task.yml
    with:
      directory: ${{ matrix.directory }}
      cargo_make_task: "verify-flow"
