-
Notifications
You must be signed in to change notification settings - Fork 208
95 lines (89 loc) · 3.89 KB
/
manage-integration-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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