Skip to content

Commit

Permalink
[actions] fix publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 10, 2022
1 parent 35f6403 commit 59af733
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
11 changes: 11 additions & 0 deletions .eslintrc
Expand Up @@ -67,5 +67,16 @@
"no-console": 0,
},
},
{
"files": ".github/workflows/*.js",
"parserOptions": {
"ecmaVersion": 2019,
},
"rules": {
"camelcase": 0,
"no-console": 0,
"no-restricted-syntax": 0,
},
},
],
}
35 changes: 2 additions & 33 deletions .github/workflows/npm-publish.yml
Expand Up @@ -48,39 +48,8 @@ jobs:
result-encoding: string
retries: 3
script: |
const ref = context.payload.inputs.tag;
console.log(`Checking status checks for ${ref}`);
const { owner, repo } = context.repo;
const { default_branch: branch } = context.payload.repository;
const branch = github.rest.repos.getBranch({ owner, repo, branch });
const checkSuites = await github.rest.checks.listSuitesForRef({ owner, repo, ref });
if (checkSuites.some(({ status }) => 'completed')) {
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
}
const { data: { check_runs: checkRuns } } = await Promise.all(
(await branch).data.protection.required_status_checks.checks.map(({ context }) => (
github.rest.checks.listForRef({
owner,
repo,
ref,
check_name: context
})
)
)
checkRuns.forEach(({ name, status, conclusion }) => {
if (status !== 'completed' || conclusion !== 'success') {
console.log(`${name} check failed`);
core.setFailed(`Required status check ${name} did not succeed`);
}
console.log(`${name} check passed`);
});
const script = require('./publish');
console.log(await script({ github, context, core }));
publish:
needs: [check-status]
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/publish.js
@@ -0,0 +1,41 @@
'use strict';

module.exports = async function publish({ github, context, core }) {
const ref = context.payload.inputs.tag;

console.log(`Checking status checks for ${ref}`);

const { owner, repo } = context.repo;
const { default_branch: branch } = context.payload.repository;

const branchData = github.rest.repos.getBranch({ owner, repo, branch });

const { data: { check_suites: checkSuites } } = await github.rest.checks.listSuitesForRef({ owner, repo, ref });

if (checkSuites.some(({ status }) => status === 'completed')) {
core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress`);
}

const result = await Promise.all(
(await branchData).data.protection.required_status_checks.checks.map(({ context: check_name }) => (
github.rest.checks.listForRef({
owner,
repo,
ref,
check_name,
})
)),
);

console.log(result);

const { data: { check_runs: checkRuns } } = result;

checkRuns.forEach(({ name, status, conclusion }) => {
if (status !== 'completed' || conclusion !== 'success') {
console.log(`${name} check failed`);
core.setFailed(`Required status check ${name} did not succeed`);
}
console.log(`${name} check passed`);
});
};

0 comments on commit 59af733

Please sign in to comment.