-
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(lint): add instructions and setup script for maven checklist
- Loading branch information
1 parent
517db4d
commit a2220d3
Showing
3 changed files
with
77 additions
and
0 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
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,18 @@ | ||
#!/bin/sh | ||
|
||
# This script is used to install a git pre-commit hook that will run the | ||
|
||
if [ -f .git/hooks/pre-commit ]; then | ||
echo "Pre-commit hook already exists, good job!" | ||
echo "If you want to re-install the hook, please remove the .git/hooks/pre-commit file first" | ||
exit 1 | ||
fi | ||
|
||
# Copy the pre-commit script to the .git/hooks directory | ||
cp ./utils/pre-commit .git/hooks/pre-commit | ||
# Make the script executable | ||
chmod +x .git/hooks/pre-commit | ||
|
||
echo "Pre-commit hook installed, you should be good to go" | ||
|
||
# Currently it is for backend, but we will add frontend as well. |
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,42 @@ | ||
#!/bin/sh | ||
|
||
## This script is used to run tests and checkstyle before commiting the code | ||
## If the tests or checkstyle fails, the commit will be aborted | ||
|
||
# Change to the backend directory | ||
cd backend | ||
|
||
# Check if there are any changes to commit | ||
|
||
if [ -z "$(git status --porcelain)" ]; then | ||
# Working directory clean, nothing to commit, not running things | ||
echo "No changes to commit in backend" | ||
else | ||
# Working directory not clean, running tests and checkstyle | ||
## Looking for maven binary | ||
if ! [ -x "$(command -v mvn)" ]; then | ||
## If maven not found, print error message and exit | ||
echo 'Error: maven is not installed.' >&2 | ||
echo 'Please install maven (with the recommended package managers) and try again' >&2 | ||
echo 'On mac, you can install maven using brew: brew install maven | ||
brew -> https://brew.sh/ | ||
maven -> brew install maven' >&2 | ||
echo 'on linux, you can install maven using apt: sudo apt install maven' >&2 | ||
echo 'on windows, you can install maven using chocolatey: choco install maven\ | ||
chocolatey -> https://chocolatey.org/ | ||
maven -> choco install maven' >&2 | ||
exit 1 | ||
else | ||
## If maven is found, run tests and checkstyle | ||
echo "Running tests and checkstyle" | ||
local maven_result = $(mvn clean install checkstyle:check) | ||
if [ $? -eq 0 ]; then | ||
echo "Tests and checkstyle passed, hopefully the watchdog will be happy too" | ||
else | ||
echo "Tests or checkstyle failed" | ||
echo "Please fix the issues and try again" | ||
echo "Aborting commit" | ||
exit 1 | ||
fi | ||
fi | ||
fi |