Skip to content

Commit

Permalink
Use a manual check for integration-test-result
Browse files Browse the repository at this point in the history
  • Loading branch information
mhofman committed Sep 8, 2023
1 parent f468867 commit 8699214
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 14 deletions.
81 changes: 81 additions & 0 deletions .github/actions/get-latest-check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Get latest check
description: 'Get the latest integration-test-result check associated with commit'

inputs:
create-if-needed:
description: 'Create a new check if a a previous check is not suitable'
default: false

outputs:
run_id:
description: 'The id of the integration-test-result check'
value: ${{ steps.attach-check.outputs.result }}

runs:
using: composite
steps:
- name: Attach integration-test-result check
id: attach-check
uses: actions/github-script@v6
env:
CREATE_IF_NEEDED: "${{ inputs.create-if-needed }}"
with:
result-encoding: string
script: |
let createIfNeeded = process.env.CREATE_IF_NEEDED === 'true'
let runId;
const currentWorkflowRunUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
const head_sha = context.eventName === 'pull_request' ?
context.payload.pull_request.head.sha : context.sha
async function attachRun(run) {
console.log('Latest integration-test-result run', run && run.html_url)
if (!run) {
core.setFailed(`No integration-test-result check found for this commit (${head_sha})`)
return
}
if (run.output.summary) {
if (run.output.summary.includes(currentWorkflowRunUrl)) {
console.log('Latest integration-test-result already attached to this workflow run')
return run.id
} else {
core.setFailed(`Latest integration-test-result check (${run.html_url}) found attached to other workflow run: ${run.output.summary}`)
return
}
}
if (run.status !== 'queued') {
core.setFailed(`Latest integration-test-result check status not queued (${run.status})`)
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
}
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)}`)
runId = await attachRun(runs.sort((a, b) => Date.parse(b.started_at) - Date.parse(a.started_at))[0])
if (!runId && createIfNeeded) {
process.exitCode = 0
const res = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
})
core.debug('check create response: ${JSON.stringify(res, null, 2)}')
console.log('created integration-test-result', res.data.html_url)
runId = await attachRun(res.data)
}
return runId
55 changes: 53 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,52 @@ jobs:
sleep ${{ fromJSON(steps.get-behavior.outputs.result).sleep || 45 }}
exit ${{ fromJSON(steps.get-behavior.outputs.result).exitCode || 0 }}
integration-test-result:
set-integration-result-in-progress:
needs: pre_check
if: needs.pre_check.outputs.should_run == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Update integration-test-result check to in-progress
uses: actions/github-script@v6
with:
script: |
const runId = "${{ steps.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
if: (needs.pre_check.outputs.should_run == 'true' && (success() || failure() || cancelled())) || needs.pre_check.outputs.previous_success == 'true'
if: >-
always() &&
needs.pre_check.result == 'success' &&
needs.matrix-test.result != 'cancelled' &&
needs.standalone-test.result != 'cancelled' &&
(
needs.pre_check.outputs.should_run == 'true' ||
needs.pre_check.outputs.previous_success == 'true'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- id: get-pending-integration-result
uses: ./.github/actions/get-latest-check
with:
create-if-needed: true
- name: Check job results
id: check-result
shell: bash
run: |
cat <<EOF
Expand All @@ -112,3 +149,17 @@ jobs:
[ "${{ 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 = "${{ steps.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}`)
30 changes: 18 additions & 12 deletions .github/workflows/mergify-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ on:
merge_group:

jobs:
pre_check:
uses: ./.github/workflows/pre-check-integration.yml

wait-integration-pre-checks:
needs: pre_check
if: needs.pre_check.outputs.merge_requested == 'true'
runs-on: ubuntu-latest
steps:
- name: wait
shell: bash
run: |
cat <<EOF
needs ${{ toJSON(needs.pre_check.outputs) }}
EOF
sleep 15
- name: Create integration-test-result check
id: create-check
if: always()
uses: actions/github-script@v6
with:
script: |
const head_sha = context.eventName === 'pull_request' ?
context.payload.pull_request.head.sha : context.sha
const res = await github.rest.checks.create({
...context.repo,
head_sha,
name: "integration-test-result",
})
core.debug('check create response: ${JSON.stringify(res, null, 2)}')
console.log('created integration-test-result', res.data.html_url)
return res.data.id
outputs:
run_id: ${{ steps.create-check.outputs.result }}

merge-strategy:
runs-on: ubuntu-latest
Expand Down

0 comments on commit 8699214

Please sign in to comment.