chore: automate version bumps (#6627)

Issue: #6482
This commit is contained in:
Mathias Bynens 2020-11-26 11:38:24 +01:00 committed by GitHub
parent b57f3fcd53
commit 470124fb2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 63 additions and 16 deletions

View File

@ -1,3 +0,0 @@
{
"releaseCommitMessageFormat": "chore(release): mark v{{currentTag}}"
}

27
.versionrc.js Normal file
View File

@ -0,0 +1,27 @@
/**
* Copyright 2020 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = {
releaseCommitMessageFormat: 'chore(release): mark v{{currentTag}}',
skip: {
commit: true,
tag: true,
},
scripts: {
prerelease: 'node utils/remove_version_suffix.js',
postbump: 'IS_RELEASE=true npm run doc',
},
};

View File

@ -276,8 +276,7 @@ node utils/bisect.js --good 686378 --bad 706915 script.js
Releasing to npm consists of the following phases: Releasing to npm consists of the following phases:
1. Source Code: mark a release. 1. Source Code: mark a release.
1. Run `npm run release` to bump the version number in `package.json` and populate the changelog. 1. Run `npm run release` to bump the version number in `package.json`, populate the changelog, and update the docs.
1. Run `npm run doc` to update the docs accordingly.
1. Send a PR titled `'chore(release): mark vXXX.YYY.ZZZ'` ([example](https://github.com/puppeteer/puppeteer/pull/5078)). 1. Send a PR titled `'chore(release): mark vXXX.YYY.ZZZ'` ([example](https://github.com/puppeteer/puppeteer/pull/5078)).
1. Make sure the PR passes **all checks**. 1. Make sure the PR passes **all checks**.
- **WHY**: there are linters in place that help to avoid unnecessary errors, e.g. [like this](https://github.com/puppeteer/puppeteer/pull/2446) - **WHY**: there are linters in place that help to avoid unnecessary errors, e.g. [like this](https://github.com/puppeteer/puppeteer/pull/2446)

View File

@ -34,7 +34,7 @@
"test-install": "scripts/test-install.sh", "test-install": "scripts/test-install.sh",
"generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs", "generate-docs": "npm run tsc && api-extractor run --local --verbose && api-documenter markdown -i temp -o new-docs",
"ensure-correct-devtools-protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package", "ensure-correct-devtools-protocol-revision": "ts-node -s scripts/ensure-correct-devtools-protocol-package",
"release": "standard-version" "release": "node utils/remove_version_suffix.js && standard-version"
}, },
"files": [ "files": [
"lib/", "lib/",
@ -105,11 +105,5 @@
"hooks": { "hooks": {
"commit-msg": "commitlint --env HUSKY_GIT_PARAMS" "commit-msg": "commitlint --env HUSKY_GIT_PARAMS"
} }
},
"standard-version": {
"skip": {
"commit": true,
"tag": true
}
} }
} }

View File

@ -26,6 +26,8 @@ const RED_COLOR = '\x1b[31m';
const YELLOW_COLOR = '\x1b[33m'; const YELLOW_COLOR = '\x1b[33m';
const RESET_COLOR = '\x1b[0m'; const RESET_COLOR = '\x1b[0m';
const IS_RELEASE = Boolean(process.env.IS_RELEASE);
run(); run();
async function run() { async function run() {
@ -35,7 +37,7 @@ async function run() {
const messages = []; const messages = [];
let changedFiles = false; let changedFiles = false;
if (!VERSION.endsWith('-post')) { if (IS_RELEASE) {
const versions = await Source.readFile( const versions = await Source.readFile(
path.join(PROJECT_DIR, 'versions.js') path.join(PROJECT_DIR, 'versions.js')
); );
@ -132,5 +134,5 @@ async function run() {
const runningTime = Date.now() - startTime; const runningTime = Date.now() - startTime;
console.log(`DocLint Finished in ${runningTime / 1000} seconds`); console.log(`DocLint Finished in ${runningTime / 1000} seconds`);
process.exit(clearExit ? 0 : 1); process.exit(clearExit || IS_RELEASE ? 0 : 1);
} }

View File

@ -16,6 +16,8 @@
const Message = require('../Message'); const Message = require('../Message');
const IS_RELEASE = Boolean(process.env.IS_RELEASE);
module.exports.ensureReleasedAPILinks = function (sources, version) { module.exports.ensureReleasedAPILinks = function (sources, version) {
// Release version is everything that doesn't include "-". // Release version is everything that doesn't include "-".
const apiLinkRegex = /https:\/\/github.com\/puppeteer\/puppeteer\/blob\/v[^/]*\/docs\/api.md/gi; const apiLinkRegex = /https:\/\/github.com\/puppeteer\/puppeteer\/blob\/v[^/]*\/docs\/api.md/gi;
@ -35,7 +37,7 @@ module.exports.ensureReleasedAPILinks = function (sources, version) {
module.exports.runCommands = function (sources, version) { module.exports.runCommands = function (sources, version) {
// Release version is everything that doesn't include "-". // Release version is everything that doesn't include "-".
const isReleaseVersion = !version.includes('-'); const isReleaseVersion = IS_RELEASE || !version.includes('-');
const messages = []; const messages = [];
const commands = []; const commands = [];
@ -70,7 +72,7 @@ module.exports.runCommands = function (sources, version) {
for (const command of commands) { for (const command of commands) {
let newText = null; let newText = null;
if (command.name === 'version') if (command.name === 'version')
newText = isReleaseVersion ? 'v' + version : 'Tip-Of-Tree'; newText = isReleaseVersion ? `v${version}` : 'Tip-Of-Tree';
else if (command.name === 'empty-if-release') else if (command.name === 'empty-if-release')
newText = isReleaseVersion ? '' : command.originalText; newText = isReleaseVersion ? '' : command.originalText;
else if (command.name === 'toc') else if (command.name === 'toc')

View File

@ -0,0 +1,26 @@
/**
* Copyright 2020 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const fs = require('fs');
const json = fs.readFileSync('./package.json', 'utf8').toString();
const pkg = JSON.parse(json);
const oldVersion = pkg.version;
const version = oldVersion.replace(/-post$/, '');
const updated = json.replace(
`"version": "${oldVersion}"`,
`"version": "${version}"`
);
fs.writeFileSync('./package.json', updated);