build: update version-bumper to support alpha (#30165)

* build: update version-bumper to support alpha

* build: seperate alpha bump version tests

For easier deletion. If we want to continue supporting an alpha channel,
they can be reintegrated with main tests.

* chore: fix regex

Co-authored-by: Samuel Attard <sam@electronjs.org>

Co-authored-by: Samuel Attard <sam@electronjs.org>
This commit is contained in:
Keeley Hammond 2021-07-19 17:58:15 -07:00 committed by GitHub
parent d35fb2a2e3
commit deb75ceaa5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 231 additions and 84 deletions

View file

@ -25,8 +25,9 @@ const runGit = async (args) => {
};
const tagIsSupported = tag => tag && !tag.includes('nightly') && !tag.includes('unsupported');
const tagIsAlpha = tag => tag && tag.includes('alpha');
const tagIsBeta = tag => tag && tag.includes('beta');
const tagIsStable = tag => tagIsSupported(tag) && !tagIsBeta(tag);
const tagIsStable = tag => tagIsSupported(tag) && !tagIsBeta(tag) && !tagIsAlpha(tag);
const getTagsOf = async (point) => {
try {

View file

@ -25,7 +25,7 @@ const pass = '✓'.green;
const fail = '✗'.red;
if (!bumpType && !args.notesOnly) {
console.log('Usage: prepare-release [stable | minor | beta | nightly]' +
console.log('Usage: prepare-release [stable | minor | beta | alpha | nightly]' +
' (--stable) (--notesOnly) (--automaticRelease) (--branch)');
process.exit(1);
}
@ -93,6 +93,11 @@ async function createRelease (branchToTarget, isBeta) {
'for any bugs you find in it.\n \n This release is published to npm ' +
'under the electron-nightly package and can be installed via `npm install electron-nightly`, ' +
`or \`npm install electron-nightly@${newVersion.substr(1)}\`.\n \n ${releaseNotes.text}`;
} else if (newVersion.indexOf('alpha') > 0) {
releaseBody = 'Note: This is an alpha release. Please file new issues ' +
'for any bugs you find in it.\n \n This release is published to npm ' +
'under the alpha tag and can be installed via `npm install electron@alpha`, ' +
`or \`npm install electron@${newVersion.substr(1)}\`.\n \n ${releaseNotes.text}`;
} else {
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 ' +
@ -182,7 +187,8 @@ async function promptForVersion (version) {
// function to determine if there have been commits to main since the last release
async function changesToRelease () {
const lastCommitWasRelease = new RegExp('^Bump v[0-9.]*(-beta[0-9.]*)?(-nightly[0-9.]*)?$', 'g');
// eslint-disable-next-line no-useless-escape
const lastCommitWasRelease = new RegExp('^Bump v[0-9]+\.[0-9]+\.[0-9]+(-beta\.[0-9]+)?(-alpha\.[0-9]+)?(-nightly\.[0-9]+)?$', 'g');
const lastCommit = await GitProcess.exec(['log', '-n', '1', '--pretty=format:\'%s\''], ELECTRON_DIR);
return !lastCommitWasRelease.test(lastCommit.stdout);
}

View file

@ -135,6 +135,9 @@ new Promise((resolve, reject) => {
} else if (!release.prerelease) {
// Tag the release with a `2-0-x` style tag
npmTag = currentBranch;
} else if (release.tag_name.indexOf('alpha') > 0) {
// Tag the release with an `alpha-3-0-x` style tag
npmTag = `alpha-${currentBranch}`;
} else {
// Tag the release with a `beta-3-0-x` style tag
npmTag = `beta-${currentBranch}`;
@ -175,6 +178,10 @@ new Promise((resolve, reject) => {
semver.gt(localVersion, currentTags.beta)) {
childProcess.execSync(`npm dist-tag add electron@${localVersion} beta --otp=${process.env.ELECTRON_NPM_OTP}`);
}
if (parsedLocalVersion.prerelease[0] === 'alpha' &&
semver.gt(localVersion, currentTags.alpha)) {
childProcess.execSync(`npm dist-tag add electron@${localVersion} alpha --otp=${process.env.ELECTRON_NPM_OTP}`);
}
}
})
.catch((err) => {

View file

@ -71,13 +71,20 @@ async function main () {
console.log(`Bumped to version: ${version}`);
}
// get next version for release based on [nightly, beta, stable]
// get next version for release based on [nightly, alpha, beta, stable]
async function nextVersion (bumpType, version) {
if (versionUtils.isNightly(version) || versionUtils.isBeta(version)) {
if (
versionUtils.isNightly(version) ||
versionUtils.isAlpha(version) ||
versionUtils.isBeta(version)
) {
switch (bumpType) {
case 'nightly':
version = await versionUtils.nextNightly(version);
break;
case 'alpha':
version = await versionUtils.nextAlpha(version);
break;
case 'beta':
version = await versionUtils.nextBeta(version);
break;
@ -92,6 +99,8 @@ async function nextVersion (bumpType, version) {
case 'nightly':
version = versionUtils.nextNightly(version);
break;
case 'alpha':
throw new Error('Cannot bump to alpha from stable.');
case 'beta':
throw new Error('Cannot bump to beta from stable.');
case 'minor':

View file

@ -23,6 +23,7 @@ const getCurrentDate = () => {
};
const isNightly = v => v.includes('nightly');
const isAlpha = v => v.includes('alpha');
const isBeta = v => v.includes('beta');
const isStable = v => {
const parsed = semver.parse(v);
@ -39,9 +40,22 @@ const makeVersion = (components, delim, pre = preType.NONE) => {
return version;
};
async function nextAlpha (v) {
const next = semver.coerce(semver.clean(v));
const tagBlob = await GitProcess.exec(['tag', '--list', '-l', `v${next}-alpha.*`], ELECTRON_DIR);
const tags = tagBlob.stdout.split('\n').filter(e => e !== '');
tags.sort((t1, t2) => {
const a = parseInt(t1.split('.').pop(), 10);
const b = parseInt(t2.split('.').pop(), 10);
return a - b;
});
// increment the latest existing alpha tag or start at alpha.1 if it's a new alpha line
return tags.length === 0 ? `${next}-alpha.1` : semver.inc(tags.pop(), 'prerelease');
}
async function nextBeta (v) {
const next = semver.coerce(semver.clean(v));
const tagBlob = await GitProcess.exec(['tag', '--list', '-l', `v${next}-beta.*`], ELECTRON_DIR);
const tags = tagBlob.stdout.split('\n').filter(e => e !== '');
tags.sort((t1, t2) => {
@ -94,8 +108,10 @@ function getNextReleaseBranch (branches) {
module.exports = {
isStable,
isAlpha,
isBeta,
isNightly,
nextAlpha,
nextBeta,
makeVersion,
getElectronVersion,