2019-07-24 17:16:28 +00:00
|
|
|
import { expect } from 'chai';
|
2021-07-20 00:58:15 +00:00
|
|
|
import { GitProcess, IGitExecutionOptions, IGitResult } from 'dugite';
|
2021-06-02 19:53:23 +00:00
|
|
|
import { nextVersion, shouldUpdateSupported, updateSupported } from '../script/release/version-bumper';
|
2019-07-24 17:16:28 +00:00
|
|
|
import * as utils from '../script/release/version-utils';
|
2021-07-20 00:58:15 +00:00
|
|
|
import * as sinon from 'sinon';
|
2019-11-01 20:37:02 +00:00
|
|
|
import { ifdescribe } from './spec-helpers';
|
2021-06-02 19:53:23 +00:00
|
|
|
const { promises: fs } = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const fixtureDir = path.resolve(__dirname, 'fixtures', 'version-bumper', 'fixture_support.md');
|
|
|
|
const readFile = fs.readFile;
|
|
|
|
const writeFile = fs.writeFile;
|
2019-07-24 17:16:28 +00:00
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
class GitFake {
|
|
|
|
branches: {
|
|
|
|
[key: string]: string[],
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor () {
|
|
|
|
this.branches = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
setBranch (channel: string): void {
|
|
|
|
this.branches[channel] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
setVersion (channel: string, latestTag: string): void {
|
|
|
|
const tags = [latestTag];
|
|
|
|
if (channel === 'alpha') {
|
|
|
|
const versionStrs = latestTag.split(`${channel}.`);
|
|
|
|
const latest = parseInt(versionStrs[1]);
|
|
|
|
|
|
|
|
for (let i = latest; i >= 1; i--) {
|
|
|
|
tags.push(`${versionStrs[0]}${channel}.${latest - i}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.branches[channel] = tags;
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
exec (args: string[], path: string, options?: IGitExecutionOptions | undefined): Promise<IGitResult> {
|
|
|
|
let stdout = '';
|
|
|
|
const stderr = '';
|
|
|
|
const exitCode = 0;
|
|
|
|
|
|
|
|
// handle for promoting from current master HEAD
|
|
|
|
let branch = 'stable';
|
|
|
|
const v = (args[2] === 'HEAD') ? 'stable' : args[3];
|
|
|
|
if (v.includes('nightly')) branch = 'nightly';
|
|
|
|
if (v.includes('alpha')) branch = 'alpha';
|
|
|
|
if (v.includes('beta')) branch = 'beta';
|
|
|
|
|
|
|
|
if (!this.branches[branch]) this.setBranch(branch);
|
|
|
|
|
|
|
|
stdout = this.branches[branch].join('\n');
|
|
|
|
return Promise.resolve({ exitCode, stdout, stderr });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-24 17:16:28 +00:00
|
|
|
describe('version-bumper', () => {
|
|
|
|
describe('makeVersion', () => {
|
|
|
|
it('makes a version with a period delimeter', () => {
|
|
|
|
const components = {
|
|
|
|
major: 2,
|
|
|
|
minor: 0,
|
|
|
|
patch: 0
|
|
|
|
};
|
|
|
|
|
|
|
|
const version = utils.makeVersion(components, '.');
|
|
|
|
expect(version).to.equal('2.0.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('makes a version with a period delimeter and a partial pre', () => {
|
|
|
|
const components = {
|
|
|
|
major: 2,
|
|
|
|
minor: 0,
|
|
|
|
patch: 0,
|
2020-03-20 15:12:18 +00:00
|
|
|
pre: ['nightly', 12345678]
|
2019-07-24 17:16:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const version = utils.makeVersion(components, '.', utils.preType.PARTIAL);
|
|
|
|
expect(version).to.equal('2.0.0.12345678');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('makes a version with a period delimeter and a full pre', () => {
|
|
|
|
const components = {
|
|
|
|
major: 2,
|
|
|
|
minor: 0,
|
|
|
|
patch: 0,
|
2020-03-20 15:12:18 +00:00
|
|
|
pre: ['nightly', 12345678]
|
2019-07-24 17:16:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const version = utils.makeVersion(components, '.', utils.preType.FULL);
|
|
|
|
expect(version).to.equal('2.0.0-nightly.12345678');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-06-02 19:53:23 +00:00
|
|
|
describe('updateSupported', () => {
|
|
|
|
let restore: any;
|
|
|
|
before(async () => {
|
|
|
|
restore = await readFile(fixtureDir, 'utf8');
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
await writeFile(fixtureDir, restore, 'utf8');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('updates correctly when a new stable version is promoted from beta', async () => {
|
|
|
|
const version = '4.0.0';
|
|
|
|
const currentVersion = '4.0.0-beta.29';
|
|
|
|
if (shouldUpdateSupported('stable', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('4.x.y\n* 3.x.y\n* 2.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update when a new stable patch version is promoted', async () => {
|
|
|
|
const version = '3.0.1';
|
|
|
|
const currentVersion = '3.0.0';
|
|
|
|
if (shouldUpdateSupported('stable', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update when a new stable minor version is promoted', async () => {
|
|
|
|
const version = '3.1.0';
|
|
|
|
const currentVersion = '3.0.0';
|
|
|
|
if (shouldUpdateSupported('minor', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update when a new beta.1 version is promoted', async () => {
|
|
|
|
const version = '5.0.0-beta.1';
|
|
|
|
const currentVersion = '4.0.0-beta.29';
|
|
|
|
if (shouldUpdateSupported('beta', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update when a new beta.12 version is promoted', async () => {
|
|
|
|
const version = '4.0.0-beta.12';
|
|
|
|
const currentVersion = '4.0.0-beta.11';
|
|
|
|
if (shouldUpdateSupported('beta', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should update when a new major nightly version is promoted', async () => {
|
|
|
|
const version = '4.0.0-nightly.19950901';
|
|
|
|
const currentVersion = '3.0.0-nightly.19950828';
|
|
|
|
if (shouldUpdateSupported('nightly', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('4.x.y\n* 3.x.y\n* 2.x.y');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update when a new nightly version is promoted', async () => {
|
|
|
|
const version = '3.0.0-nightly.19950901';
|
|
|
|
const currentVersion = '3.0.0-nightly.19950828';
|
|
|
|
if (shouldUpdateSupported('nightly', currentVersion, version)) {
|
|
|
|
await updateSupported(version, fixtureDir);
|
|
|
|
}
|
|
|
|
const contents = await readFile(fixtureDir, 'utf8');
|
|
|
|
|
|
|
|
expect(contents).to.contain('3.x.y\n* 2.x.y\n* 1.x.y');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-07-24 17:16:28 +00:00
|
|
|
// On macOS Circle CI we don't have a real git environment due to running
|
|
|
|
// gclient sync on a linux machine. These tests therefore don't run as expected.
|
2021-06-17 22:38:25 +00:00
|
|
|
ifdescribe(!(process.platform === 'linux' && process.arch.indexOf('arm') === 0) && process.platform !== 'darwin')('nextVersion', () => {
|
2021-07-20 00:58:15 +00:00
|
|
|
describe('bump versions', () => {
|
|
|
|
const nightlyPattern = /[0-9.]*(-nightly.(\d{4})(\d{2})(\d{2}))$/g;
|
|
|
|
const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
|
|
|
|
|
|
|
|
it('bumps to nightly from stable', async () => {
|
|
|
|
const version = 'v2.0.0';
|
|
|
|
const next = await nextVersion('nightly', version);
|
|
|
|
const matches = next.match(nightlyPattern);
|
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to nightly from beta', async () => {
|
|
|
|
const version = 'v2.0.0-beta.1';
|
|
|
|
const next = await nextVersion('nightly', version);
|
|
|
|
const matches = next.match(nightlyPattern);
|
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to nightly from nightly', async () => {
|
|
|
|
const version = 'v2.0.0-nightly.19950901';
|
|
|
|
const next = await nextVersion('nightly', version);
|
|
|
|
const matches = next.match(nightlyPattern);
|
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to a nightly version above our switch from N-0-x to N-x-y branch names', async () => {
|
|
|
|
const version = 'v2.0.0-nightly.19950901';
|
|
|
|
const next = await nextVersion('nightly', version);
|
|
|
|
// If it starts with v8 then we didn't bump above the 8-x-y branch
|
|
|
|
expect(next.startsWith('v8')).to.equal(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws error when bumping to beta from stable', () => {
|
|
|
|
const version = 'v2.0.0';
|
|
|
|
return expect(
|
|
|
|
nextVersion('beta', version)
|
|
|
|
).to.be.rejectedWith('Cannot bump to beta from stable.');
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO ELECTRON 15: Re-enable after Electron 15 alpha has released
|
|
|
|
it.skip('bumps to beta from nightly', async () => {
|
|
|
|
const version = 'v2.0.0-nightly.19950901';
|
|
|
|
const next = await nextVersion('beta', version);
|
|
|
|
const matches = next.match(betaPattern);
|
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to beta from beta', async () => {
|
|
|
|
const version = 'v2.0.0-beta.8';
|
|
|
|
const next = await nextVersion('beta', version);
|
|
|
|
expect(next).to.equal('2.0.0-beta.9');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to beta from beta if the previous beta is at least beta.10', async () => {
|
|
|
|
const version = 'v6.0.0-beta.15';
|
|
|
|
const next = await nextVersion('beta', version);
|
|
|
|
expect(next).to.equal('6.0.0-beta.16');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to stable from beta', async () => {
|
|
|
|
const version = 'v2.0.0-beta.1';
|
|
|
|
const next = await nextVersion('stable', version);
|
|
|
|
expect(next).to.equal('2.0.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to stable from stable', async () => {
|
|
|
|
const version = 'v2.0.0';
|
|
|
|
const next = await nextVersion('stable', version);
|
|
|
|
expect(next).to.equal('2.0.1');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to minor from stable', async () => {
|
|
|
|
const version = 'v2.0.0';
|
|
|
|
const next = await nextVersion('minor', version);
|
|
|
|
expect(next).to.equal('2.1.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('bumps to stable from nightly', async () => {
|
|
|
|
const version = 'v2.0.0-nightly.19950901';
|
|
|
|
const next = await nextVersion('stable', version);
|
|
|
|
expect(next).to.equal('2.0.0');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws on an invalid version', () => {
|
|
|
|
const version = 'vI.AM.INVALID';
|
|
|
|
return expect(
|
|
|
|
nextVersion('beta', version)
|
|
|
|
).to.be.rejectedWith(`Invalid current version: ${version}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('throws on an invalid bump type', () => {
|
|
|
|
const version = 'v2.0.0';
|
|
|
|
return expect(
|
|
|
|
nextVersion('WRONG', version)
|
|
|
|
).to.be.rejectedWith('Invalid bump type.');
|
|
|
|
});
|
2019-07-24 17:16:28 +00:00
|
|
|
});
|
2021-07-20 00:58:15 +00:00
|
|
|
});
|
2019-07-24 17:16:28 +00:00
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
// If we don't plan on continuing to support an alpha channel past Electron 15,
|
|
|
|
// these tests will be removed. Otherwise, integrate into the bump versions tests
|
|
|
|
describe('bump versions - alpha channel', () => {
|
|
|
|
const alphaPattern = /[0-9.]*(-alpha[0-9.]*)/g;
|
|
|
|
const betaPattern = /[0-9.]*(-beta[0-9.]*)/g;
|
2019-07-24 17:16:28 +00:00
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
const sandbox = sinon.createSandbox();
|
|
|
|
const gitFake = new GitFake();
|
2019-07-24 17:16:28 +00:00
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
const wrapper = (args: string[], path: string, options?: IGitExecutionOptions | undefined) => gitFake.exec(args, path, options);
|
|
|
|
sandbox.replace(GitProcess, 'exec', wrapper);
|
2019-11-12 16:36:03 +00:00
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
afterEach(() => {
|
|
|
|
gitFake.branches = {};
|
|
|
|
sandbox.restore();
|
2019-07-24 17:16:28 +00:00
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
it('bumps to alpha from nightly', async () => {
|
2019-07-24 17:16:28 +00:00
|
|
|
const version = 'v2.0.0-nightly.19950901';
|
2021-07-20 00:58:15 +00:00
|
|
|
gitFake.setVersion('nightly', version);
|
|
|
|
const next = await nextVersion('alpha', version);
|
|
|
|
const matches = next.match(alphaPattern);
|
2019-07-24 17:16:28 +00:00
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
it('throws error when bumping to alpha from stable', () => {
|
2019-07-24 17:16:28 +00:00
|
|
|
const version = 'v2.0.0';
|
2021-07-20 00:58:15 +00:00
|
|
|
return expect(
|
|
|
|
nextVersion('alpha', version)
|
|
|
|
).to.be.rejectedWith('Cannot bump to alpha from stable.');
|
2019-10-23 18:07:10 +00:00
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
it('bumps to alpha from alpha', async () => {
|
|
|
|
const version = 'v2.0.0-alpha.8';
|
|
|
|
gitFake.setVersion('alpha', version);
|
|
|
|
const next = await nextVersion('alpha', version);
|
|
|
|
expect(next).to.equal('2.0.0-alpha.9');
|
2019-07-24 17:16:28 +00:00
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
it('bumps to alpha from alpha if the previous alpha is at least alpha.10', async () => {
|
|
|
|
const version = 'v6.0.0-alpha.15';
|
|
|
|
gitFake.setVersion('alpha', version);
|
|
|
|
const next = await nextVersion('alpha', version);
|
|
|
|
expect(next).to.equal('6.0.0-alpha.16');
|
2019-07-24 17:16:28 +00:00
|
|
|
});
|
|
|
|
|
2021-07-20 00:58:15 +00:00
|
|
|
it('bumps to beta from alpha', async () => {
|
|
|
|
const version = 'v2.0.0-alpha.8';
|
|
|
|
gitFake.setVersion('alpha', version);
|
|
|
|
const next = await nextVersion('beta', version);
|
|
|
|
const matches = next.match(betaPattern);
|
|
|
|
expect(matches).to.have.lengthOf(1);
|
|
|
|
expect(next).to.equal('2.0.0-beta.1');
|
2019-07-24 17:16:28 +00:00
|
|
|
});
|
|
|
|
});
|
2019-11-01 20:37:02 +00:00
|
|
|
});
|