diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-19 14:48:47 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-07-23 11:21:51 -0700 |
commit | 870d7fda4d5b65d9a4993f35322678bc6f50767c (patch) | |
tree | 433d721e4010480b8177d333f29b8390d2f5e7d1 /scripts | |
parent | 3821f74079f88b6a5b3b0ea210fe529132a3494f (diff) | |
download | qtlocation-mapboxgl-870d7fda4d5b65d9a4993f35322678bc6f50767c.tar.gz |
[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.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/environment.js | 11 |
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; + } + } } |