From 78675447a4f054b0c7fa5254f836f566865fbdf1 Mon Sep 17 00:00:00 2001 From: phips28 Date: Tue, 31 May 2022 20:34:44 +0200 Subject: [PATCH] fix #166 --- index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8f122ab..cea1558 100644 --- a/index.js +++ b/index.js @@ -141,7 +141,8 @@ const workspace = process.env.GITHUB_WORKSPACE; `"${process.env.GITHUB_EMAIL || 'gh-action-bump-version@users.noreply.github.com'}"`, ]); - let currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1]; + const refsRegExResult = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF); + let currentBranch = refsRegExResult ? refsRegExResult[1] : undefined; let isPullRequest = false; if (process.env.GITHUB_HEAD_REF) { // Comes from a pull request @@ -153,6 +154,12 @@ const workspace = process.env.GITHUB_WORKSPACE; currentBranch = process.env['INPUT_TARGET-BRANCH']; } console.log('currentBranch:', currentBranch); + + if (!currentBranch) { + exitFailure('No branch found'); + return; + } + // do it in the current checked out github branch (DETACHED HEAD) // important for further usage of the package.json version await runInWorkspace('npm', ['version', '--allow-same-version=true', '--git-tag-version=false', current]);