Skip to content

Commit

Permalink
Propagate pre-commit errors when running go commands (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Apr 29, 2024
1 parent a89f080 commit dff640d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions .githooks/go-lint
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#!/bin/bash

# Find all 'go.mod' files, get their directories, and run 'go mod tidy'
# shellcheck disable=SC2016
find "./" -type f -name 'go.mod' -print0 | xargs -0 -I{} bash -c '
directory=$(dirname "{}")
find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do
directory=$(dirname "$file")
cd "$directory" || exit 1

# Run linter and capture exit status
golangci-lint run > /dev/null
local linting_result=$?
golangci-lint run > /dev/null
linting_result=$?

# Check linting result
if [[ $linting_result -ne 0 ]]; then
Expand All @@ -18,4 +17,5 @@ find "./" -type f -name 'go.mod' -print0 | xargs -0 -I{} bash -c '
else
echo -e "Executing linters in $directory... \e[32mOK!\e[0m\n"
fi
'
cd - || exit 1
done
8 changes: 4 additions & 4 deletions .githooks/go-mod-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
set -e

# Find all 'go.mod' files, get their directories, and run 'go mod tidy'
# shellcheck disable=SC2016
find "./" -type f -name 'go.mod' -print0 | xargs -0 -I{} bash -c '
dir=$(dirname "{}")
find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do
dir=$(dirname "$file")
echo "Executing cd \"$dir\" && go mod tidy"
cd "$dir"
go mod tidy
'
cd -
done
# pre-commit stashes changes before running the hooks so we can use git to check for changes here
# Run git diff and capture output
output=$(git diff --stat)
Expand Down
8 changes: 4 additions & 4 deletions .githooks/go-test-build
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
set -e

# Find all 'go.mod' files, get their directories, and run an empty 'go test' in them to compile the tests.
# shellcheck disable=SC2016
find "./" -type f -name 'go.mod' -print0 | xargs -0 -I{} bash -c '
dir=$(dirname "{}")
find "./" -type f -name 'go.mod' -print0 | while IFS= read -r -d $'\0' file; do
dir=$(dirname "$file")
echo "Executing cd \"$dir\" && go test -run=^# ./..."
cd "$dir"
go test -run=^# ./...
'
cd -
done

0 comments on commit dff640d

Please sign in to comment.