Skip to content

Commit

Permalink
refactor: switch the git hook pre-commit to use docker instead of a w…
Browse files Browse the repository at this point in the history
…ild wayne
  • Loading branch information
chrispelzer committed Apr 18, 2024
1 parent c7cf017 commit 0530cca
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions hooks/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#!/bin/bash

# Run on either wild wayne or local machine
wild_wayne_test=${WILD_WAYNE}
# Run the pre-commit hook to check for any errors before committing
# ${DOCKER_ENV} comes from the environment variables in the docker-compose.yml file for the wsu docker container
docker_test=${DOCKER_ENV}

# Current working directory of the site
site_folder=${PWD##*/}

export PATH=/usr/local/bin:$PATH
echo "Folder: ${site_folder}";

# Make sure vagrant command is found
if [ "$wild_wayne_test" != "true" ]; then
if hash vagrant 2>/dev/null; then
printf "vagrant command found...\n"
if [ "${docker_test}" != "true" ]; then
if [ "$(which docker)" != "" ]; then
printf "docker command found...\n"
else
printf "Vagrant command could not be found. If you plan to develop without using vagrant then delete this check.\n"
printf "Docker command could not be found. If you plan to develop without using docker then delete this check.\n"
exit 1
fi
fi
Expand All @@ -28,12 +30,12 @@ if [[ "$branch" == "master" ]]; then
fi

# PHP linting
if [ "$wild_wayne_test" = "true" ]; then
if [ "${docker_test}" = "true" ]; then
printf "Running phplint...\n"
phplint="$(make phplintdry)"
else
printf "Running phplint...\n"
phplint="$(vagrant ssh -c "cd /vagrant/${site_folder}; make phplintdry")"
phplint="$(docker exec -i wsu-${site_folder} bash -i -c "make phplintdry")"
fi

# Check if the last command (PHPLint) didn't exit with a 0 success
Expand All @@ -44,12 +46,12 @@ if (( $? != 0 )); then
fi

# Style linting
if [ "$wild_wayne_test" = "true" ]; then
if [ "${docker_test}" = "true" ]; then
printf "Running stylelint...\n"
stylelint="$(make stylelint)"
else
printf "Running stylelint...\n"
stylelint="$(vagrant ssh -c "cd /vagrant/${site_folder}; make stylelint")"
stylelint="$(docker exec -i wsu-${site_folder} bash -i -c "make stylelint")"
fi

# Check if the last command (Stylelint) didn't exit with a 0 success
Expand All @@ -60,12 +62,12 @@ if (( $? != 0 )); then
fi

# PHP tests
if [ "$wild_wayne_test" = "true" ]; then
if [ "${docker_test}" = "true" ]; then
printf "Running tests...\n"
phpunit="$(phpunit)"
else
printf "Running tests...\n"
phpunit="$(vagrant ssh -c "cd /vagrant/${site_folder}; phpunit")"
phpunit="$(docker exec -i wsu-${site_folder} bash -i -c "phpunit")"
fi

# Check if the last command (PHPUnit) didn't exit with a 0 success
Expand Down

0 comments on commit 0530cca

Please sign in to comment.