name: CI (PR label)

on:
    # Also trigger in case the PR labels change so that we can re-check the execution condition
    pull_request:
        types: [labeled, synchronize, reopened]

concurrency:
    group: release
    cancel-in-progress: false

jobs:
    wait_for_checks:
        name: Wait for code checks to pass
        runs-on: ubuntu-latest
        steps:
            -   name: Wait for existing checks or skip if none
                uses: lewagon/wait-on-check-action@v1.3.4
                with:
                    ref: ${{ github.event.pull_request.head.sha }}
                    repo-token: ${{ secrets.GITHUB_TOKEN }}
                    check-regexp: (Code checks)
                    wait-interval: 10
                    running-workflow-name: 'Wait for code checks to pass'
                    allowed-conclusions: success,neutral,skipped
                continue-on-error: false

    push_pkg_pr_new:
        needs: [ wait_for_checks ]
        # Run ONLY when PR has the "beta" label
        if: contains(github.event.pull_request.labels.*.name, 'beta')
        name: Push to pkg.pr.new
        uses: ./.github/workflows/_publish_to_pkg_pr_new.yaml
        with:
            ref: ${{ github.event.pull_request.head.ref }}

    evaluations:
        needs: [ wait_for_checks ]
        name: MCP tool calling evaluations
        # Run when PR is labeled with 'validated'
        if: github.event.action == 'labeled' && github.event.label.name == 'validated'
        uses: ./.github/workflows/_evaluations.yaml
        secrets: inherit
        with:
            pr_number: ${{ github.event.pull_request.number }}
