ci: Adding minimal required job set and validation preventing PRs from merging when tests are running #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GitHub Actions workflow to monitor Yamato CI job state on pull requests | |
| # We are using https://cli.github.com/manual/gh_pr_checks | |
| # The aim is to ensure that conditionally triggered Yamato jobs are completed successfully before allowing merges | |
| name: Yamato PR Supervisor | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| branches: | |
| - develop | |
| - develop-2.0.0 | |
| - release/* | |
| jobs: | |
| yamato-supervisor: | |
| runs-on: ubuntu-latest | |
| env: | |
| # The name of the Yamato check to monitor | |
| CHECK_NAME: "Code changes PR checks" | |
| # How long to wait for the check to appear before assuming it won't run | |
| GRACE_PERIOD_SECONDS: 120 # 2 minutes | |
| # How often to poll the GitHub API to see if job has finished (fail or succeeded) | |
| POLLING_INTERVAL_SECONDS: 30 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Wait and Verify Yamato Job Status | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| run: | | |
| start_time=$(date +%s) | |
| timeout_seconds=$((TIMEOUT_MINUTES * 60)) | |
| echo "Starting to monitor for the state of check: '$CHECK_NAME'" | |
| while true; do | |
| current_time=$(date +%s) | |
| elapsed_seconds=$((current_time - start_time)) | |
| checks_json=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state | jq ".[] | select(.name == \"$CHECK_NAME\")") | |
| if [ -z "$check_status" ]; then | |
| # Case 1: The check has not appeared yet. | |
| if [ $elapsed_seconds -gt $GRACE_PERIOD_SECONDS ]; then | |
| echo "Grace period of $GRACE_PERIOD_SECONDS seconds has passed and the check '$CHECK_NAME' was not found." | |
| echo "Assuming it was not triggered (e.g., docs-only change). Success!" | |
| exit 0 | |
| else | |
| echo "Check '$CHECK_NAME' not found yet. Continuing to poll..." | |
| fi | |
| elif [ "$check_status" == "pending" ]; then | |
| # Case 2: The check is running. | |
| echo "Check '$CHECK_NAME' is currently '$check_status'. Waiting..." | |
| elif [ "$check_status" == "pass" ]; then | |
| # Case 3: The check has finished. | |
| echo "Check '$CHECK_NAME' completed with conclusion: 'success'." | |
| exit 0 | |
| else | |
| echo "::error::Check '$CHECK_NAME' completed with conclusion: '$check_status'." | |
| exit 1 | |
| fi | |
| # Wait before the next poll | |
| sleep $POLLING_INTERVAL_SECONDS | |
| done |