From d1dcd9aaaabe0f313fe79c79f9f51eaf63367154 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Thu, 20 Jun 2024 16:58:09 -0700 Subject: [PATCH] misc(release): fix lint issues in changelog script --- package.json | 1 + scripts/print-changelog.js | 102 +++++++++++++++++++------------------ yarn.lock | 36 ++++++++++--- 3 files changed, 83 insertions(+), 56 deletions(-) diff --git a/package.json b/package.json index 2b96b2fa0..e27f08821 100644 --- a/package.json +++ b/package.json @@ -85,6 +85,7 @@ "puppeteer": "^21.6.1", "puppeteer-core": "^21.6.1", "rimraf": "^3.0.2", + "shelljs": "^0.8.5", "sqlite3": "^5.1.2", "storybook": "^7.6.4", "ts-jest": "^29.1.1", diff --git a/scripts/print-changelog.js b/scripts/print-changelog.js index b62ae8764..74a61bfe9 100644 --- a/scripts/print-changelog.js +++ b/scripts/print-changelog.js @@ -1,3 +1,5 @@ +// @ts-nocheck + // https://github.com/patrickhulce/hulk /** The MIT License (MIT) @@ -23,6 +25,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +'use strict'; + const changelogLib = require('@patrickhulce/scripts/lib/shared/changelog.js'); const parseCommit = require('conventional-commits-parser').sync; const shelljs = require('shelljs'); @@ -30,66 +34,66 @@ const shelljs = require('shelljs'); const lastTag = process.argv[2]; const nextTag = process.argv[3]; -const GIT_BODY_DELIMITER = '______MARK_THE_BODY______' -const GIT_BODY = `${GIT_BODY_DELIMITER}"%B"${GIT_BODY_DELIMITER}` -const GIT_LOG_JSON_FORMAT = `{"hash": "%H", "date": "%aI", "subject": "%s", "body": ${GIT_BODY}}` +const GIT_BODY_DELIMITER = '______MARK_THE_BODY______'; +const GIT_BODY = `${GIT_BODY_DELIMITER}"%B"${GIT_BODY_DELIMITER}`; +const GIT_LOG_JSON_FORMAT = `{"hash": "%H", "date": "%aI", "subject": "%s", "body": ${GIT_BODY}}`; const RELEASE_TYPE = { - MAJOR: 2, - MINOR: 1, - PATCH: 0, -} + MAJOR: 2, + MINOR: 1, + PATCH: 0, +}; -const exec = cmd => shelljs.exec(cmd, {silent: true}) +const exec = cmd => shelljs.exec(cmd, {silent: true}); function getCommitsAndReleaseType(lastVersion) { - const commitRange = `${lastVersion.tag}...HEAD` - const flags = `--pretty=format:'${GIT_LOG_JSON_FORMAT}' --no-merges` - const command = `git log ${commitRange} ${flags}` - let logs = exec(command).stdout - // Replace all the newlines in the body so it's valid JSON - const regex = new RegExp(`${GIT_BODY_DELIMITER}"((.|[\n\r\f])*?)"${GIT_BODY_DELIMITER}}`, 'gim') - logs = logs.replace(regex, (s, body) => `"${body.replace(/\r?\n/g, '\\n')}"}`) - - const commits = logs - .split('\n') - .filter(Boolean) - .map(l => { - try { - return JSON.parse(l) - } catch (err) { - console.error('Unable to parse message:', l) - return undefined - } - }) - .filter(Boolean) - .map(commit => { - const parsed = parseCommit(commit.body) - parsed.hash = commit.hash - parsed.date = commit.date - - let releaseType = RELEASE_TYPE.PATCH - if (parsed.type === 'feat') releaseType = RELEASE_TYPE.MINOR - if (commit.body.includes('BREAKING CHANGE')) releaseType = RELEASE_TYPE.MAJOR - - return {...commit, releaseType, parsed} - }) - - const releaseType = commits.reduce( - (type, commit) => Math.max(type, commit.releaseType), - RELEASE_TYPE.PATCH, - ) - - return {releaseType, commits} - } + const commitRange = `${lastVersion.tag}...HEAD`; + const flags = `--pretty=format:'${GIT_LOG_JSON_FORMAT}' --no-merges`; + const command = `git log ${commitRange} ${flags}`; + let logs = exec(command).stdout; + // Replace all the newlines in the body so it's valid JSON + const regex = new RegExp(`${GIT_BODY_DELIMITER}"((.|[\n\r\f])*?)"${GIT_BODY_DELIMITER}}`, 'gim'); + logs = logs.replace(regex, (s, body) => `"${body.replace(/\r?\n/g, '\\n')}"}`); + + const commits = logs + .split('\n') + .filter(Boolean) + .map(l => { + try { + return JSON.parse(l); + } catch (err) { + console.error('Unable to parse message:', l); + return undefined; + } + }) + .filter(Boolean) + .map(commit => { + const parsed = parseCommit(commit.body); + parsed.hash = commit.hash; + parsed.date = commit.date; + + let releaseType = RELEASE_TYPE.PATCH; + if (parsed.type === 'feat') releaseType = RELEASE_TYPE.MINOR; + if (commit.body.includes('BREAKING CHANGE')) releaseType = RELEASE_TYPE.MAJOR; + + return {...commit, releaseType, parsed}; + }); + + const releaseType = commits.reduce( + (type, commit) => Math.max(type, commit.releaseType), + RELEASE_TYPE.PATCH + ); + + return {releaseType, commits}; +} const options = {}; const tag = nextTag; const lastVersion = {tag: lastTag}; const nextVersion = {tag}; const repository = { - owner: 'GoogleChrome', - name: 'lighthouse-ci', + owner: 'GoogleChrome', + name: 'lighthouse-ci', }; const {commits} = getCommitsAndReleaseType(lastVersion); changelogLib.get(options, {repository, lastVersion, nextVersion, commits, tag}).then(console.log); diff --git a/yarn.lock b/yarn.lock index a45be557c..dbaf4aa86 100644 --- a/yarn.lock +++ b/yarn.lock @@ -19584,7 +19584,7 @@ shell-quote@^1.6.1: resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.8.1.tgz#6dbf4db75515ad5bac63b4f1894c3a154c766680" integrity sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA== -shelljs@^0.8.1: +shelljs@^0.8.1, shelljs@^0.8.5: version "0.8.5" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c" integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow== @@ -20252,8 +20252,7 @@ string-to-arraybuffer@^1.0.0: atob-lite "^2.0.0" is-base64 "^0.1.0" -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: - name string-width-cjs +"string-width-cjs@npm:string-width@^4.2.0": version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -20279,6 +20278,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.2.3: + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + string-width@^3.0.0, string-width@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/string-width/-/string-width-3.1.0.tgz#22767be21b62af1081574306f69ac51b62203961" @@ -20402,8 +20410,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.1: - name strip-ansi-cjs +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -20438,6 +20445,13 @@ strip-ansi@^6.0.0: dependencies: ansi-regex "^5.0.0" +strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -22284,8 +22298,7 @@ world-calendars@^1.0.3: dependencies: object-assign "^4.1.0" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: - name wrap-ansi-cjs +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -22320,6 +22333,15 @@ wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"