Files
goplt/scripts/pre-commit-check.sh
0x1d a785cd73de
All checks were successful
CI / Test (pull_request) Successful in 53s
CI / Build (pull_request) Successful in 38s
CI / Format Check (pull_request) Successful in 2s
CI / Lint (pull_request) Successful in 26s
perf(ci): pre-install all tools in pre-commit Docker image
- Move Go 1.25.3 installation to Dockerfile
- Pre-install protobuf plugins and golangci-lint in image
- Set environment variables in Dockerfile
- Remove runtime installation steps from pre-commit script
- Significantly improves pre-commit check performance
2025-11-07 10:16:12 +01:00

58 lines
1.6 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 '📋 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