Skip to content

Commit

Permalink
chore(CI): Enforce semantic commits inside CI 👮‍♂️
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Jun 8, 2018
1 parent 5dcbc48 commit 7fe18e5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ before_script:
- git remote set-url --push origin https://${GITHUB_TOKEN}@github.com/ivanilves/lstags.git

script:
- make build
- make lint
- make vet
- make build
- if [[ "${TRAVIS_PULL_REQUEST}" == "true" ]]; then make semantic RANGE=$(scripts/travis_range.sh); fi
- make stress-test-async CONCURRENT_REQUESTS=128
- make coverage
- make blackbox-integration-test
Expand Down
14 changes: 12 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ lint: fail-on-errors
vet: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -I {} go tool vet {} | tr '`' '|')
vet: fail-on-errors

semantic: REGEX:="^(feat|fix|docs|style|refactor|test|chore)(\([a-zA-Z0-9\_\-\/]+\))?: [A-Z]"
semantic:
@if [[ -n "${RANGE}" ]]; then \
git log --pretty="format:%s" ${RANGE} \
| egrep -v ${REGEX} | awk '{print "NON-SEMANTIC: "$$0}' | grep . \
&& echo -e "\e[1m\e[31mFATAL: Non-semantic commit messages found (${RANGE})!\e[0m" && exit 1 || echo "OK"; \
else \
echo -e "\e[33mERROR: Please define 'RANGE' variable!\e[0m"; exit 1; \
fi

fail-on-errors:
@echo "${ERRORS}" | grep . || echo "OK"
@test `echo "${ERRORS}" | grep . | wc -l` -eq 0
Expand Down Expand Up @@ -147,8 +157,8 @@ deploy-github:
@if [[ "${DO_RELEASE}" == "true" ]]; then \
${MAKE} --no-print-directory validate-release \
&& test -n "${GITHUB_TOKEN}" && git tag ${TAG} && git push --tags \
&& GITHUB_TOKEN=${GITHUB_TOKEN} ./scripts/github-create-release.sh ./dist/release \
&& GITHUB_TOKEN=${GITHUB_TOKEN} ./scripts/github-upload-assets.sh ${TAG} ./dist/assets; \
&& GITHUB_TOKEN=${GITHUB_TOKEN} scripts/github-create-release.sh ./dist/release \
&& GITHUB_TOKEN=${GITHUB_TOKEN} scripts/github-upload-assets.sh ${TAG} ./dist/assets; \
else \
echo "NB! GitHub release skipped! (DO_RELEASE != true)"; \
fi
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,13 @@ CHANGED sha256:aa96c8dc3815c44d4aceaf1ee7903ce58 37c7be7a096b 2017-10-25T2
**You are very welcome to open pull requests to this repository!** :wink:
:warning: CI build will fail, if your commit messages are not **[semantic](https://github.com/fteem/git-semantic-commits)**!
To maximize our collaboration efficiency we would humbly ask you to follow these recommendations:
* Please add reasonable description (what?/why?/etc) to your pull request :exclamation:
* Your code should pass CI (Travis) and a [pretty liberal] code review :mag:
* If code adds or changes some logic, it should be covered by a unit test :neckbeard:
* Please, please, please: Put meaningful messages on your commits :pray:
* Please, put meaningful and [semantic](https://github.com/fteem/git-semantic-commits) messages on your commits :pray:
**NB!** Not a requirement, but a GIF included in PR description would make our world a happier place!
Expand Down
12 changes: 12 additions & 0 deletions scripts/travis_range.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
#
if [[ "${TRAVIS}" != "true" ]]; then
echo "FATAL: This should NOT be run outside Travis!"
exit 1
fi

if [[ "${TRAVIS_PULL_REQUEST}" == "true" ]]; then
echo ${TRAVIS_BRANCH}...HEAD
else
echo ${TRAVIS_COMMIT_RANGE}
fi

0 comments on commit 7fe18e5

Please sign in to comment.