Manage integration check #341
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: Manage integration check | |
on: | |
workflow_run: | |
workflows: ['Integration tests'] | |
jobs: | |
create-check: | |
runs-on: ubuntu-latest | |
outputs: | |
check_id: ${{ steps.create-check.outputs.result }} | |
steps: | |
- name: Create check | |
uses: actions/github-script@v7 | |
id: create-check | |
if: ${{ github.event.action == 'requested' || github.event.action == 'in_progress' }} | |
with: | |
script: | | |
const external_id = context.payload.workflow_run.html_url + "-" + context.payload.workflow_run.run_attempt; | |
const head_sha = context.payload.workflow_run.head_sha; | |
const runs = await github.paginate(github.rest.checks.listForRef, { | |
...context.repo, | |
ref: head_sha, | |
check_name: "integration-test-result", | |
external_id, | |
}) | |
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`); | |
const filtRuns = runs.filter(run => run.external_id === external_id); | |
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at)); | |
const run = descRuns[0]; | |
if (run) { | |
// Check already exists. | |
return run.id; | |
} | |
const check = await github.rest.checks.create({ | |
...context.repo, | |
head_sha, | |
name: "integration-test-result", | |
status: "in_progress", | |
external_id, | |
output: { | |
title: "Integration Test Aggregate Result", | |
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a> (attempt ${context.payload.workflow_run.run_attempt})`, | |
} | |
}); | |
return check.data.id; | |
update-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Update check result | |
uses: actions/github-script@v7 | |
if: ${{ github.event.action == 'completed' }} | |
with: | |
result-encoding: string | |
script: | | |
// Update the check run | |
const external_id = context.payload.workflow_run.html_url + "-" + context.payload.workflow_run.run_attempt; | |
const head_sha = context.payload.workflow_run.head_sha; | |
const runs = await github.paginate(github.rest.checks.listForRef, { | |
...context.repo, | |
ref: head_sha, | |
check_name: "integration-test-result", | |
external_id, | |
}) | |
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`); | |
const filtRuns = runs.filter(run => run.status !== 'completed' && run.external_id === external_id); | |
const descRuns = filtRuns.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at)); | |
const run = descRuns[0]; | |
if (!run) { | |
const check = await github.rest.checks.create({ | |
...context.repo, | |
head_sha, | |
name: "integration-test-result", | |
status: "completed", | |
conclusion: context.payload.workflow_run.conclusion, | |
external_id, | |
output: { | |
title: "Integration Test Aggregate Result", | |
summary: `Synthetic check capturing the result of the <a href="${context.payload.workflow_run.html_url}">integration-test workflow run</a> (attempt ${context.payload.workflow_run.run_attempt})`, | |
} | |
}); | |
return; | |
} | |
console.log('Latest integration-test-result check run:', run.html_url) | |
await github.rest.checks.update({ | |
...context.repo, | |
check_run_id: run.id, | |
status: "completed", | |
conclusion: context.payload.workflow_run.conclusion, | |
}); | |
return run.id |