Skip to content

Commit 0d5fd30

Browse files
authored
Merge branch 'master' into dependabot/github_actions/gh-actions-packages-5b54a54548
2 parents 04298c6 + ae89815 commit 0d5fd30

File tree

3 files changed

+109
-28
lines changed

3 files changed

+109
-28
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// This script runs in the context of `actions/github-script` from GitHub Action workflow.
2+
// It checks the conclusion for check suites of a commit (SHA) from a specifc Github App.
3+
// It fails the workflow if any of the check suites are not 'success', 'neutral' or 'skipped'.
4+
5+
// API:
6+
// - https://docs.github.com/en/rest/checks/suites?apiVersion=2022-11-28#list-check-suites-for-a-git-reference
7+
// - https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-in-a-check-suite
8+
module.exports = async ({github, context, core}) => {
9+
const checkSuites = await github.paginate(github.rest.checks.listSuitesForRef, {
10+
owner: context.repo.owner,
11+
repo: context.repo.repo,
12+
ref: context.sha,
13+
app_id: parseInt(process.env.APP_ID),
14+
per_page: 100
15+
});
16+
17+
console.log(`Found ${checkSuites.length} check suites`);
18+
19+
const failedSuites = checkSuites.filter(suite =>
20+
suite.status === 'completed' &&
21+
suite.conclusion !== 'success' &&
22+
suite.conclusion !== 'neutral' &&
23+
suite.conclusion !== 'skipped'
24+
);
25+
26+
if (failedSuites.length > 0) {
27+
console.log(`Found ${failedSuites.length} failed check suites`);
28+
29+
const failedChecksPromises = failedSuites.map(async suite => {
30+
const checkRuns = await github.paginate(github.rest.checks.listForSuite, {
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
check_suite_id: suite.id,
34+
per_page: 100
35+
});
36+
37+
return checkRuns.filter(check =>
38+
check.status === 'completed' &&
39+
check.conclusion !== 'success' &&
40+
check.conclusion !== 'neutral' &&
41+
check.conclusion !== 'skipped'
42+
);
43+
});
44+
45+
const failedChecksArrays = await Promise.all(failedChecksPromises);
46+
const failedChecks = failedChecksArrays.flat();
47+
48+
console.log(`Found a total of ${failedChecks.length} failed check runs`);
49+
50+
failedChecks.forEach(failedCheck => {
51+
const { name, conclusion, html_url } = failedCheck;
52+
const message = JSON.stringify({ name, conclusion, url: html_url }, null, 2);
53+
54+
core.error(message);
55+
});
56+
57+
// Set job failure
58+
core.setFailed(`Found ${failedSuites.length} failed check suites`);
59+
}
60+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// This script runs in the context of `actions/github-script` from GitHub Action workflow.
2+
// It checks the commit status of a commit (SHA).
3+
// It fails the workflow if the combined status is not 'success'.
4+
5+
// API:
6+
// - https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference
7+
module.exports = async ({github, context, core}) => {
8+
const { data: combinedStatus } = await github.rest.repos.getCombinedStatusForRef({
9+
owner: context.repo.owner,
10+
repo: context.repo.repo,
11+
ref: context.sha
12+
});
13+
14+
if (combinedStatus.state !== 'success') {
15+
const allStatuses = await github.paginate(github.rest.repos.listCommitStatusesForRef, {
16+
owner: context.repo.owner,
17+
repo: context.repo.repo,
18+
ref: context.sha,
19+
per_page: 100
20+
});
21+
22+
console.log(`Found ${allStatuses.length} commit statuses`);
23+
24+
const failedStatuses = allStatuses.filter(s => s.state !== 'success');
25+
26+
if (failedStatuses.length > 0) {
27+
console.log(`Found ${failedStatuses.length} failed commit statuses`);
28+
failedStatuses.forEach(failedStatus => {
29+
const message = JSON.stringify({
30+
context: failedStatus.context,
31+
state: failedStatus.state,
32+
url: failedStatus.target_url
33+
}, null, 2);
34+
35+
core.error(message);
36+
});
37+
}
38+
39+
core.setFailed(`Commit status is ${combinedStatus.state} with ${failedStatuses.length} failed checks`);
40+
}
41+
}

.github/workflows/publish.yml

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -105,46 +105,26 @@ jobs:
105105
console.log(`Found open milestone ${process.env.GEM_VERSION} (ID: ${versionMilestone.number})`);
106106
107107
# Check if the commit has passed all Github checks
108-
# API: https://docs.github.com/en/rest/checks/runs?apiVersion=2022-11-28#list-check-runs-for-a-git-reference
109108
- name: Verify check runs
110109
continue-on-error: ${{ inputs.force }}
110+
env:
111+
APP_ID: 15368 # Github Actions app ID
111112
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
112113
with:
114+
retries: 3
113115
script: |
114-
const checkRuns = await github.paginate(github.rest.checks.listForRef, {
115-
owner: context.repo.owner,
116-
repo: context.repo.repo,
117-
ref: context.sha,
118-
per_page: 100
119-
});
120-
121-
const failedChecks = checkRuns.filter(check =>
122-
check.status === 'completed' &&
123-
check.conclusion !== 'success' &&
124-
check.conclusion !== 'skipped'
125-
);
126-
127-
if (failedChecks.length > 0) {
128-
const failedNames = failedChecks.map(c => c.name).join(', ');
129-
core.setFailed(`Check runs failed: ${failedNames}`);
130-
}
116+
const script = require('./.github/scripts/publish/verify_check_runs.js')
117+
await script({github, context, core})
131118
132119
# Check if the commit has passed external CI checks
133-
# API: https://docs.github.com/en/rest/commits/statuses?apiVersion=2022-11-28#get-the-combined-status-for-a-specific-reference
134120
- name: Verify commit status
135121
continue-on-error: ${{ inputs.force }}
136122
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
137123
with:
124+
retries: 3
138125
script: |
139-
const { data: status } = await github.rest.repos.getCombinedStatusForRef({
140-
owner: context.repo.owner,
141-
repo: context.repo.repo,
142-
ref: context.sha
143-
});
144-
145-
if (status.state !== 'success') {
146-
core.setFailed(`Commit status is ${status.state}`);
147-
}
126+
const script = require('./.github/scripts/publish/verify_commit_status.js')
127+
await script({github, context, core})
148128
149129
# Check if the commit has all the checks passed
150130
- name: Verify deferred commit data

0 commit comments

Comments
 (0)