|
1 | 1 | # GitHub Actions workflow to monitor Yamato CI job state on pull requests |
| 2 | +# We are using https://cli.github.com/manual/gh_pr_checks |
| 3 | +# The aim is to ensure that conditionally triggered Yamato jobs are completed successfully before allowing merges |
2 | 4 |
|
3 | 5 | name: Yamato PR Supervisor |
4 | 6 |
|
|
20 | 22 | GRACE_PERIOD_SECONDS: 120 # 2 minutes |
21 | 23 | # How often to poll the GitHub API to see if job has finished (fail or succeeded) |
22 | 24 | POLLING_INTERVAL_SECONDS: 30 |
23 | | - # Max time to wait for the job to finish |
24 | | - TIMEOUT_MINUTES: 360 |
25 | 25 |
|
26 | 26 | steps: |
27 | 27 | - name: Checkout repository |
|
31 | 31 | env: |
32 | 32 | GH_TOKEN: ${{ secrets.GH_TOKEN }} |
33 | 33 | run: | |
34 | | - # Give Yamato a moment to trigger its jobs |
35 | | - echo "Waiting for 2 minutes to allow Yamato jobs to start..." |
36 | | - sleep 120 |
37 | | -
|
38 | 34 | start_time=$(date +%s) |
39 | 35 | timeout_seconds=$((TIMEOUT_MINUTES * 60)) |
40 | 36 |
|
|
43 | 39 | while true; do |
44 | 40 | current_time=$(date +%s) |
45 | 41 | elapsed_seconds=$((current_time - start_time)) |
46 | | -
|
47 | | - # --- Timeout Check --- |
48 | | - if [ $elapsed_seconds -gt $timeout_seconds ]; then |
49 | | - echo "::error::Timeout of $TIMEOUT_MINUTES minutes reached. The Yamato job '$CHECK_NAME' did not complete in time." |
50 | | - exit 1 |
51 | | - fi |
52 | | - |
53 | | - # --- Get PR Checks using GitHub CLI --- |
54 | | - # https://cli.github.com/manual/gh_pr_checks |
55 | | - # This command gets all checks for the current PR in JSON format |
56 | | - checks_json=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state) |
57 | 42 | |
58 | | - # --- Find our specific check using jq --- |
59 | | - check_status=$(echo "$checks_json" | jq -r ".[] | select(.name == \"$CHECK_NAME\") | .state") |
| 43 | + checks_json=$(gh pr checks ${{ github.event.pull_request.number }} --json name,state | jq ".[] | select(.name == \"$CHECK_NAME\")") |
60 | 44 | |
61 | 45 | if [ -z "$check_status" ]; then |
62 | 46 | # Case 1: The check has not appeared yet. |
|
72 | 56 | echo "Check '$CHECK_NAME' is currently '$check_status'. Waiting..." |
73 | 57 | elif [ "$check_status" == "pass" ]; then |
74 | 58 | # Case 3: The check has finished. |
75 | | - echo "Check '$CHECK_NAME' completed with conclusion: 'success'. Great!" |
| 59 | + echo "Check '$CHECK_NAME' completed with conclusion: 'success'." |
76 | 60 | exit 0 |
77 | 61 | else |
78 | 62 | echo "::error::Check '$CHECK_NAME' completed with conclusion: '$check_status'." |
|
0 commit comments