|
| 1 | +--- |
| 2 | +name: Integration Tests |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "action.yaml" |
| 7 | + - ".github/workflows/integration-tests.yaml" |
| 8 | + |
| 9 | +jobs: |
| 10 | + target-unnamed: |
| 11 | + permissions: {} |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - run: sleep 10 |
| 15 | + |
| 16 | + target-named: |
| 17 | + name: Target Named |
| 18 | + permissions: {} |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - run: sleep 10 |
| 22 | + |
| 23 | + test-same-workflow: |
| 24 | + name: Test Same Workflow |
| 25 | + # These permissions are needed to: |
| 26 | + # - Checkout the repo |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + - uses: ./ |
| 33 | + id: wait-for-job-unnamed |
| 34 | + with: |
| 35 | + run-id: ${{ github.run_id }} |
| 36 | + job-name: target-unnamed |
| 37 | + poll-interval: 5 |
| 38 | + - name: Validate wait for unnamed job |
| 39 | + run: | |
| 40 | + set -x |
| 41 | + [[ "$conclusion" == "success" ]] || exit 1 |
| 42 | +
|
| 43 | + # https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run |
| 44 | + job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')" |
| 45 | + [[ "$job_status" == "completed" ]] || exit 1 |
| 46 | + env: |
| 47 | + GH_TOKEN: ${{ github.token }} |
| 48 | + job_id: ${{ steps.wait-for-job-unnamed.outputs.job-id }} |
| 49 | + conclusion: ${{ steps.wait-for-job-unnamed.outputs.conclusion }} |
| 50 | + - uses: ./ |
| 51 | + id: wait-for-job-named |
| 52 | + with: |
| 53 | + run-id: ${{ github.run_id }} |
| 54 | + job-name: Target Named |
| 55 | + poll-interval: 5 |
| 56 | + - name: Validate wait for named job |
| 57 | + run: | |
| 58 | + set -x |
| 59 | + [[ "$conclusion" == "success" ]] || exit 1 |
| 60 | +
|
| 61 | + # https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run |
| 62 | + job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')" |
| 63 | + [[ "$job_status" == "completed" ]] || exit 1 |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ github.token }} |
| 66 | + job_id: ${{ steps.wait-for-job-named.outputs.job-id }} |
| 67 | + conclusion: ${{ steps.wait-for-job-named.outputs.conclusion }} |
| 68 | + |
| 69 | + test-build-workflow: |
| 70 | + name: Test Build Workflow |
| 71 | + # These permissions are needed to: |
| 72 | + # - Checkout the repo |
| 73 | + permissions: |
| 74 | + contents: read |
| 75 | + runs-on: ubuntu-latest |
| 76 | + steps: |
| 77 | + - uses: actions/checkout@v4 |
| 78 | + - uses: beacon-biosignals/get-workflow-run@v1 |
| 79 | + id: workflow-run |
| 80 | + with: |
| 81 | + workflow-file: target-workflow.yaml |
| 82 | + commit-sha: ${{ github.event.pull_request.head.sha }} |
| 83 | + - uses: ./ |
| 84 | + id: wait-for-job |
| 85 | + with: |
| 86 | + run-id: ${{ steps.workflow-run.outputs.run-id }} |
| 87 | + job-name: Build |
| 88 | + poll-interval: 5 |
| 89 | + - name: Validate wait job |
| 90 | + run: | |
| 91 | + [[ "$conclusion" == "success" ]] || exit 1 |
| 92 | +
|
| 93 | + # https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#list-jobs-for-a-workflow-run |
| 94 | + run_jobs="$(gh api -X GET "/repos/{owner}/{repo}/actions/runs/${run_id:?}/jobs" --jq '.jobs | {jobs: map({name, status, conclusion})}')" |
| 95 | +
|
| 96 | + # https://docs.github.com/en/rest/actions/workflow-jobs?apiVersion=2022-11-28#get-a-job-for-a-workflow-run |
| 97 | + job_status="$(gh api -X GET "/repos/{owner}/{repo}/actions/jobs/${job_id:?}" --jq '.status')" |
| 98 | + if [[ "$job_status" != "completed" ]]; then |
| 99 | + jq <<<"$run_jobs" |
| 100 | + exit 1 |
| 101 | + fi |
| 102 | +
|
| 103 | + # The workflow run status may be "queued" when a subset of the jobs have |
| 104 | + # completed and the remaining jobs are "queued". |
| 105 | + # https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#get-a-workflow-run |
| 106 | + run_status="$(gh api "/repos/{owner}/{repo}/actions/runs/${run_id}" --jq '.status')" |
| 107 | + if [[ "$run_status" != "in_progress" && "$run_status" != "queued" ]]; then |
| 108 | + jq <<<"$run_jobs" |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + run_id: ${{ steps.workflow-run.outputs.run-id }} |
| 114 | + job_id: ${{ steps.wait-for-job.outputs.job-id }} |
| 115 | + conclusion: ${{ steps.wait-for-job.outputs.conclusion }} |
| 116 | + - uses: actions/download-artifact@v4 |
| 117 | + with: |
| 118 | + name: build |
| 119 | + run-id: ${{ steps.workflow-run.outputs.run-id }} |
| 120 | + github-token: ${{ github.token }} |
| 121 | + - name: Validate artifact |
| 122 | + run: | |
| 123 | + jq <build.json |
| 124 | + [[ "$(jq -er .run_id <build.json)" == "${{ steps.workflow-run.outputs.run-id }}" ]] || exit 1 |
| 125 | + [[ "$(jq -er .run_attempt <build.json)" == "${{ steps.workflow-run.outputs.run-attempt }}" ]] || exit 1 |
| 126 | +
|
| 127 | + test-missing-workflow: |
| 128 | + name: Test Missing Workflow |
| 129 | + # These permissions are needed to: |
| 130 | + # - Checkout the repo |
| 131 | + permissions: |
| 132 | + contents: read |
| 133 | + runs-on: ubuntu-latest |
| 134 | + steps: |
| 135 | + - uses: actions/checkout@v4 |
| 136 | + - uses: ./ |
| 137 | + id: wait-for-job |
| 138 | + with: |
| 139 | + run-id: ${{ github.run_id }} |
| 140 | + job-name: missing |
| 141 | + timeout: 10 |
| 142 | + poll-interval: 5 |
| 143 | + continue-on-error: true |
| 144 | + - name: Validate timeout |
| 145 | + run: | |
| 146 | + [[ "$outcome" == "failure" ]] || exit 1 |
| 147 | + [[ -z "$job_id" ]] || exit 1 |
| 148 | + [[ -z "$conclusion" ]] || exit 1 |
| 149 | + env: |
| 150 | + outcome: ${{ steps.wait-for-job.outcome }} |
| 151 | + job_id: ${{ steps.wait-for-job.outputs.job-id }} |
| 152 | + conclusion: ${{ steps.wait-for-job.outputs.conclusion }} |
0 commit comments