Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add check for commit message format #56

Merged
merged 3 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Checkout code
uses: actions/checkout@v1
with:
fetch-depth: 1
fetch-depth: 0
- name: Test
run: |
scripts/alpine-setup.sh
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ $(RELEASE_DIR)/%-$(RELEASE_SUFFIX): $(PACKED_DIR)/%-$(BIN_ARCH)
$(TAR) -cvz --transform 's,$(PACKED_DIR)/$(*)-$(BIN_ARCH),$(*),gi' -f "$@" "$<"

## Run Go tests
test: generate test-fmt
test: generate test-fmt test-git
go test -coverprofile fmtcoverage.html ./...
.PHONY: test

Expand All @@ -108,6 +108,11 @@ test-fmt: generate
test -z "$$(go fmt ./...)"
.PHONY: test-fmt

## Check git commits formatting
test-git:
./scripts/git-check-commits.sh
.PHONY: test-git

## Clean build artifacts
clean:
rm -rf $(GENERATE_DIR)
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,36 @@ release-artifacts Create release artifacts
clean Clean build artifacts
```

### Commit messages

We enforce simple version of [Conventional Commits][cc] in the form:

```
<type>: <summary>

[optional body]

[optional footer(s)]
```

Where type is one of:
- **build** - Affects build and/or build system
- **chore** - Other non-functional changes
- **ci** - Affects CI (e.g. GitHub actions)
- **dep** - Dependency update
- **docs** - Documentation only change
- **feat** - A new feature
- **fix** - A bug fix
- **ref** - Code refactoring without functinality change
- **style** - Formatting changes
- **test** - Adding/changing tests

[cc]: https://www.conventionalcommits.org/

Use imperative, present tense (Add, not ~Added~), capitalize first letter of
summary, no dot at the and. The body and footer are optional. Relevant GitHub
issues should be referenced in the footer in the form `Fixes #123, fixes #456`.

## Issues and Contributions

Please open any issues and/or PRs against github.com/doitintl/kube-no-trouble repository.
Expand Down
19 changes: 19 additions & 0 deletions scripts/git-check-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
# Set strict error checking
set -emou pipefail

BASE_REF="origin/master"
COMMIT_TYPES="build|chore|ci|dep|docs|feat|fix|ref|style|test"
COMMIT_REGEXP="^(${COMMIT_TYPES}): [A-Z]+.{5,}[^.]$"


COMMITS_COUNT="$(git log --oneline --no-merges "${BASE_REF}..HEAD" | wc -l)"

echo "- Checking commit messages: ${COMMITS_COUNT} commits"

BAD_COMMITS="$(git log --oneline --no-merges -E --invert-grep --grep="${COMMIT_REGEXP}" "${BASE_REF}..HEAD")"
if [ -n "${BAD_COMMITS}" ]; then
echo "${BAD_COMMITS}"
echo "Error: commit messages do no confirm to required format: ${COMMIT_REGEXP}"
exit 1
fi