Skip to content

Commit

Permalink
misc(release): remove hulk from release process (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Jun 20, 2024
1 parent cdf4605 commit bbaa624
Show file tree
Hide file tree
Showing 4 changed files with 2,894 additions and 60 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@chialab/esbuild-plugin-html": "^0.17.3",
"@patrickhulce/scripts": "^0.4.0",
"@storybook/addon-actions": "^7.6.4",
"@storybook/addon-links": "^7.6.4",
"@storybook/addon-storyshots": "^7.6.4",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@types/yargs": "^12.0.8",
"@types/yargs-parser": "^11.0.0",
"@typescript-eslint/parser": "^6.14.0",
"conventional-commits-parser": "^3.0.0",
"esbuild": "^0.19.9",
"eslint": "^8.8.0",
"eslint-config-google": "^0.14.0",
Expand Down
95 changes: 95 additions & 0 deletions scripts/print-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// https://github.com/patrickhulce/hulk
/**
The MIT License (MIT)
Copyright (c) 2018 Patrick Hulce <[email protected]> (https://patrickhulce.com/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

const changelogLib = require('@patrickhulce/scripts/lib/shared/changelog.js');

Check failure on line 26 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Could not find a declaration file for module '@patrickhulce/scripts/lib/shared/changelog.js'. '/home/runner/work/lighthouse-ci/lighthouse-ci/node_modules/@patrickhulce/scripts/lib/shared/changelog.js' implicitly has an 'any' type.
const parseCommit = require('conventional-commits-parser').sync;

Check failure on line 27 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Could not find a declaration file for module 'conventional-commits-parser'. '/home/runner/work/lighthouse-ci/lighthouse-ci/node_modules/conventional-commits-parser/index.js' implicitly has an 'any' type.
const shelljs = require('shelljs');

Check failure on line 28 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Could not find a declaration file for module 'shelljs'. '/home/runner/work/lighthouse-ci/lighthouse-ci/node_modules/shelljs/shell.js' implicitly has an 'any' type.

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 RELEASE_TYPE = {
MAJOR: 2,
MINOR: 1,
PATCH: 0,
}

const exec = cmd => shelljs.exec(cmd, {silent: true})

Check failure on line 43 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'cmd' implicitly has an 'any' type.

function getCommitsAndReleaseType(lastVersion) {

Check failure on line 45 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'lastVersion' implicitly has an 'any' type.
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')}"}`)

Check failure on line 52 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 's' implicitly has an 'any' type.

Check failure on line 52 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'body' implicitly has an 'any' type.

const commits = logs
.split('\n')
.filter(Boolean)
.map(l => {

Check failure on line 57 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'l' implicitly has an 'any' type.
try {
return JSON.parse(l)
} catch (err) {
console.error('Unable to parse message:', l)
return undefined
}
})
.filter(Boolean)
.map(commit => {

Check failure on line 66 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'commit' implicitly has an 'any' type.
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),

Check failure on line 79 in scripts/print-changelog.js

View workflow job for this annotation

GitHub Actions / Linux

Parameter 'type' implicitly has an 'any' type.
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',
};
const {commits} = getCommitsAndReleaseType(lastVersion);
changelogLib.get(options, {repository, lastVersion, nextVersion, commits, tag}).then(console.log);
21 changes: 20 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
#!/bin/bash

if ! [ $# -eq 2 ]; then
echo "Expected two args: CURRENT_VERSION NEXT_VERSION"
echo "example: 0.12.0 0.13.0"
exit 1
fi

set -euox pipefail

CURRENT_VERSION=$1
NEXT_VERSION=$2
CURRENT_TAG="v$CURRENT_VERSION"
NEXT_TAG="v$NEXT_VERSION"

if [ -n "$(git status --porcelain)" ]; then
echo "Cannot release when there are pending changes!"
git status --porcelain
Expand All @@ -25,8 +36,16 @@ yarn clean
yarn build

# Release
hulk npm-publish --lerna
# hulk npm-publish --lerna

yarn lerna publish '--force-publish=*' --exact --skip-git --repo-version=$NEXT_VERSION --npm-tag=$NEXT_TAG --yes
git checkout lerna.json # lerna prettifies the JSON and isn't useful
git tag "$NEXT_TAG"
node ./scripts/print-changelog.js "$CURRENT_TAG" "$NEXT_TAG"
echo "----"
echo "Take the above changelog and add to GH release"

git push --tags

# Do related releases
./scripts/deploy-gh-pages.sh
Expand Down
Loading

0 comments on commit bbaa624

Please sign in to comment.