2017-10-23 15:02:50 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
if (!process.env.CI) require('dotenv-safe').load();
|
2018-05-14 21:21:51 +00:00
|
|
|
const args = require('minimist')(process.argv.slice(2), {
|
|
|
|
boolean: ['automaticRelease', 'notesOnly', 'stable']
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
const ciReleaseBuild = require('./ci-release-build');
|
2020-08-05 15:59:52 +00:00
|
|
|
const { Octokit } = require('@octokit/rest');
|
2020-03-20 20:28:31 +00:00
|
|
|
const { execSync } = require('child_process');
|
|
|
|
const { GitProcess } = require('dugite');
|
2018-12-03 21:28:10 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
const path = require('path');
|
|
|
|
const readline = require('readline');
|
|
|
|
const releaseNotesGenerator = require('./notes/index.js');
|
|
|
|
const { getCurrentBranch, ELECTRON_DIR } = require('../lib/utils.js');
|
|
|
|
const bumpType = args._[0];
|
|
|
|
const targetRepo = bumpType === 'nightly' ? 'nightlies' : 'electron';
|
2017-10-23 15:02:50 +00:00
|
|
|
|
2020-08-05 15:59:52 +00:00
|
|
|
const octokit = new Octokit({
|
|
|
|
auth: process.env.ELECTRON_GITHUB_TOKEN
|
|
|
|
});
|
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
require('colors');
|
|
|
|
const pass = '✓'.green;
|
|
|
|
const fail = '✗'.red;
|
2018-12-03 21:28:10 +00:00
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
if (!bumpType && !args.notesOnly) {
|
2020-03-20 15:12:18 +00:00
|
|
|
console.log('Usage: prepare-release [stable | minor | beta | nightly]' +
|
2020-03-20 20:28:31 +00:00
|
|
|
' (--stable) (--notesOnly) (--automaticRelease) (--branch)');
|
|
|
|
process.exit(1);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2018-08-16 15:57:12 +00:00
|
|
|
async function getNewVersion (dryRun) {
|
2018-08-20 15:17:47 +00:00
|
|
|
if (!dryRun) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`Bumping for new "${bumpType}" version.`);
|
2018-01-31 23:40:38 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
const bumpScript = path.join(__dirname, 'version-bumper.js');
|
|
|
|
const scriptArgs = ['node', bumpScript, `--bump=${bumpType}`];
|
|
|
|
if (dryRun) scriptArgs.push('--dryRun');
|
2017-10-23 15:02:50 +00:00
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
let bumpVersion = execSync(scriptArgs.join(' '), { encoding: 'UTF-8' });
|
|
|
|
bumpVersion = bumpVersion.substr(bumpVersion.indexOf(':') + 1).trim();
|
|
|
|
const newVersion = `v${bumpVersion}`;
|
2018-01-31 23:40:38 +00:00
|
|
|
if (!dryRun) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${pass} Successfully bumped version to ${newVersion}`);
|
2018-01-31 23:40:38 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
return newVersion;
|
2017-10-23 15:02:50 +00:00
|
|
|
} catch (err) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${fail} Could not bump version, error was:`, err);
|
|
|
|
throw err;
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 20:01:38 +00:00
|
|
|
async function getReleaseNotes (currentBranch, newVersion) {
|
2018-12-06 19:00:10 +00:00
|
|
|
if (bumpType === 'nightly') {
|
2020-03-20 20:28:31 +00:00
|
|
|
return { text: 'Nightlies do not get release notes, please compare tags for info.' };
|
2018-08-16 15:57:12 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`Generating release notes for ${currentBranch}.`);
|
|
|
|
const releaseNotes = await releaseNotesGenerator(currentBranch, newVersion);
|
2018-11-06 20:06:11 +00:00
|
|
|
if (releaseNotes.warning) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.warn(releaseNotes.warning);
|
2018-05-14 21:21:51 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
return releaseNotes;
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function createRelease (branchToTarget, isBeta) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const newVersion = await getNewVersion();
|
|
|
|
const releaseNotes = await getReleaseNotes(branchToTarget, newVersion);
|
|
|
|
await tagRelease(newVersion);
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log('Checking for existing draft release.');
|
2019-01-08 20:05:58 +00:00
|
|
|
const releases = await octokit.repos.listReleases({
|
2017-10-23 15:02:50 +00:00
|
|
|
owner: 'electron',
|
2018-08-16 16:12:06 +00:00
|
|
|
repo: targetRepo
|
2019-01-08 20:05:58 +00:00
|
|
|
}).catch(err => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${fail} Could not get releases. Error was: `, err);
|
|
|
|
});
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2018-10-02 01:56:31 +00:00
|
|
|
const drafts = releases.data.filter(release => release.draft &&
|
2020-03-20 20:28:31 +00:00
|
|
|
release.tag_name === newVersion);
|
2017-10-23 15:02:50 +00:00
|
|
|
if (drafts.length > 0) {
|
|
|
|
console.log(`${fail} Aborting because draft release for
|
2020-03-20 20:28:31 +00:00
|
|
|
${drafts[0].tag_name} already exists.`);
|
|
|
|
process.exit(1);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${pass} A draft release does not exist; creating one.`);
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
let releaseBody;
|
|
|
|
let releaseIsPrelease = false;
|
2017-10-23 15:02:50 +00:00
|
|
|
if (isBeta) {
|
2018-08-17 17:42:45 +00:00
|
|
|
if (newVersion.indexOf('nightly') > 0) {
|
2020-03-20 15:12:18 +00:00
|
|
|
releaseBody = 'Note: This is a nightly release. Please file new issues ' +
|
|
|
|
'for any bugs you find in it.\n \n This release is published to npm ' +
|
2020-08-27 19:11:27 +00:00
|
|
|
'under the electron-nightly package and can be installed via `npm install electron-nightly`, ' +
|
2020-04-14 15:14:21 +00:00
|
|
|
`or \`npm install electron-nightly@${newVersion.substr(1)}\`.\n \n ${releaseNotes.text}`;
|
2018-08-16 16:12:06 +00:00
|
|
|
} else {
|
2020-03-20 15:12:18 +00:00
|
|
|
releaseBody = 'Note: This is a beta release. Please file new issues ' +
|
|
|
|
'for any bugs you find in it.\n \n This release is published to npm ' +
|
2020-04-14 15:14:21 +00:00
|
|
|
'under the beta tag and can be installed via `npm install electron@beta`, ' +
|
|
|
|
`or \`npm install electron@${newVersion.substr(1)}\`.\n \n ${releaseNotes.text}`;
|
2018-08-16 16:12:06 +00:00
|
|
|
}
|
2020-03-20 20:28:31 +00:00
|
|
|
releaseIsPrelease = true;
|
2018-01-31 23:40:38 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
releaseBody = releaseNotes.text;
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
2019-01-08 20:05:58 +00:00
|
|
|
|
|
|
|
const release = await octokit.repos.createRelease({
|
|
|
|
owner: 'electron',
|
|
|
|
repo: targetRepo,
|
|
|
|
tag_name: newVersion,
|
|
|
|
draft: true,
|
|
|
|
name: `electron ${newVersion}`,
|
|
|
|
body: releaseBody,
|
|
|
|
prerelease: releaseIsPrelease,
|
|
|
|
target_commitish: newVersion.indexOf('nightly') !== -1 ? 'master' : branchToTarget
|
|
|
|
}).catch(err => {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${fail} Error creating new release: `, err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
2019-01-08 20:05:58 +00:00
|
|
|
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`Release has been created with id: ${release.data.id}.`);
|
|
|
|
console.log(`${pass} Draft release for ${newVersion} successful.`);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 21:21:51 +00:00
|
|
|
async function pushRelease (branch) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const pushDetails = await GitProcess.exec(['push', 'origin', `HEAD:${branch}`, '--follow-tags'], ELECTRON_DIR);
|
2017-10-23 15:02:50 +00:00
|
|
|
if (pushDetails.exitCode === 0) {
|
2018-02-12 16:01:50 +00:00
|
|
|
console.log(`${pass} Successfully pushed the release. Wait for ` +
|
2020-03-20 20:28:31 +00:00
|
|
|
'release builds to finish before running "npm run release".');
|
2017-10-23 15:02:50 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${fail} Error pushing the release: ${pushDetails.stderr}`);
|
|
|
|
process.exit(1);
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-12 16:01:50 +00:00
|
|
|
async function runReleaseBuilds (branch) {
|
|
|
|
await ciReleaseBuild(branch, {
|
2018-05-14 21:21:51 +00:00
|
|
|
ghRelease: true,
|
|
|
|
automaticRelease: args.automaticRelease
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2017-11-17 20:13:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-12 16:01:50 +00:00
|
|
|
async function tagRelease (version) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`Tagging release ${version}.`);
|
|
|
|
const checkoutDetails = await GitProcess.exec(['tag', '-a', '-m', version, version], ELECTRON_DIR);
|
2018-02-12 16:01:50 +00:00
|
|
|
if (checkoutDetails.exitCode === 0) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${pass} Successfully tagged ${version}.`);
|
2018-02-12 16:01:50 +00:00
|
|
|
} else {
|
|
|
|
console.log(`${fail} Error tagging ${version}: ` +
|
2020-03-20 20:28:31 +00:00
|
|
|
`${checkoutDetails.stderr}`);
|
|
|
|
process.exit(1);
|
2018-02-12 16:01:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-31 23:40:38 +00:00
|
|
|
async function verifyNewVersion () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const newVersion = await getNewVersion(true);
|
|
|
|
let response;
|
2018-05-14 21:21:51 +00:00
|
|
|
if (args.automaticRelease) {
|
2020-03-20 20:28:31 +00:00
|
|
|
response = 'y';
|
2018-05-14 21:21:51 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
response = await promptForVersion(newVersion);
|
2018-05-14 21:21:51 +00:00
|
|
|
}
|
2018-01-31 23:40:38 +00:00
|
|
|
if (response.match(/^y/i)) {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${pass} Starting release of ${newVersion}`);
|
2018-01-31 23:40:38 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log(`${fail} Aborting release of ${newVersion}`);
|
|
|
|
process.exit();
|
2018-01-31 23:40:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function promptForVersion (version) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const rl = readline.createInterface({
|
|
|
|
input: process.stdin,
|
|
|
|
output: process.stdout
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2018-01-31 23:40:38 +00:00
|
|
|
rl.question(`Do you want to create the release ${version.green} (y/N)? `, (answer) => {
|
2020-03-20 20:28:31 +00:00
|
|
|
rl.close();
|
|
|
|
resolve(answer);
|
|
|
|
});
|
|
|
|
});
|
2018-01-31 23:40:38 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 00:36:16 +00:00
|
|
|
// function to determine if there have been commits to master since the last release
|
|
|
|
async function changesToRelease () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const lastCommitWasRelease = new RegExp('^Bump v[0-9.]*(-beta[0-9.]*)?(-nightly[0-9.]*)?$', 'g');
|
|
|
|
const lastCommit = await GitProcess.exec(['log', '-n', '1', '--pretty=format:\'%s\''], ELECTRON_DIR);
|
|
|
|
return !lastCommitWasRelease.test(lastCommit.stdout);
|
2018-08-19 00:36:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-23 15:02:50 +00:00
|
|
|
async function prepareRelease (isBeta, notesOnly) {
|
2018-08-20 15:17:47 +00:00
|
|
|
if (args.dryRun) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const newVersion = await getNewVersion(true);
|
|
|
|
console.log(newVersion);
|
2017-10-23 15:02:50 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
const currentBranch = (args.branch) ? args.branch : await getCurrentBranch(ELECTRON_DIR);
|
2018-08-20 15:17:47 +00:00
|
|
|
if (notesOnly) {
|
2020-03-20 20:28:31 +00:00
|
|
|
const newVersion = await getNewVersion(true);
|
|
|
|
const releaseNotes = await getReleaseNotes(currentBranch, newVersion);
|
|
|
|
console.log(`Draft release notes are: \n${releaseNotes.text}`);
|
2018-08-19 00:36:16 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
const changes = await changesToRelease(currentBranch);
|
2018-08-20 15:17:47 +00:00
|
|
|
if (changes) {
|
2020-03-20 20:28:31 +00:00
|
|
|
await verifyNewVersion();
|
|
|
|
await createRelease(currentBranch, isBeta);
|
|
|
|
await pushRelease(currentBranch);
|
|
|
|
await runReleaseBuilds(currentBranch);
|
2018-08-20 15:17:47 +00:00
|
|
|
} else {
|
2020-03-20 20:28:31 +00:00
|
|
|
console.log('There are no new changes to this branch since the last release, aborting release.');
|
|
|
|
process.exit(1);
|
2018-08-20 15:17:47 +00:00
|
|
|
}
|
2018-08-19 00:36:16 +00:00
|
|
|
}
|
2017-10-23 15:02:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-10 17:18:08 +00:00
|
|
|
prepareRelease(!args.stable, args.notesOnly)
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
});
|