Skip to content

Commit

Permalink
Fix wrong branch for pull_request builds
Browse files Browse the repository at this point in the history
Signed-off-by: Timothy Johnson <timothy.johnson@broadcom.com>
  • Loading branch information
t1m0thyj committed May 23, 2023
1 parent f1700ea commit 0864c3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion dist/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## `1.0.1`

* Fixed wrong branch detected for GitHub Actions `pull_request` builds
* Fixed Git tags being matched that do not conform to semver

## `1.0.0`
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,15 @@ export async function getLastCommitMessage(context: IContext): Promise<string |
* @returns CI environment for the `context.ci` property
*/
async function loadCiEnv(): Promise<any> {
const envCi = require("env-ci")();
let envCi = require("env-ci")();
if (envCi.service == null) {
throw new Error(`Unsupported CI service detected: ${envCi.service}`);
}

if (envCi.isPr) {
// For PR builds, map `branch` (base) to `baseBranch` and `prBranch` (head) to `branch`
envCi = { ...envCi, baseBranch: envCi.branch, branch: envCi.prBranch, prBranch: undefined };
}
if (envCi.branch == null) {
const cmdOutput = await exec.getExecOutput("git", ["rev-parse", "--abbrev-ref", "HEAD"]);
envCi.branch = cmdOutput.stdout.trim();
Expand Down

0 comments on commit 0864c3a

Please sign in to comment.