78 lines
2.5 KiB
Bash
Executable File
78 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# Pre-commit check script that runs lint, fmt-check, test, and build in gitea-runner container
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
|
|
IMAGE_NAME="wirelos/pre-commit"
|
|
CONTAINER_NAME="goplt-pre-commit-check"
|
|
|
|
echo "🔍 Checking for Docker image: $IMAGE_NAME"
|
|
if ! docker images --format "{{.Repository}}:{{.Tag}}" | grep -q "^${IMAGE_NAME}:latest$"; then
|
|
echo "📦 Image not found. Building $IMAGE_NAME from ci/pre-commit/Dockerfile..."
|
|
docker build -t "$IMAGE_NAME:latest" -f "$PROJECT_ROOT/ci/pre-commit/Dockerfile" "$PROJECT_ROOT/ci/pre-commit" || {
|
|
echo "❌ Failed to build Docker image"
|
|
exit 1
|
|
}
|
|
echo "✅ Image built successfully"
|
|
else
|
|
echo "✅ Image found locally"
|
|
fi
|
|
|
|
echo "🧹 Cleaning up any existing container..."
|
|
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
|
|
|
echo "🚀 Starting pre-commit container..."
|
|
docker run --rm \
|
|
--name "$CONTAINER_NAME" \
|
|
-v "$PROJECT_ROOT:/workspace" \
|
|
-w /workspace \
|
|
"$IMAGE_NAME:latest" \
|
|
sh -c "
|
|
echo '📦 Installing Go 1.25.3 and required tools...'
|
|
apk add --no-cache protobuf protobuf-dev bash git wget tar || exit 1
|
|
|
|
# Install Go 1.25.3
|
|
cd /tmp && \
|
|
wget -q https://go.dev/dl/go1.25.3.linux-amd64.tar.gz && \
|
|
tar -C /usr/local -xzf go1.25.3.linux-amd64.tar.gz && \
|
|
rm go1.25.3.linux-amd64.tar.gz || exit 1
|
|
|
|
export PATH=/usr/local/go/bin:\$PATH:/root/go/bin
|
|
export GOROOT=/usr/local/go
|
|
export GOPATH=/root/go
|
|
|
|
echo '📥 Installing Go protobuf plugins...'
|
|
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest || exit 1
|
|
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest || exit 1
|
|
|
|
echo '📥 Installing golangci-lint...'
|
|
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /root/go/bin || exit 1
|
|
|
|
echo '📋 Running make fmt-check...'
|
|
make fmt-check || exit 1
|
|
|
|
echo '🔍 Running make lint...'
|
|
make lint || exit 1
|
|
|
|
echo '🧪 Running make test...'
|
|
make test || exit 1
|
|
|
|
echo '🔨 Running make build...'
|
|
make build || exit 1
|
|
|
|
echo '✅ All checks passed!'
|
|
"
|
|
|
|
EXIT_CODE=$?
|
|
|
|
if [ $EXIT_CODE -eq 0 ]; then
|
|
echo "✅ All pre-commit checks passed!"
|
|
else
|
|
echo "❌ Pre-commit checks failed. Please fix the issues above."
|
|
fi
|
|
|
|
exit $EXIT_CODE
|
|
|