Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
(cherry picked from commit d57593c)
  • Loading branch information
frangio committed Jan 24, 2022
1 parent 0a950ac commit 6851364
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions scripts/update-docs-branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ const tryRead = cmd => { try { return read(cmd); } catch (e) { return undefined;

const releaseBranchRegex = /^release-v(?<version>(?<major>\d+)\.(?<minor>\d+)(?:\.(?<patch>\d+))?)$/;

const currentBranch = read(`git rev-parse --abbrev-ref HEAD`);
const currentBranch = read('git rev-parse --abbrev-ref HEAD');
const match = currentBranch.match(releaseBranchRegex);

if (!match) {
console.error(`Not currently on a release branch`);
console.error('Not currently on a release branch');
process.exit(1);
}

if (/-.*$/.test(require('../package.json').version)) {
console.error(`Refusing to update docs: prerelease detected`);
console.error('Refusing to update docs: prerelease detected');
process.exit(0);
}

const current = match.groups;
const docsBranch = `docs-v${current.major}.x`;

// Fetch remotes and find the docs branch if it exists
run(`git fetch --all --no-tags`);
run('git fetch --all --no-tags');
const matchingDocsBranches = tryRead(`git rev-parse --glob='*/${docsBranch}'`);

if (!matchingDocsBranches) {
Expand All @@ -32,24 +32,24 @@ if (!matchingDocsBranches) {
const [publishedRef, ...others] = new Set(matchingDocsBranches.split('\n'));
if (others.length > 0) {
console.error(
`Found conflicting ${docsBranch} branches.\n`
+ `Either local branch is outdated or there are multiple matching remote branches.`
`Found conflicting ${docsBranch} branches.\n` +
'Either local branch is outdated or there are multiple matching remote branches.',
);
process.exit(1);
}
const publishedVersion = JSON.parse(read(`git show ${publishedRef}:package.json`)).version;
const publishedMinor = publishedVersion.match(/\d+\.(?<minor>\d+)\.\d+/).groups.minor;
if (current.minor < publishedMinor) {
console.error(`Refusing to update docs: newer version is published`);
console.error('Refusing to update docs: newer version is published');
process.exit(0);
}

run(`git checkout --quiet --detach`);
run('git checkout --quiet --detach');
run(`git reset --soft ${publishedRef}`);
run(`git checkout ${docsBranch}`);
}

run(`npm run prepare-docs`);
run(`git add -f docs`); // --force needed because generated docs files are gitignored
run(`git commit -m "Update docs"`);
run('npm run prepare-docs');
run('git add -f docs'); // --force needed because generated docs files are gitignored
run('git commit -m "Update docs"');
run(`git checkout ${currentBranch}`);

0 comments on commit 6851364

Please sign in to comment.