From 470124fb2bfd203ad4e75e44e7d90d4245f530ef Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Thu, 26 Nov 2020 11:38:24 +0100 Subject: [PATCH] chore: automate version bumps (#6627) Issue: #6482 --- .versionrc | 3 --- .versionrc.js | 27 +++++++++++++++++++++++++++ CONTRIBUTING.md | 3 +-- package.json | 8 +------- utils/doclint/cli.js | 6 ++++-- utils/doclint/preprocessor/index.js | 6 ++++-- utils/remove_version_suffix.js | 26 ++++++++++++++++++++++++++ 7 files changed, 63 insertions(+), 16 deletions(-) delete mode 100644 .versionrc create mode 100644 .versionrc.js create mode 100644 utils/remove_version_suffix.js diff --git a/.versionrc b/.versionrc deleted file mode 100644 index a0247ed4..00000000 --- a/.versionrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "releaseCommitMessageFormat": "chore(release): mark v{{currentTag}}" -} diff --git a/.versionrc.js b/.versionrc.js new file mode 100644 index 00000000..7fdd91b0 --- /dev/null +++ b/.versionrc.js @@ -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', + }, +}; diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 54bfb306..4910b39f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -276,8 +276,7 @@ node utils/bisect.js --good 686378 --bad 706915 script.js Releasing to npm consists of the following phases: 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 doc` to update the docs accordingly. + 1. Run `npm run release` to bump the version number in `package.json`, populate the changelog, and update the docs. 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**. - **WHY**: there are linters in place that help to avoid unnecessary errors, e.g. [like this](https://github.com/puppeteer/puppeteer/pull/2446) diff --git a/package.json b/package.json index 43e41a42..482f7997 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "test-install": "scripts/test-install.sh", "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", - "release": "standard-version" + "release": "node utils/remove_version_suffix.js && standard-version" }, "files": [ "lib/", @@ -105,11 +105,5 @@ "hooks": { "commit-msg": "commitlint --env HUSKY_GIT_PARAMS" } - }, - "standard-version": { - "skip": { - "commit": true, - "tag": true - } } } diff --git a/utils/doclint/cli.js b/utils/doclint/cli.js index 75775c65..2c83189c 100755 --- a/utils/doclint/cli.js +++ b/utils/doclint/cli.js @@ -26,6 +26,8 @@ const RED_COLOR = '\x1b[31m'; const YELLOW_COLOR = '\x1b[33m'; const RESET_COLOR = '\x1b[0m'; +const IS_RELEASE = Boolean(process.env.IS_RELEASE); + run(); async function run() { @@ -35,7 +37,7 @@ async function run() { const messages = []; let changedFiles = false; - if (!VERSION.endsWith('-post')) { + if (IS_RELEASE) { const versions = await Source.readFile( path.join(PROJECT_DIR, 'versions.js') ); @@ -132,5 +134,5 @@ async function run() { const runningTime = Date.now() - startTime; console.log(`DocLint Finished in ${runningTime / 1000} seconds`); - process.exit(clearExit ? 0 : 1); + process.exit(clearExit || IS_RELEASE ? 0 : 1); } diff --git a/utils/doclint/preprocessor/index.js b/utils/doclint/preprocessor/index.js index 340d973c..37d8254b 100644 --- a/utils/doclint/preprocessor/index.js +++ b/utils/doclint/preprocessor/index.js @@ -16,6 +16,8 @@ const Message = require('../Message'); +const IS_RELEASE = Boolean(process.env.IS_RELEASE); + module.exports.ensureReleasedAPILinks = function (sources, version) { // Release version is everything that doesn't include "-". 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) { // Release version is everything that doesn't include "-". - const isReleaseVersion = !version.includes('-'); + const isReleaseVersion = IS_RELEASE || !version.includes('-'); const messages = []; const commands = []; @@ -70,7 +72,7 @@ module.exports.runCommands = function (sources, version) { for (const command of commands) { let newText = null; 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') newText = isReleaseVersion ? '' : command.originalText; else if (command.name === 'toc') diff --git a/utils/remove_version_suffix.js b/utils/remove_version_suffix.js new file mode 100644 index 00000000..091a35ec --- /dev/null +++ b/utils/remove_version_suffix.js @@ -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);