Skip to content

Commit

Permalink
ci: pre commit semantic commit msg check (#659)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahrar-deriv authored Jul 1, 2024
1 parent 701f453 commit 75e5c6c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

This repository contains private packages & plugins that are used by the company's products built in Flutter.

### <span style="color:green">GIT HOOK</span>

<span style="color:orange">Please run the below command to have the git hook installed.</span></br>
<span style="color:orange">This Hook will check for Semantic versioning commit convention</span></br>

```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:
Expand Down
28 changes: 28 additions & 0 deletions githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -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: <type>(<optional-scope>): <subject>"
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

0 comments on commit 75e5c6c

Please sign in to comment.