diff --git a/index.js b/index.js index c702a27..8d688d6 100644 --- a/index.js +++ b/index.js @@ -40,9 +40,12 @@ Toolkit.run(async tools => { await tools.runInWorkspace('git', ['config', 'user.name', `"${process.env.GITHUB_USER || 'Automated Version Bump'}"`]) await tools.runInWorkspace('git', ['config', 'user.email', `"${process.env.GITHUB_EMAIL || 'gh-action-bump-version@users.noreply.github.com'}"`]) - const currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1] + let currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1] + if (process.env.GITHUB_HEAD_REF) { + // Comes from a pull request + currentBranch = process.env.GITHUB_HEAD_REF; + } console.log('currentBranch:', currentBranch) - // do it in the current checked out github branch (DETACHED HEAD) // important for further usage of the package.json version await tools.runInWorkspace('npm', @@ -52,6 +55,8 @@ Toolkit.run(async tools => { await tools.runInWorkspace('git', ['commit', '-a', '-m', `ci: ${commitMessage} ${newVersion}`]) // now go to the actual branch to perform the same versioning + // First fetch to get updated local version of branch + await tools.runInWorkspace('git', ['fetch']) await tools.runInWorkspace('git', ['checkout', currentBranch]) await tools.runInWorkspace('npm', ['version', '--allow-same-version=true', '--git-tag-version=false', current])