diff --git a/.github/workflows/publish-release.js b/.github/workflows/publish-release.js index 689bf1e..5713afb 100644 --- a/.github/workflows/publish-release.js +++ b/.github/workflows/publish-release.js @@ -16,6 +16,25 @@ module.exports = /*async*/ ({github, context, core}) => { const version = context.payload.inputs.version const tag = "v" + version 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: 'refs/heads/release' + version + }) + if (ref == null) { + core.setFailed(`Could not find branch 'release/${version}'.`) + return + } + } + catch (error) { + core.setFailed(`Could not find branch 'release/${version}'.`) + return + } + + // github release must exist and not be published yet try { const release = restapi.repos.getReleaseByTag({ owner: context.repo.owner, @@ -36,6 +55,8 @@ module.exports = /*async*/ ({github, context, core}) => { core.setFailed(`Could not find a GitHub release for tag '${tag}'.`) return } + + // tag must not exist try { const ref = await restapi.git.getRef({ owner: context.repo.owner, @@ -49,7 +70,7 @@ module.exports = /*async*/ ({github, context, core}) => { // this is expected - the tag should not exist } - console.log(`Found a yet-unpublished GitHub Release for tag '${tag}' which does not exist yet.`) + console.log(`Found branch 'release/${version}', a yet-unpublished GitHub Release for tag '${tag}' which does not exist yet.`) } function test() {