Skip to content

Commit bbaa624

Browse files
committed
misc(release): remove hulk from release process (mostly)
1 parent cdf4605 commit bbaa624

File tree

4 files changed

+2894
-60
lines changed

4 files changed

+2894
-60
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@chialab/esbuild-plugin-html": "^0.17.3",
33+
"@patrickhulce/scripts": "^0.4.0",
3334
"@storybook/addon-actions": "^7.6.4",
3435
"@storybook/addon-links": "^7.6.4",
3536
"@storybook/addon-storyshots": "^7.6.4",
@@ -57,6 +58,7 @@
5758
"@types/yargs": "^12.0.8",
5859
"@types/yargs-parser": "^11.0.0",
5960
"@typescript-eslint/parser": "^6.14.0",
61+
"conventional-commits-parser": "^3.0.0",
6062
"esbuild": "^0.19.9",
6163
"eslint": "^8.8.0",
6264
"eslint-config-google": "^0.14.0",

scripts/print-changelog.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// https://github.com/patrickhulce/hulk
2+
/**
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2018 Patrick Hulce <[email protected]> (https://patrickhulce.com/)
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
*/
25+
26+
const changelogLib = require('@patrickhulce/scripts/lib/shared/changelog.js');
27+
const parseCommit = require('conventional-commits-parser').sync;
28+
const shelljs = require('shelljs');
29+
30+
const lastTag = process.argv[2];
31+
const nextTag = process.argv[3];
32+
33+
const GIT_BODY_DELIMITER = '______MARK_THE_BODY______'
34+
const GIT_BODY = `${GIT_BODY_DELIMITER}"%B"${GIT_BODY_DELIMITER}`
35+
const GIT_LOG_JSON_FORMAT = `{"hash": "%H", "date": "%aI", "subject": "%s", "body": ${GIT_BODY}}`
36+
37+
const RELEASE_TYPE = {
38+
MAJOR: 2,
39+
MINOR: 1,
40+
PATCH: 0,
41+
}
42+
43+
const exec = cmd => shelljs.exec(cmd, {silent: true})
44+
45+
function getCommitsAndReleaseType(lastVersion) {
46+
const commitRange = `${lastVersion.tag}...HEAD`
47+
const flags = `--pretty=format:'${GIT_LOG_JSON_FORMAT}' --no-merges`
48+
const command = `git log ${commitRange} ${flags}`
49+
let logs = exec(command).stdout
50+
// Replace all the newlines in the body so it's valid JSON
51+
const regex = new RegExp(`${GIT_BODY_DELIMITER}"((.|[\n\r\f])*?)"${GIT_BODY_DELIMITER}}`, 'gim')
52+
logs = logs.replace(regex, (s, body) => `"${body.replace(/\r?\n/g, '\\n')}"}`)
53+
54+
const commits = logs
55+
.split('\n')
56+
.filter(Boolean)
57+
.map(l => {
58+
try {
59+
return JSON.parse(l)
60+
} catch (err) {
61+
console.error('Unable to parse message:', l)
62+
return undefined
63+
}
64+
})
65+
.filter(Boolean)
66+
.map(commit => {
67+
const parsed = parseCommit(commit.body)
68+
parsed.hash = commit.hash
69+
parsed.date = commit.date
70+
71+
let releaseType = RELEASE_TYPE.PATCH
72+
if (parsed.type === 'feat') releaseType = RELEASE_TYPE.MINOR
73+
if (commit.body.includes('BREAKING CHANGE')) releaseType = RELEASE_TYPE.MAJOR
74+
75+
return {...commit, releaseType, parsed}
76+
})
77+
78+
const releaseType = commits.reduce(
79+
(type, commit) => Math.max(type, commit.releaseType),
80+
RELEASE_TYPE.PATCH,
81+
)
82+
83+
return {releaseType, commits}
84+
}
85+
86+
const options = {};
87+
const tag = nextTag;
88+
const lastVersion = {tag: lastTag};
89+
const nextVersion = {tag};
90+
const repository = {
91+
owner: 'GoogleChrome',
92+
name: 'lighthouse-ci',
93+
};
94+
const {commits} = getCommitsAndReleaseType(lastVersion);
95+
changelogLib.get(options, {repository, lastVersion, nextVersion, commits, tag}).then(console.log);

scripts/release.sh

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#!/bin/bash
22

3+
if ! [ $# -eq 2 ]; then
4+
echo "Expected two args: CURRENT_VERSION NEXT_VERSION"
5+
echo "example: 0.12.0 0.13.0"
6+
exit 1
7+
fi
8+
39
set -euox pipefail
410

11+
CURRENT_VERSION=$1
12+
NEXT_VERSION=$2
13+
CURRENT_TAG="v$CURRENT_VERSION"
14+
NEXT_TAG="v$NEXT_VERSION"
15+
516
if [ -n "$(git status --porcelain)" ]; then
617
echo "Cannot release when there are pending changes!"
718
git status --porcelain
@@ -25,8 +36,16 @@ yarn clean
2536
yarn build
2637

2738
# Release
28-
hulk npm-publish --lerna
39+
# hulk npm-publish --lerna
40+
41+
yarn lerna publish '--force-publish=*' --exact --skip-git --repo-version=$NEXT_VERSION --npm-tag=$NEXT_TAG --yes
2942
git checkout lerna.json # lerna prettifies the JSON and isn't useful
43+
git tag "$NEXT_TAG"
44+
node ./scripts/print-changelog.js "$CURRENT_TAG" "$NEXT_TAG"
45+
echo "----"
46+
echo "Take the above changelog and add to GH release"
47+
48+
git push --tags
3049

3150
# Do related releases
3251
./scripts/deploy-gh-pages.sh

0 commit comments

Comments
 (0)