Skip to content

Commit

Permalink
feat(lint): add instructions and setup script for maven checklist
Browse files Browse the repository at this point in the history
  • Loading branch information
markkovari committed Jul 14, 2024
1 parent 517db4d commit a2220d3
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,20 @@ It was created with Vite
npm install vite@latest
```

## Contributing

### Precommit-hooks

This project uses precommit-hooks to ensure that the code is formatted correctly and that the tests pass before committing. To enable this, you need to install the precommit-hooks:

[:warning: **Important**] You need to have `maven` being installed in your machine to run the pre-commit hooks.
Although the project is using `maven-wrapper`, the pre-commit hooks are using the `mvn` command directly.
If the binary cannot be found please follow the instructions of the pre-commit hook to install `maven`.

To install the pre-commit hooks, run the following commands:

```bash
chmod +x ./setup-pre-commit-hook.sh
sh ./setup-pre-commit-hook.sh
```

18 changes: 18 additions & 0 deletions setup-pre-commit-hook.sh
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.
42 changes: 42 additions & 0 deletions utils/pre-commit
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

0 comments on commit a2220d3

Please sign in to comment.