summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2018-07-19 14:48:47 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2018-07-19 15:11:43 -0700
commit499632924c52acda9f36bcf81cb2a8a6ef1c2781 (patch)
tree049083bc5505eddb78389b761672d7eccc904d48
parent5d7e3e24e565afffe2bc9db5029286b167f039ed (diff)
downloadqtlocation-mapboxgl-upstream/alternate-target-branch-detection.tar.gz
[build] Attempt to determine a likely base branch without a PRupstream/alternate-target-branch-detection
Walk backward through the history (maximum of 10 commits) until finding a commit on either master or release-*; assume that's the base branch.
-rwxr-xr-xscripts/environment.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/scripts/environment.js b/scripts/environment.js
index b071a484e7..9777377f19 100755
--- a/scripts/environment.js
+++ b/scripts/environment.js
@@ -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;
+ }
+ }
}