From d3c58ea48c037eedbae8209f72a1aaca36edfb19 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Mon, 3 Dec 2018 13:28:10 -0800 Subject: [PATCH] chore: move getCurrentBranch to a util file (#15921) * chore: move getCurrentBranch to a util file * fix import --- script/lib/utils.js | 20 ++++++++++++++++++++ script/prepare-release.js | 30 ++++++++---------------------- script/publish-to-npm.js | 20 +------------------- script/release-artifact-cleanup.js | 13 +------------ 4 files changed, 30 insertions(+), 53 deletions(-) diff --git a/script/lib/utils.js b/script/lib/utils.js index e5c864b0de9d..51d7db4439af 100644 --- a/script/lib/utils.js +++ b/script/lib/utils.js @@ -1,7 +1,12 @@ const OUT_DIR = process.env.ELECTRON_OUT_DIR || 'Debug' +const { GitProcess } = require('dugite') const path = require('path') +require('colors') +const pass = '\u2713'.green +const fail = '\u2717'.red + function getElectronExec () { switch (process.platform) { case 'darwin': @@ -19,7 +24,22 @@ 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 + } else { + const error = GitProcess.parseError(branchDetails.stderr) + console.log(`${fail} couldn't get details current branch: `, error) + process.exit(1) + } +} + module.exports = { + getCurrentBranch, getElectronExec, getAbsoluteElectronExec, OUT_DIR diff --git a/script/prepare-release.js b/script/prepare-release.js index 917f90f55543..408f765fd3eb 100755 --- a/script/prepare-release.js +++ b/script/prepare-release.js @@ -1,22 +1,25 @@ #!/usr/bin/env node if (!process.env.CI) require('dotenv-safe').load() -require('colors') const args = require('minimist')(process.argv.slice(2), { boolean: ['automaticRelease', 'notesOnly', 'stable'] }) const ciReleaseBuild = require('./ci-release-build') -const { execSync } = require('child_process') -const fail = '\u2717'.red -const { GitProcess } = require('dugite') const GitHub = require('github') -const pass = '\u2713'.green +const { execSync } = require('child_process') +const { GitProcess } = require('dugite') + const path = require('path') const readline = require('readline') const releaseNotesGenerator = require('./release-notes/index.js') +const { getCurrentBranch } = require('./lib/utils.js') const versionType = args._[0] const targetRepo = versionType === 'nightly' ? 'nightlies' : 'electron' +require('colors') +const pass = '\u2713'.green +const fail = '\u2717'.red + // TODO (future) automatically determine version based on conventional commits // via conventional-recommended-bump @@ -53,23 +56,6 @@ async function getNewVersion (dryRun) { } } -async function getCurrentBranch (gitDir) { - console.log(`Determining current git branch`) - 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} Successfully determined current git branch is ` + - `${currentBranch}`) - return currentBranch - } else { - const error = GitProcess.parseError(branchDetails.stderr) - console.log(`${fail} Could not get details for the current branch, - error was ${branchDetails.stderr}`, error) - process.exit(1) - } -} - async function getReleaseNotes (currentBranch) { if (versionType === 'nightly') { return 'Nightlies do not get release notes, please compare tags for info' diff --git a/script/publish-to-npm.js b/script/publish-to-npm.js index 3667d3bde626..867a267c3ca5 100644 --- a/script/publish-to-npm.js +++ b/script/publish-to-npm.js @@ -3,7 +3,7 @@ const fs = require('fs') const path = require('path') const childProcess = require('child_process') const GitHubApi = require('github') -const { GitProcess } = require('dugite') +const { getCurrentBranch } = require('./lib/utils.js') const request = require('request') const semver = require('semver') const rootPackageJson = require('../package.json') @@ -162,21 +162,3 @@ new Promise((resolve, reject) => { console.error(`Error: ${err}`) process.exit(1) }) - -async function getCurrentBranch () { - const gitDir = path.resolve(__dirname, '..') - console.log(`Determining current git branch`) - 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(`Successfully determined current git branch is ` + - `${currentBranch}`) - return currentBranch - } else { - const error = GitProcess.parseError(branchDetails.stderr) - console.log(`Could not get details for the current branch, - error was ${branchDetails.stderr}`, error) - process.exit(1) - } -} diff --git a/script/release-artifact-cleanup.js b/script/release-artifact-cleanup.js index c1dea28dcc94..b84e99905f6d 100755 --- a/script/release-artifact-cleanup.js +++ b/script/release-artifact-cleanup.js @@ -10,6 +10,7 @@ const args = require('minimist')(process.argv.slice(2), { }) const { execSync } = require('child_process') const { GitProcess } = require('dugite') +const { getCurrentBranch } = require('./lib/utils.js') const GitHub = require('github') const path = require('path') @@ -27,18 +28,6 @@ function getLastBumpCommit (tag) { return JSON.parse(data) } -async function getCurrentBranch (gitDir) { - const gitArgs = ['rev-parse', '--abbrev-ref', 'HEAD'] - const branchDetails = await GitProcess.exec(gitArgs, gitDir) - if (branchDetails.exitCode === 0) { - return branchDetails.stdout.trim() - } - - const error = GitProcess.parseError(branchDetails.stderr) - console.error(`${fail} couldn't get current branch: `, error) - process.exit(1) -} - async function revertBumpCommit (tag) { const branch = await getCurrentBranch() const commitToRevert = getLastBumpCommit(tag).hash