2024-10-01 10:04:22 +00:00
|
|
|
import * as semver from 'semver';
|
|
|
|
import { GitProcess } from 'dugite';
|
2018-12-06 19:00:10 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
import { ELECTRON_DIR } from '../lib/utils';
|
2019-06-24 17:18:04 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
export enum PreType {
|
|
|
|
NONE = 'none',
|
|
|
|
PARTIAL = ' partial',
|
|
|
|
FULL = 'full',
|
|
|
|
}
|
2019-01-07 21:41:07 +00:00
|
|
|
|
2018-12-06 19:00:10 +00:00
|
|
|
const getCurrentDate = () => {
|
|
|
|
const d = new Date();
|
|
|
|
const dd = `${d.getDate()}`.padStart(2, '0');
|
|
|
|
const mm = `${d.getMonth() + 1}`.padStart(2, '0');
|
|
|
|
const yyyy = d.getFullYear();
|
|
|
|
return `${yyyy}${mm}${dd}`;
|
|
|
|
};
|
2020-03-20 20:28:31 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
export const isNightly = (v: string) => v.includes('nightly');
|
|
|
|
export const isAlpha = (v: string) => v.includes('alpha');
|
|
|
|
export const isBeta = (v: string) => v.includes('beta');
|
|
|
|
export const isStable = (v: string) => {
|
2018-12-06 19:00:10 +00:00
|
|
|
const parsed = semver.parse(v);
|
|
|
|
return !!(parsed && parsed.prerelease.length === 0);
|
|
|
|
};
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
export async function nextAlpha (v: string) {
|
2018-12-06 19:00:10 +00:00
|
|
|
const next = semver.coerce(semver.clean(v));
|
2021-07-20 00:58:15 +00:00
|
|
|
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) => {
|
2024-10-01 10:04:22 +00:00
|
|
|
const a = parseInt(t1.split('.').pop()!, 10);
|
|
|
|
const b = parseInt(t2.split('.').pop()!, 10);
|
2021-07-20 00:58:15 +00:00
|
|
|
return a - b;
|
|
|
|
});
|
|
|
|
|
|
|
|
// increment the latest existing alpha tag or start at alpha.1 if it's a new alpha line
|
2024-10-01 10:04:22 +00:00
|
|
|
return tags.length === 0 ? `${next}-alpha.1` : semver.inc(tags.pop()!, 'prerelease')!;
|
2021-07-20 00:58:15 +00:00
|
|
|
}
|
2018-12-06 19:00:10 +00:00
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
export async function nextBeta (v: string) {
|
2021-07-20 00:58:15 +00:00
|
|
|
const next = semver.coerce(semver.clean(v));
|
2019-06-24 17:18:04 +00:00
|
|
|
const tagBlob = await GitProcess.exec(['tag', '--list', '-l', `v${next}-beta.*`], ELECTRON_DIR);
|
2018-12-06 19:00:10 +00:00
|
|
|
const tags = tagBlob.stdout.split('\n').filter(e => e !== '');
|
2020-03-24 13:04:12 +00:00
|
|
|
tags.sort((t1, t2) => {
|
2024-10-01 10:04:22 +00:00
|
|
|
const a = parseInt(t1.split('.').pop()!, 10);
|
|
|
|
const b = parseInt(t2.split('.').pop()!, 10);
|
2020-03-24 13:04:12 +00:00
|
|
|
return a - b;
|
|
|
|
});
|
2018-12-06 19:00:10 +00:00
|
|
|
|
|
|
|
// increment the latest existing beta tag or start at beta.1 if it's a new beta line
|
2024-10-01 10:04:22 +00:00
|
|
|
return tags.length === 0 ? `${next}-beta.1` : semver.inc(tags.pop()!, 'prerelease')!;
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
export async function nextNightly (v: string) {
|
2018-12-06 19:00:10 +00:00
|
|
|
let next = semver.valid(semver.coerce(v));
|
|
|
|
const pre = `nightly.${getCurrentDate()}`;
|
|
|
|
|
2019-06-24 17:18:04 +00:00
|
|
|
const branch = (await GitProcess.exec(['rev-parse', '--abbrev-ref', 'HEAD'], ELECTRON_DIR)).stdout.trim();
|
2023-01-12 17:05:26 +00:00
|
|
|
if (branch === 'main') {
|
2021-05-28 00:32:37 +00:00
|
|
|
next = semver.inc(await getLastMajorForMain(), 'major');
|
2018-12-06 19:00:10 +00:00
|
|
|
} else if (isStable(v)) {
|
2024-10-01 10:04:22 +00:00
|
|
|
next = semver.inc(next!, 'patch');
|
2018-12-06 19:00:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return `${next}-${pre}`;
|
|
|
|
}
|
|
|
|
|
2021-05-28 00:32:37 +00:00
|
|
|
async function getLastMajorForMain () {
|
2019-06-24 17:18:04 +00:00
|
|
|
let branchNames;
|
2019-11-12 16:36:03 +00:00
|
|
|
const result = await GitProcess.exec(['branch', '-a', '--remote', '--list', 'origin/[0-9]*-x-y'], ELECTRON_DIR);
|
2019-06-24 17:18:04 +00:00
|
|
|
if (result.exitCode === 0) {
|
|
|
|
branchNames = result.stdout.trim().split('\n');
|
|
|
|
const filtered = branchNames.map(b => b.replace('origin/', ''));
|
|
|
|
return getNextReleaseBranch(filtered);
|
|
|
|
} else {
|
|
|
|
throw new Error('Release branches could not be fetched.');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-01 10:04:22 +00:00
|
|
|
function getNextReleaseBranch (branches: string[]) {
|
2019-11-12 16:36:03 +00:00
|
|
|
const converted = branches.map(b => b.replace(/-/g, '.').replace('x', '0').replace('y', '0'));
|
2019-06-24 17:18:04 +00:00
|
|
|
return converted.reduce((v1, v2) => semver.gt(v1, v2) ? v1 : v2);
|
|
|
|
}
|