const VALID_REF_PREFIX = 'refs/heads/';
...
function getBranchRef(isProd = false) {
let branchRef = 'origin/master';
if (isProd) {
return branchRef;
}
/**
* When the workflow is invoked from manual flow, the branch name
* is in GITHUB_REF, otherwise, we have to look into GITHUB_BASE_REF
*/
if (GITHUB_REF.startsWith(VALID_REF_PREFIX)) {
// coming from a manual workflow trigger
branchName = `origin/${GITHUB_REF.replace(VALID_REF_PREFIX, '')}`;
} else {
// coming from a PR
branchRef = `origin/${GITHUB_HEAD_REF}`;
}
return branchRef;
}