-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ea4dfa
commit b41c616
Showing
4 changed files
with
540 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use strict'; | ||
|
||
const semver = require('semver'); | ||
const CLI = require('../../lib/cli'); | ||
const Release = require('../../lib/release'); | ||
const Request = require('../../lib/request'); | ||
const { runPromise } = require('../../lib/run'); | ||
const yargs = require('yargs'); | ||
|
||
const PREPARE = 'prepare'; | ||
const PROMOTE = 'promote'; | ||
|
||
const releaseOptions = { | ||
prepare: { | ||
describe: 'Prepare a new release with the given version number', | ||
type: 'boolean' | ||
}, | ||
security: { | ||
describe: 'Prepare a new security release', | ||
type: 'boolean' | ||
} | ||
}; | ||
|
||
function builder(yargs) { | ||
return yargs | ||
.options(releaseOptions).positional('newVersion', { | ||
describe: 'Version number of the release to be created' | ||
}) | ||
.example('git node release 1.2.3', | ||
'Prepare a new release of Node.js tagged v1.2.3'); | ||
} | ||
|
||
function handler(argv) { | ||
if (argv.newVersion) { | ||
const newVersion = semver.coerce(argv.newVersion); | ||
if (semver.valid(newVersion)) { | ||
return release(PREPARE, argv); | ||
} | ||
} | ||
|
||
// If more than one action is provided or no valid action | ||
// is provided, show help. | ||
yargs.showHelp(); | ||
} | ||
|
||
function release(state, argv) { | ||
const logStream = process.stdout.isTTY ? process.stdout : process.stderr; | ||
const cli = new CLI(logStream); | ||
|
||
const req = new Request(); | ||
const dir = process.cwd(); | ||
|
||
return runPromise(main(state, argv, cli, req, dir)).catch((err) => { | ||
if (cli.spinner.enabled) { | ||
cli.spinner.fail(); | ||
} | ||
throw err; | ||
}); | ||
} | ||
|
||
module.exports = { | ||
command: 'release [newVersion|options]', | ||
describe: | ||
'Manage an in-progress release or start a new one.', | ||
builder, | ||
handler | ||
}; | ||
|
||
async function main(state, argv, cli, req, dir) { | ||
const release = new Release(state, argv, cli, req, dir); | ||
|
||
// TODO(codebytere): check if this command is being run by | ||
// someone on the Releasers team in GitHub before proceeding. | ||
|
||
if (state === PREPARE) { | ||
if (release.warnForWrongBranch()) return; | ||
|
||
// Check the branch diff to determine if the releaser | ||
// wants to backport any more commits before proceeding. | ||
cli.startSpinner('Fetching branch-diff'); | ||
const raw = release.checkBranchDiff(); | ||
const diff = raw.split('*'); | ||
cli.stopSpinner('Got branch diff'); | ||
|
||
const staging = `v${semver.major(argv.newVersion)}.x-staging`; | ||
const proceed = await cli.prompt( | ||
`There are ${diff.length} commits that may be backported ` + | ||
`to ${staging} - do you still want to proceed?`, | ||
false); | ||
|
||
if (!proceed) { | ||
const seeDiff = await cli.prompt( | ||
'Do you want to see the branch diff?', true); | ||
if (seeDiff) console.log(raw); | ||
return; | ||
} | ||
|
||
return release.prepare(); | ||
} else if (state === PROMOTE) { | ||
return release.promote(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.