From 870d7fda4d5b65d9a4993f35322678bc6f50767c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 19 Jul 2018 14:48:47 -0700 Subject: [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. --- scripts/environment.js | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; + } + } } -- cgit v1.2.1