|
3 | 3 | push: |
4 | 4 | branches: [main] |
5 | 5 | workflow_dispatch: |
6 | | - workflow_run: |
7 | | - workflows: [Benchmarks] |
8 | | - types: [completed] |
| 6 | + inputs: |
| 7 | + benchmark_run_id: |
| 8 | + description: Benchmark run to await (optional) |
| 9 | + required: false |
| 10 | + type: string |
| 11 | + default: '' |
9 | 12 | permissions: |
10 | 13 | contents: read |
11 | 14 | jobs: |
|
16 | 19 | cancel-in-progress: false |
17 | 20 | if: >- |
18 | 21 | github.repository == 'managedcode/KeyLoad' && github.event.repository.id == 477801965 && |
19 | | - ((github.ref == 'refs/heads/main' && |
20 | | - (github.event_name == 'push' || github.event_name == 'workflow_dispatch')) || |
21 | | - (github.event_name == 'workflow_run' && |
22 | | - github.event.workflow_run.head_repository.id == 477801965 && |
23 | | - github.event.workflow_run.head_branch == 'main' && |
24 | | - github.event.workflow_run.name == 'Benchmarks' && |
25 | | - github.event.workflow_run.path == '.github/workflows/benchmarks.yml' && |
26 | | - github.event.workflow_run.status == 'completed' && |
27 | | - (github.event.workflow_run.event == 'push' || github.event.workflow_run.event == 'workflow_dispatch') && |
28 | | - (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure'))) |
| 22 | + github.ref == 'refs/heads/main' && |
| 23 | + (github.event_name == 'push' || github.event_name == 'workflow_dispatch') |
29 | 24 | runs-on: ubuntu-latest |
30 | 25 | timeout-minutes: 180 |
31 | 26 | permissions: {contents: read, actions: read} |
|
37 | 32 | GH_TOKEN: ${{ github.token }} |
38 | 33 | GH_REPO: ${{ github.repository }} |
39 | 34 | steps: |
| 35 | + - name: Await the triggering benchmark run |
| 36 | + if: github.event_name == 'workflow_dispatch' && inputs.benchmark_run_id != '' |
| 37 | + timeout-minutes: 5 |
| 38 | + env: |
| 39 | + BENCHMARK_RUN_ID: ${{ inputs.benchmark_run_id }} |
| 40 | + run: | |
| 41 | + [[ "$BENCHMARK_RUN_ID" =~ ^[1-9][0-9]*$ && ${#BENCHMARK_RUN_ID} -le 20 ]] |
| 42 | + benchmark_deadline=$((SECONDS + 270)) |
| 43 | + benchmark_poll=0 |
| 44 | + while ((SECONDS < benchmark_deadline)); do |
| 45 | + benchmark_remaining=$((benchmark_deadline - SECONDS)) |
| 46 | + ((benchmark_remaining > 0)) || break |
| 47 | + benchmark_request_timeout=$((benchmark_remaining < 10 ? benchmark_remaining : 10)) |
| 48 | + if ! benchmark_metadata=$(timeout "${benchmark_request_timeout}s" gh api "repos/$GH_REPO/actions/runs/$BENCHMARK_RUN_ID"); then |
| 49 | + printf '%s\n' 'Unable to read the triggering benchmark run within the bounded request.' >&2 |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + jq -e --arg run "$BENCHMARK_RUN_ID" ' |
| 53 | + (.id | tostring) == $run and |
| 54 | + .repository.id == 477801965 and .repository.full_name == "managedcode/KeyLoad" and |
| 55 | + .head_repository.id == 477801965 and .head_repository.full_name == "managedcode/KeyLoad" and |
| 56 | + .head_branch == "main" and .name == "Benchmarks" and |
| 57 | + .path == ".github/workflows/benchmarks.yml" and |
| 58 | + (.event == "push" or .event == "workflow_dispatch") and |
| 59 | + (.head_sha | test("^[a-f0-9]{40}$"))' <<< "$benchmark_metadata" > /dev/null |
| 60 | + if [[ "$(jq -r .status <<< "$benchmark_metadata")" == completed ]]; then |
| 61 | + exit 0 |
| 62 | + fi |
| 63 | + benchmark_poll=$((benchmark_poll + 1)) |
| 64 | + printf 'Waiting for benchmark completion (poll %s).\n' "$benchmark_poll" |
| 65 | + benchmark_remaining=$((benchmark_deadline - SECONDS)) |
| 66 | + ((benchmark_remaining > 0)) || break |
| 67 | + sleep "$((benchmark_remaining < 5 ? benchmark_remaining : 5))" |
| 68 | + done |
| 69 | + printf '%s\n' 'The triggering benchmark run did not complete within the bounded wait.' >&2 |
| 70 | + exit 1 |
40 | 71 | - name: Download source code |
41 | 72 | uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
42 | 73 | with: |
|
0 commit comments