From 59af7334feb1e991ab2ebcf5962979320a6e14cb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 10 Nov 2022 13:01:38 -0500 Subject: [PATCH] [actions] fix publish script --- .eslintrc | 11 +++++++++ .github/workflows/npm-publish.yml | 35 ++------------------------ .github/workflows/publish.js | 41 +++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/publish.js diff --git a/.eslintrc b/.eslintrc index 653bc9f651..4991f200f2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -67,5 +67,16 @@ "no-console": 0, }, }, + { + "files": ".github/workflows/*.js", + "parserOptions": { + "ecmaVersion": 2019, + }, + "rules": { + "camelcase": 0, + "no-console": 0, + "no-restricted-syntax": 0, + }, + }, ], } diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 24055688fd..8d1ff32dbd 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -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] diff --git a/.github/workflows/publish.js b/.github/workflows/publish.js new file mode 100644 index 0000000000..005277abc7 --- /dev/null +++ b/.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`); + }); +};