From c3025e2dfacf610addcf725c113635a17895ecc2 Mon Sep 17 00:00:00 2001 From: Jacob Lauritzen Date: Sat, 26 Sep 2020 14:13:48 +0200 Subject: [PATCH 1/3] Get head branch from PRs --- index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3c26c57..a591ca5 100644 --- a/index.js +++ b/index.js @@ -39,9 +39,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) { + console.log('Is 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', From 044466b91b03b788e98f56379bf3fd2c7b2d6f1b Mon Sep 17 00:00:00 2001 From: Jacob Lauritzen Date: Sat, 26 Sep 2020 14:29:49 +0200 Subject: [PATCH 2/3] Fetch local branches --- index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index.js b/index.js index a591ca5..b211ff7 100644 --- a/index.js +++ b/index.js @@ -54,6 +54,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]) From f4692d2d0732417b596dd052265ec374459ac0c1 Mon Sep 17 00:00:00 2001 From: Jacob Lauritzen Date: Sat, 26 Sep 2020 14:34:59 +0200 Subject: [PATCH 3/3] Remove log --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index b211ff7..fed2a48 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,7 @@ Toolkit.run(async tools => { let currentBranch = /refs\/[a-zA-Z]+\/(.*)/.exec(process.env.GITHUB_REF)[1] if (process.env.GITHUB_HEAD_REF) { - console.log('Is pull request'); + // Comes from a pull request currentBranch = process.env.GITHUB_HEAD_REF; } console.log('currentBranch:', currentBranch)