-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
219 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: pre-commit checks | ||
name: check Python 3.5 compatibility | ||
on: [push, pull_request] | ||
jobs: | ||
pre-commit: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,63 @@ | ||
PRECOMMIT_VERSION=2.13.0 | ||
PRECOMMIT_VERSION = 2.17.0 | ||
|
||
PRECOMMIT_ENV := $(shell git rev-parse --git-dir 2>/dev/null || echo ".")/.pre-commit_env | ||
|
||
no-default: | ||
@echo "There is no default target. Please choose one of the following targets: check, git-hooks-install" | ||
@exit 1 | ||
|
||
check-git: | ||
@if ! command -v git >/dev/null 2>&1; then \ | ||
>&2 echo "Please install Git first."; \ | ||
exit 1; \ | ||
fi | ||
@if ! git rev-parse --git-dir >/dev/null 2>&1; then \ | ||
>&2 echo "You are not in a Git repository, but pre-commit requires this."; \ | ||
>&2 echo "Is this an unpacked source code archive?"; \ | ||
exit 1; \ | ||
fi | ||
|
||
check-python: | ||
@if ! command -v python3 >/dev/null 2>&1; then \ | ||
>&2 echo "Please install Python 3 first."; \ | ||
exit 1; \ | ||
fi; | ||
fi | ||
@if ! python3 -m venv --help >/dev/null 2>&1; then \ | ||
>&2 echo "Please install the Python 3 venv module."; \ | ||
exit 1; \ | ||
fi; | ||
fi | ||
|
||
check: check-python | ||
install-pre-commit: check-git check-python | ||
@if ! [ -d "$(PRECOMMIT_ENV)" ] || ! "$(PRECOMMIT_ENV)/bin/python" --version >/dev/null 2>&1; then \ | ||
echo "Installing pre-commit to \"$(PRECOMMIT_ENV)\"" && \ | ||
rm -rf "$(PRECOMMIT_ENV)" && \ | ||
python3 -m venv "$(PRECOMMIT_ENV)" && \ | ||
"$(PRECOMMIT_ENV)/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" || exit; \ | ||
fi | ||
|
||
check: install-pre-commit | ||
@TMP_PRECOMMIT_DIR="$$(mktemp -d 2>/dev/null || mktemp -d -t 'tmp' 2>/dev/null)" && \ | ||
python3 -m venv "$${TMP_PRECOMMIT_DIR}" && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" && \ | ||
git log -1 --pretty=%B > "$${TMP_PRECOMMIT_DIR}/commit_msg" && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage commit && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage commit-msg \ | ||
"$(PRECOMMIT_ENV)/bin/pre-commit" run \ | ||
--all-files \ | ||
--show-diff-on-failure \ | ||
--hook-stage commit && \ | ||
"$(PRECOMMIT_ENV)/bin/pre-commit" run \ | ||
--all-files \ | ||
--show-diff-on-failure \ | ||
--hook-stage commit-msg \ | ||
--commit-msg-filename "$${TMP_PRECOMMIT_DIR}/commit_msg" && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" run --all-files --hook-stage post-commit && \ | ||
rm -rf "$${TMP_PRECOMMIT_DIR}" | ||
"$(PRECOMMIT_ENV)/bin/pre-commit" run \ | ||
--all-files \ | ||
--show-diff-on-failure \ | ||
--hook-stage post-commit; \ | ||
RETURN_CODE="$$?"; \ | ||
rm -rf "$${TMP_PRECOMMIT_DIR}"; \ | ||
exit "$${RETURN_CODE}" | ||
|
||
git-hooks-install: check-python | ||
@TMP_PRECOMMIT_DIR="$$(mktemp -d 2>/dev/null || mktemp -d -t 'tmp' 2>/dev/null)" && \ | ||
python3 -m venv "$${TMP_PRECOMMIT_DIR}" && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pip" install "pre-commit==$(PRECOMMIT_VERSION)" && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type pre-commit && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type commit-msg && \ | ||
"$${TMP_PRECOMMIT_DIR}/bin/pre-commit" install --hook-type post-commit && \ | ||
rm -rf "$${TMP_PRECOMMIT_DIR}" | ||
|
||
.PHONY: no-default check-python check git-hooks-install | ||
git-hooks-install: install-pre-commit | ||
@"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type pre-commit && \ | ||
"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type commit-msg && \ | ||
"$(PRECOMMIT_ENV)/bin/pre-commit" install --hook-type post-commit | ||
|
||
.PHONY: no-default check-git check-python check git-hooks-install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.