name: "Next.js tip"

on:
  workflow_dispatch: # disabled schedule — re-enable once ecosystem tests are stable

permissions:
  contents: read

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

jobs:
  load-repos:
    runs-on: ubuntu-latest
    outputs:
      repos: ${{ steps.read.outputs.repos }}
    steps:
      - uses: actions/checkout@v4
      - id: read
        run: echo "repos=$(jq -c . .github/repos.json)" >> "$GITHUB_OUTPUT"

  test:
    name: "${{ matrix.repo.name }} (next@canary)"
    needs: load-repos
    strategy:
      fail-fast: false
      matrix:
        repo: ${{ fromJson(needs.load-repos.outputs.repos) }}
    uses: ./.github/workflows/ecosystem-run.yml
    with:
      repo_url: ${{ matrix.repo.url }}
      next_version: "canary"

  notify-on-failure:
    name: Send failure email
    needs: test
    if: failure()
    runs-on: ubuntu-latest
    permissions:
      actions: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 24

      - name: Send failure notification
        if: ${{ secrets.EMAIL_API_TOKEN != '' }}
        env:
          EMAIL_API_TOKEN: ${{ secrets.EMAIL_API_TOKEN }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: node .github/scripts/send-email.mjs
