Skip to content

Commit f382ed2

Browse files
committed
Improve Error Handling and Dependency Checks in build.sh
Although, the project says to have GO as a pre-req but having something to catch and check the dependency beforehand helps. Therefore, refactoring the script to add the check first before running to handle the script in a better way. Issue: The script does not check for Go installation before running go build. Fix: Added a dependency check to prevent build failures.
1 parent 76f9cea commit f382ed2

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

build.sh

+13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
#!/bin/bash
22

3+
# check if `go` is installed or not
4+
if ! command -v go &> /dev/null; then
5+
echo "Error: Go is not installed. Please install Go before running this script."
6+
exit 1
7+
fi
8+
39
BINFILE=watchtower
410
if [ -n "$MSYSTEM" ]; then
511
BINFILE=watchtower.exe
612
fi
713
VERSION=$(git describe --tags)
814
echo "Building $VERSION..."
915
go build -o $BINFILE -ldflags "-X github.com/containrrr/watchtower/internal/meta.Version=$VERSION"
16+
17+
if [ $? -ne 0 ]; then
18+
echo "Error: Build failed!"
19+
exit 1
20+
fi
21+
22+
echo "Build successful!"

0 commit comments

Comments
 (0)