From 181c68fabee4b948056b9c49274d0e3c6e41f5f5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 17 Nov 2022 14:11:57 -0800 Subject: [PATCH] [actions] fix publish script --- .github/workflows/npm-publish.yml | 40 ++++++++++++++++++++++++++++-- .github/workflows/publish.js | 41 ------------------------------- 2 files changed, 38 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/publish.js diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 5cbe8f7a46..2b89b601b7 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -48,8 +48,44 @@ jobs: result-encoding: string retries: 3 script: | - const script = require('./.github/workflows/publish'); - console.log(await script({ github, context, core })); + console.log(process.cwd()); + 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 }); + + const pending = checkSuites.filter(({ status }) => status !== 'completed') + + if (pending.length > 0) { + core.setFailed(`Some workflows for ${context.payload.inputs.tag} are still in-progress: ${JSON.stringify(pending)}`); + } + + 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, + }) + )), + ); + + const checkRuns = result.flatMap(({ data: { check_runs } }) => check_runs); + + 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`); + }); publish: needs: [check-status] diff --git a/.github/workflows/publish.js b/.github/workflows/publish.js deleted file mode 100644 index 005277abc7..0000000000 --- a/.github/workflows/publish.js +++ /dev/null @@ -1,41 +0,0 @@ -'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`); - }); -};