Use a manual check for integration-test-result #33
This file contains 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
name: Integration tests | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
pull_request: | |
types: | |
- opened | |
- reopened | |
- synchronize | |
- converted_to_draft | |
- ready_for_review | |
- labeled | |
- unlabeled | |
- auto_merge_enabled | |
- auto_merge_disabled | |
merge_group: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
pre_check: | |
uses: ./.github/workflows/pre-check-integration.yml | |
matrix-test: | |
needs: pre_check | |
if: needs.pre_check.outputs.should_run == 'true' | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
variation: [one, two] | |
timeout-minutes: 5 | |
steps: | |
- name: Get the behavior from the PR description | |
id: get-behavior | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
let behavior = '{}'; | |
if (context.payload.pull_request) { | |
const { body } = context.payload.pull_request; | |
const regex = /^\#matrix-test-${{ matrix.variation }}:\s+(.*)$/m; | |
const result = regex.exec(body); | |
if (result) { | |
behavior = result[1]; | |
} | |
} | |
console.log(behavior); | |
return behavior; | |
- name: run matrix test | |
run: | | |
sleep ${{ fromJSON(steps.get-behavior.outputs.result).sleep || 60 }} | |
exit ${{ fromJSON(steps.get-behavior.outputs.result).exitCode || 0 }} | |
continue-on-error: ${{ matrix.variation == 'two' }} | |
standalone-test: | |
needs: pre_check | |
if: >- | |
needs.pre_check.outputs.should_run == 'true' && | |
( | |
github.event_name != 'pull_request' || | |
!contains(github.event.pull_request.labels.*.name, 'skip:standalone') | |
) | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Get the behavior from the PR description | |
id: get-behavior | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
let behavior = '{}'; | |
if (context.payload.pull_request) { | |
const { body } = context.payload.pull_request; | |
const regex = /^\#standalone-test:\s+(.*)$/m; | |
const result = regex.exec(body); | |
if (result) { | |
behavior = result[1]; | |
} | |
} | |
console.log(behavior); | |
return behavior; | |
- name: run standalone test | |
run: | | |
sleep ${{ fromJSON(steps.get-behavior.outputs.result).sleep || 45 }} | |
exit ${{ fromJSON(steps.get-behavior.outputs.result).exitCode || 0 }} | |
get-pending-integration-result: | |
needs: pre_check | |
if: needs.pre_check.outputs.should_run == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get integration-test-result check | |
id: attach-check | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const head_sha = context.eventName === 'pull_request' ? | |
context.payload.pull_request.head.sha : context.sha | |
const runs = await github.paginate(github.rest.checks.listForRef, { | |
...context.repo, | |
ref: head_sha, | |
check_name: "integration-test-result", | |
}) | |
core.debug('integration-test-result check runs: ${JSON.stringify(runs, null, 2)}') | |
const run = runs | |
.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at))[0] | |
console.log('Latest integration-test-result run', run && run.html_url) | |
const getRunUrl = runId => `https://github.com/${context.repo.owner}/${context.repo.repo}/runs/${runId}` | |
const currentWorkflowRunUrl = getRunUrl(context.runId) | |
if (!run || run.status !== 'queued' || (run.output.summary && !run.output.summary.includes(currentWorkflowRunUrl))) { | |
if (run && run.output.summary) { | |
console.log(`Latest integration-test-result check found attached to other workflow run: ${run.output.summary}`) | |
} | |
core.setFailed(`Latest integration-test-result status not queued (status: ${run ? run.status : 'null'})`) | |
return | |
} | |
const res = await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: run.id, | |
output: { | |
title: 'Integration Test Aggregate Result', | |
summary: `Synthetic check capturing the result of the <a href="${currentWorkflowRunUrl}">integration-test workflow run</a>`, | |
}, | |
}) | |
console.log(`Attached integration-test-result check to this workflow run`) | |
return run.id | |
outputs: | |
run_id: ${{ steps.attach-check.outputs.result }} | |
set-integration-result-in-progress: | |
needs: | |
- get-pending-integration-result | |
runs-on: ubuntu-latest | |
steps: | |
- name: Update integration-test-result check to in-progress | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const runId = "${{ needs.get-pending-integration-result.outputs.run_id }}"; | |
const res = await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: runId, | |
status: "in_progress", | |
}) | |
core.debug(`Check update response: ${JSON.stringify(res, null, 2)}`) | |
console.log(`Updated check ${runId} to in-progress`) | |
finalize-integration-result: | |
needs: | |
- pre_check | |
- matrix-test | |
- standalone-test | |
- get-pending-integration-result | |
if: (needs.pre_check.outputs.should_run == 'true' && (success() || failure() || cancelled())) || needs.pre_check.outputs.previous_success == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check job results | |
id: check-result | |
shell: bash | |
run: | | |
cat <<EOF | |
needs ${{ toJSON(needs) }} | |
EOF | |
[ "${{ needs.pre_check.outputs.previous_success }}" = "true" ] && exit 0 | |
[ "${{ needs.matrix-test.result }}" = "success" ] || exit 1 | |
[ "${{ needs.standalone-test.result }}" = "success" ] || exit 1 | |
- name: Publish integration-test-result | |
if: always() | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const runId = "${{ needs.get-pending-integration-result.outputs.run_id }}"; | |
const conclusion = "${{ steps.check-result.outcome }}" | |
const res = await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: runId, | |
conclusion, | |
}) | |
core.debug('Check update response: ${JSON.stringify(res, null, 2)}') | |
console.log(`Updated check ${runId} to ${conclusion}`) |