[build] Attempt to determine a likely base branch without a PR

Walk backward through the history (maximum of 10 commits) until finding a commit on either master or release-*; assume that's the base branch.
This commit is contained in:
John Firebaugh
2018-07-19 14:48:47 -07:00
parent 3821f74079
commit 870d7fda4d

View File

@@ -21,4 +21,15 @@ if (pr) {
console.log(`export CIRCLE_TARGET_BRANCH=${base}`);
console.log(`export CIRCLE_MERGE_BASE=${mergeBase}`);
});
} else {
const head = process.env['CIRCLE_SHA1'];
for (const sha of execSync(`git rev-list --max-count=10 ${head}`).toString().trim().split('\n')) {
const base = execSync(`git branch -r --contains ${sha} origin/master origin/release-*`).toString().trim().replace(/^origin\//, '');
if (base) {
const mergeBase = execSync(`git merge-base origin/${base} ${head}`).toString().trim();
console.log(`export CIRCLE_TARGET_BRANCH=${base}`);
console.log(`export CIRCLE_MERGE_BASE=${mergeBase}`);
break;
}
}
}