632bbf948d
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.
54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
const { GitProcess } = require('dugite')
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const OUT_DIR = process.env.ELECTRON_OUT_DIR || 'Debug'
|
|
|
|
require('colors')
|
|
const pass = '\u2713'.green
|
|
const fail = '\u2717'.red
|
|
|
|
function getElectronExec () {
|
|
switch (process.platform) {
|
|
case 'darwin':
|
|
return `out/${OUT_DIR}/Electron.app/Contents/MacOS/Electron`
|
|
case 'win32':
|
|
return `out/${OUT_DIR}/electron.exe`
|
|
case 'linux':
|
|
return `out/${OUT_DIR}/electron`
|
|
default:
|
|
throw new Error('Unknown platform')
|
|
}
|
|
}
|
|
|
|
function getAbsoluteElectronExec () {
|
|
return path.resolve(__dirname, '../../..', getElectronExec())
|
|
}
|
|
|
|
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(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,
|
|
getAbsoluteElectronExec,
|
|
OUT_DIR
|
|
}
|