Skip to content

Commit 069314a

Browse files
committed
[actions] fix publish script
1 parent d350a48 commit 069314a

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

.github/workflows/npm-publish.yml

+38-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,44 @@ jobs:
4848
result-encoding: string
4949
retries: 3
5050
script: |
51-
const script = require('./.github/workflows/publish');
52-
console.log(await script({ github, context, core }));
51+
console.log(process.cwd());
52+
const ref = context.payload.inputs.tag;
53+
54+
console.log(`Checking status checks for ${ref}`);
55+
56+
const { owner, repo } = context.repo;
57+
const { default_branch: branch } = context.payload.repository;
58+
59+
const branchData = github.rest.repos.getBranch({ owner, repo, branch });
60+
61+
const { data: { check_suites: checkSuites } } = await github.rest.checks.listSuitesForRef({ owner, repo, ref });
62+
63+
const pending = checkSuites.filter(({ status }) => status !== 'completed')
64+
65+
if (pending.length > 0) {
66+
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress: ${JSON.stringify(pending))`);
67+
}
68+
69+
const result = await Promise.all(
70+
(await branchData).data.protection.required_status_checks.checks.map(({ context: check_name }) => (
71+
github.rest.checks.listForRef({
72+
owner,
73+
repo,
74+
ref,
75+
check_name,
76+
})
77+
)),
78+
);
79+
80+
const checkRuns = result.flatMap(({ data: { check_runs } }) => check_runs);
81+
82+
checkRuns.forEach(({ name, status, conclusion }) => {
83+
if (status !== 'completed' || conclusion !== 'success') {
84+
console.log(`${name} check failed`);
85+
core.setFailed(`Required status check ${name} did not succeed`);
86+
}
87+
console.log(`${name} check passed`);
88+
});
5389
5490
publish:
5591
needs: [check-status]

.github/workflows/publish.js

-41
This file was deleted.

0 commit comments

Comments
 (0)