build: update support.md on stable version bumps (#29381)
* build: update support.md on stable version bumps * build: update supported on major stable & nightly bumps * test: updateSupported tests * chore: fix syntax * chore: use fspromise in version-bumper script/spec
This commit is contained in:
parent
8ce63a9f18
commit
d8d6e2ebc0
3 changed files with 257 additions and 6 deletions
|
@ -1,17 +1,17 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const { GitProcess } = require('dugite');
|
||||
const fs = require('fs');
|
||||
const { promises: fs } = require('fs');
|
||||
const semver = require('semver');
|
||||
const path = require('path');
|
||||
const { promisify } = require('util');
|
||||
const minimist = require('minimist');
|
||||
|
||||
const { ELECTRON_DIR } = require('../lib/utils');
|
||||
const versionUtils = require('./version-utils');
|
||||
const supported = path.resolve(ELECTRON_DIR, 'docs', 'tutorial', 'support.md');
|
||||
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
const readFile = promisify(fs.readFile);
|
||||
const writeFile = fs.writeFile;
|
||||
const readFile = fs.readFile;
|
||||
|
||||
function parseCommandLine () {
|
||||
let help;
|
||||
|
@ -54,6 +54,10 @@ async function main () {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (shouldUpdateSupported(opts.bump, currentVersion, version)) {
|
||||
await updateSupported(version, supported);
|
||||
}
|
||||
|
||||
// update all version-related files
|
||||
await Promise.all([
|
||||
updateVersion(version),
|
||||
|
@ -105,6 +109,22 @@ async function nextVersion (bumpType, version) {
|
|||
return version;
|
||||
}
|
||||
|
||||
function shouldUpdateSupported (bump, current, version) {
|
||||
return isMajorStable(bump, current) || isMajorNightly(version, current);
|
||||
}
|
||||
|
||||
function isMajorStable (bump, currentVersion) {
|
||||
if (versionUtils.isBeta(currentVersion) && (bump === 'stable')) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
function isMajorNightly (version, currentVersion) {
|
||||
const parsed = semver.parse(version);
|
||||
const current = semver.parse(currentVersion);
|
||||
if (versionUtils.isNightly(currentVersion) && (parsed.major > current.major)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// update VERSION file with latest release info
|
||||
async function updateVersion (version) {
|
||||
const versionPath = path.resolve(ELECTRON_DIR, 'ELECTRON_VERSION');
|
||||
|
@ -142,6 +162,22 @@ async function updateWinRC (components) {
|
|||
await writeFile(filePath, arr.join('\n'));
|
||||
}
|
||||
|
||||
// updates support.md file with new semver values (stable only)
|
||||
async function updateSupported (version, filePath) {
|
||||
const v = parseInt(version);
|
||||
const newVersions = [`* ${v}.x.y`, `* ${v - 1}.x.y`, `* ${v - 2}.x.y`];
|
||||
const contents = await readFile(filePath, 'utf8');
|
||||
const previousVersions = contents.split('\n').filter((elem) => {
|
||||
return (/[^\n]*\.x\.y[^\n]*/).test(elem);
|
||||
}, []);
|
||||
|
||||
const newContents = previousVersions.reduce((contents, current, i) => {
|
||||
return contents.replace(current, newVersions[i]);
|
||||
}, contents);
|
||||
|
||||
await writeFile(filePath, newContents, 'utf8');
|
||||
}
|
||||
|
||||
if (process.mainModule === module) {
|
||||
main().catch((error) => {
|
||||
console.error(error);
|
||||
|
@ -149,4 +185,4 @@ if (process.mainModule === module) {
|
|||
});
|
||||
}
|
||||
|
||||
module.exports = { nextVersion };
|
||||
module.exports = { nextVersion, shouldUpdateSupported, updateSupported };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue