From 75e5c6c4bc011582d2aba529dcd50e7dfcd60e65 Mon Sep 17 00:00:00 2001 From: Ahrar <98078754+ahrar-deriv@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:27:27 +0800 Subject: [PATCH] ci: pre commit semantic commit msg check (#659) --- README.md | 10 ++++++++++ githooks/commit-msg | 28 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 githooks/commit-msg diff --git a/README.md b/README.md index 54909d92e..264e735e6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,16 @@ This repository contains private packages & plugins that are used by the company's products built in Flutter. +### GIT HOOK + +Please run the below command to have the git hook installed.
+This Hook will check for Semantic versioning commit convention
+ +```BASH +curl --fail -o $HOME/.git/hooks/commit-msg https://raw.githubusercontent.com/regentmarkets/flutter-deriv-packages/master/githooks/commit-msg \ + && chmod +x $HOME/.git/hooks/commit-msg +``` + ## Using the packages Each package has been released as git tag with convention as **packageName-vVersionNumber**`(Example: deriv_auth-v6.7.7)`. To use the package, add the following to your pubspec.yaml file: diff --git a/githooks/commit-msg b/githooks/commit-msg new file mode 100755 index 000000000..096e4d223 --- /dev/null +++ b/githooks/commit-msg @@ -0,0 +1,28 @@ +#!/bin/sh + +if [ -z "$1" ]; then + echo "Missing argument (commit message). Did you try to run this manually?" + exit 1 +fi + +commitTitle="$(cat $1 | head -n1)" + +# ignore merge requests +if echo "$commitTitle" | grep -qE "Merge branch"; then + echo "Commit hook: ignoring branch merge" + exit 0 +fi +# check semantic versioning scheme +if ! echo "$commitTitle" | grep -qE '^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert)(\([a-z0-9\s\-\_\,]+\))?!?:\s\w'; then + echo "Your commit message did not follow semantic versioning: $commitTitle" + echo "" + echo "Format: (): " + echo "Example: feat(deriv-auth): single entry" + echo "" + echo "Valid types: build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test" + echo "" + echo "Please see" + echo "- https://github.com/regentmarkets/flutter-deriv-packages/blob/master/.github/GIT_RULES.md" + echo "- https://www.conventionalcommits.org/en/v1.0.0/#summary" + exit 1 +fi