From 0b6e40bbaef98d94687c088cc69b44229bbb6a79 Mon Sep 17 00:00:00 2001 From: Andrew Polk Date: Fri, 20 Sep 2024 15:36:36 -0700 Subject: [PATCH] chore: Very basic commit message validation for semantic-release --- .husky/.gitignore | 1 + .husky/commit-msg | 23 +++++++++++++++++++++++ package.json | 4 +++- yarn.lock | 5 +++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .husky/.gitignore create mode 100644 .husky/commit-msg diff --git a/.husky/.gitignore b/.husky/.gitignore new file mode 100644 index 00000000..31354ec1 --- /dev/null +++ b/.husky/.gitignore @@ -0,0 +1 @@ +_ diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 00000000..81c73270 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,23 @@ +#!/bin/bash +. "$(dirname "$0")/_/husky.sh" + +# Ideally, we might want to use a package like commitizen or commitlint, +# but as far as I can tell, those don't work with GUI git clients like GitKraken. +# And they are actually overkill for what we need here (though we could custom configure them). + +# Read the commit message from the file passed as an argument +COMMIT_MSG=$(cat "$1") + +# Check if the commit message contains a colon. +# This is a super basic validation and could certainly be improved. +if ! echo "$COMMIT_MSG" | grep -q ":"; then + echo "Improper commit message for semantic-release." + echo "Please use the format 'type: message'" + echo "e.g. chore: Updated README" + echo "e.g. fix: Made a repair" + echo "e.g. feat: Added a new thing" + exit 1 +fi + +# If we reach here, the commit message is valid +exit 0 diff --git a/package.json b/package.json index bc3d48ae..699a6d4d 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,8 @@ "build-dev": "shx rm -rf dist/ && webpack --config webpack.config.js", "tslint": "tslint --project tsconfig.json", "test": "jest", - "test-storybook": "test-storybook --url http://localhost:9009" + "test-storybook": "test-storybook --url http://localhost:9009", + "prepare": "husky install" }, "dependencies": { "@material-ui/core": "^4.12.3", @@ -77,6 +78,7 @@ "file-loader": "^3.0.1", "globule": "^1.2.1", "html-webpack-plugin": "^3.2.0", + "husky": "8", "jest": "^27.4.7", "jest-teamcity-reporter": "^0.9.0", "jest-transform-css": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index 2133a523..cf263e12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10235,6 +10235,11 @@ humanize-ms@^1.2.1: dependencies: ms "^2.0.0" +husky@8: + version "8.0.3" + resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" + integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== + hyphenate-style-name@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.3.tgz#097bb7fa0b8f1a9cf0bd5c734cf95899981a9b48"