Skip to content

Commit

Permalink
build: Add vendorcheck target
Browse files Browse the repository at this point in the history
This ensures `vendor` does not get out of sync
  • Loading branch information
cfergeau committed Jun 13, 2024
1 parent 97b9544 commit df5712d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ include tools/tools.mk

cross: bin/macadam-darwin-amd64 bin/macadam-darwin-arm64 bin/macadam-linux-amd64 bin/macadam-linux-arm64 bin/macadam-windows-amd64

check: lint test
check: lint vendorcheck test

test: build
@go test -v ./pkg/...
Expand Down Expand Up @@ -52,6 +52,15 @@ bin/macadam-windows-amd64: force-build
lint: $(TOOLS_BINDIR)/golangci-lint
@"$(TOOLS_BINDIR)"/golangci-lint run

.PHONY: vendor
vendor:
go mod tidy
go mod vendor

.PHONY: vendorcheck
vendorcheck:
./build-scripts/verify-vendor.sh

# the go compiler is doing a good job at not rebuilding unchanged files
# this phony target ensures bin/macadam-* are always considered out of date
# and rebuilt. If the code was unchanged, go won't rebuild anything so that's
Expand Down
25 changes: 25 additions & 0 deletions build-scripts/verify-vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

if [[ -n $(git status -s vendor/) ]]; then
echo 'vendor/ directory has uncommitted changes, please check `git status vendor`'
exit 1
fi

make vendor

go mod verify

echo "Diffing $(pwd)"
git diff --exit-code vendor go.mod go.sum

if [[ $? -eq 0 ]]
then
echo "$(pwd) is up to date."
else
echo "$(pwd) is out of date. Please run make vendor"
exit 1
fi

0 comments on commit df5712d

Please sign in to comment.