From b3615798ace53b983251a57593b328e707a8f419 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 18 Mar 2022 17:58:45 +0100 Subject: [PATCH] exp --- .github/workflows/publish-release.js | 37 ++++++++++------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish-release.js b/.github/workflows/publish-release.js index 9f299dc..fe4cfee 100644 --- a/.github/workflows/publish-release.js +++ b/.github/workflows/publish-release.js @@ -19,20 +19,14 @@ module.exports = /*async*/ ({github, context, core}) => { console.log(`Validate version '${version}'.`) // git branch must exist - try { - const ref = await restapi.git.getRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: 'heads/release/' + version - }) - if (ref == null) { - core.setFailed(`Could not find branch 'release/${version}'.`) - return - } - } - catch (error) { + const refs = await restapi.git.listMatchingRefs({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/release/${version}` + }) + if (firstOrDefault(refs, (x) => x.ref == `heads/release/${version}`) == null) { core.setFailed(`Could not find branch 'release/${version}'.`) - return + return } console.log(`Found branch 'release/${version}'.`) @@ -72,20 +66,15 @@ module.exports = /*async*/ ({github, context, core}) => { console.log(`Found yet-unpublished GitHub Release for tag '${tag}'.`) // tag must not exist - try { - const refs = await restapi.git.listMatchingRefs({ - owner: context.repo.owner, - repo: context.repo.repo, - //ref: 'tags/' + tag - ref: 'tags/wip' - }) - console.log(refs) + const refs = await restapi.git.listMatchingRefs({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${tag}` + }) + if (firstOrDefault(refs.data, (x) => x.ref == `tags/${tag}`) != null) { core.setFailed(`Tag '${tag}' already exists.`) return } - catch (error) { - // this is expected - the tag should not exist - } console.log(`Verified that tag '${tag}' does not exist yet.`) console.log('Release is valid.')