Skip to content

Manage integration check #41

Manage integration check

Manage integration check #41

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@v6
id: create-check
if: ${{ github.event.action == 'requested' || github.event.action == 'in_progress' }}
with:
script: |
const head_sha = context.payload.workflow_run.head_sha;
const check = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
status: "in_progress",
output: {
title: "Integration Test Aggregate Result",
summary: `Synthetic check capturing the result of the <a href="${context.workflow_run.html_url}">integration-test workflow run</a>`,
}
});
return check.data.id;
update-check:
runs-on: ubuntu-latest
steps:
- name: Update check result
uses: actions/github-script@v6
if: ${{ github.event.action == 'completed' }}
with:
script: |
// Update the check run
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",
})
core.debug(`integration-test-result check runs: ${JSON.stringify(runs, null, 2)}`);
const checkId = runs.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at))[0];
if (!checkId) {
core.setFailed(`No integration-test-result check found for commit ${head_sha}`);
return;
}
await github.checks.update({
...context.repo
check_run_id: checkId,
status: "completed",
conclusion: context.payload.workflow_run.conclusion,
});