This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PRE-COMMIT): add configured pre-commit hooks
- Loading branch information
1 parent
38ff447
commit fe3460b
Showing
18 changed files
with
509 additions
and
44 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,17 +1,27 @@ | ||
#!/bin/bash | ||
|
||
NAME=${1:-"Pro Buddy Dev"} | ||
EMAIL=${2:-"[email protected]"} | ||
# .github/scripts/template.sh | ||
# Perform automated templating. | ||
|
||
# 1: Optional TOML Formatting | ||
# 2: Git Username | ||
# 3: Git Email | ||
|
||
# CI only script. | ||
|
||
set -eo pipefail | ||
|
||
OPTIONAL_TOML_LINTING=${1:-"1"} | ||
NAME=${2:-"Pro Buddy Dev"} | ||
EMAIL=${3:-"[email protected]"} | ||
|
||
main() { | ||
|
||
git config --global user.name "${NAME}" | ||
git config --global user.email "${EMAIL}" | ||
|
||
echo -e '\n\n\n\n\n\n\n\n\n' | cookiecutter template/ | ||
echo -e "\n\n${OPTIONAL_TOML_LINTING}\n\n\n\n\n\n\n\n" | cookiecutter template/ | ||
|
||
} | ||
|
||
main | ||
main "$@" |
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#!/bin/bash | ||
|
||
# .github/scripts/test_precommit.sh | ||
# Performs tests on the pre-commit hooks. | ||
|
||
# 1: The name of a pre-commit test scenario. (See 'main' below.) | ||
# TEMPLATED_NAME: The name of the rendered test project. | ||
|
||
# CI only script. | ||
|
||
set -eo pipefail | ||
|
||
test_commit_lint() { | ||
util_git_reset | ||
touch empty_file.txt | ||
git stage empty_file.txt | ||
git commit -m 'test - pre-commit: improperly formatted commit' || exit 0 | ||
util_fail_test | ||
} | ||
|
||
test_molecule_lint() { | ||
util_git_reset | ||
echo "" >> tasks/main.yml | ||
git stage tasks/main.yml | ||
git commit -m 'test(PRE-COMMIT): fail due to ansible-lint' > error.log 2>&1 || grep "empty-lines" error.log > /dev/null && exit 0 | ||
util_fail_test | ||
} | ||
|
||
test_toml_lint_1() { | ||
util_git_reset | ||
sed -i.bak 's/authors =/ authors = /g' pyproject.toml | ||
git stage pyproject.toml | ||
git commit -m 'test(PRE-COMMIT): fail due to tomll' || exit 0 | ||
util_fail_test | ||
} | ||
|
||
test_toml_lint_2() { | ||
util_git_reset | ||
sed -i.bak 's/>=3.9.0,<4.0/>=3.9.1,<4.0/g' pyproject.toml | ||
git stage pyproject.toml | ||
git commit -m 'test(PRE-COMMIT): upgrade python without issue' | ||
} | ||
|
||
util_fail_test() { | ||
echo "This commit should have failed." | ||
exit 127 | ||
} | ||
|
||
util_git_reset() { | ||
git reset HEAD | ||
git clean -fd | ||
git checkout . | ||
} | ||
|
||
main() { | ||
|
||
pushd "${TEMPLATED_NAME}" | ||
case $1 in | ||
commit-lint) | ||
test_commit_lint | ||
;; | ||
molecule-lint) | ||
test_molecule_lint | ||
;; | ||
toml-lint-1) | ||
test_toml_lint_1 | ||
;; | ||
toml-lint-2) | ||
test_toml_lint_2 | ||
;; | ||
*) | ||
echo "Invalid test scenario." | ||
exit 127 | ||
;; | ||
esac | ||
popd | ||
|
||
} | ||
|
||
main "$@" |
Oops, something went wrong.