build: get current release branch from commit (#18810)

When we blast off again, we check out a commit so the current branch ends up being incorrect and is HEAD rather than X-Y-Z. This therefore no longer just runs git rev-parse --abbrev-ref HEAD; it instead checks to ensure that the result of that call matches the release branch pattern. If it doesn't, it fetches the containing branch for the commit.

Since we only ever blast off from bump commits, we can safely assume that only one release branch will ever contain the bump commit and therefore be the one we want to use when tagging the release on npm.
This commit is contained in:
Shelley Vohr 2019-06-16 20:56:43 -07:00 committed by GitHub
parent 77d5e0c1ef
commit 632bbf948d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,20 +25,27 @@ function getAbsoluteElectronExec () {
return path.resolve(__dirname, '../../..', getElectronExec())
}
async function getCurrentBranch (gitDir) {
const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD']
const branchDetails = await GitProcess.exec(gitArgs, gitDir)
if (branchDetails.exitCode === 0) {
const currentBranch = branchDetails.stdout.trim()
console.log(`${pass} current git branch is: ${currentBranch}`)
return currentBranch
async function handleGitCall (args, gitDir) {
const details = await GitProcess.exec(args, gitDir)
if (details.exitCode === 0) {
return details.stdout.trim()
} else {
const error = GitProcess.parseError(branchDetails.stderr)
console.log(`${fail} couldn't get details current branch: `, error)
const error = GitProcess.parseError(details.stderr)
console.log(`${fail} couldn't parse git process call: `, error)
process.exit(1)
}
}
async function getCurrentBranch (gitDir) {
let branch = await handleGitCall(['rev-parse', '--abbrev-ref', 'HEAD'], gitDir)
if (!branch.match(/[0-9]+-[0-9]+-x/)) {
const lastCommit = await handleGitCall(['rev-parse', 'HEAD'], gitDir)
const branches = (await handleGitCall(['branch', '--contains', lastCommit], gitDir)).split('\n')
branch = branches.filter(b => b.match(/[0-9]+-[0-9]+-x/))[0].trim()
}
return branch
}
module.exports = {
getCurrentBranch,
getElectronExec,