🤖 ci: optimize CI/CD with Docker cache and remove Buildx
This commit is contained in:
@@ -143,9 +143,6 @@ jobs:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
@@ -162,72 +159,40 @@ jobs:
|
||||
if docker pull "$IMAGE_NAME" >/dev/null 2>&1; then
|
||||
echo "✅ Using Docker build cache"
|
||||
echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV
|
||||
echo "CACHE_IMAGE=$IMAGE_NAME" >> $GITHUB_ENV
|
||||
else
|
||||
echo "⚠️ Building without cache (first run or new dependencies)"
|
||||
echo "CACHE_AVAILABLE=false" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.26.1'
|
||||
cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: go mod tidy
|
||||
|
||||
# SINGLE swag installation - reused for all steps
|
||||
- name: Install swag (once)
|
||||
run: go install github.com/swaggo/swag/cmd/swag@latest
|
||||
|
||||
- name: Version bump (main branch only)
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
# Analyze last commit message
|
||||
LAST_COMMIT=$(git log -1 --pretty=%B | head -1)
|
||||
|
||||
# Automatic version bump based on commit type
|
||||
if echo "$LAST_COMMIT" | grep -q "^✨ feat:"; then
|
||||
echo "🎯 Feature commit detected - bumping MINOR version"
|
||||
./scripts/version-bump.sh minor
|
||||
elif echo "$LAST_COMMIT" | grep -q "^🐛 fix:"; then
|
||||
echo "🐛 Fix commit detected - bumping PATCH version"
|
||||
./scripts/version-bump.sh patch
|
||||
elif echo "$LAST_COMMIT" | grep -q "BREAKING CHANGE"; then
|
||||
echo "💥 Breaking change detected - bumping MAJOR version"
|
||||
./scripts/version-bump.sh major
|
||||
else
|
||||
echo "⏭️ No automatic version bump needed"
|
||||
fi
|
||||
|
||||
- name: Generate Swagger Docs
|
||||
- name: Generate Swagger Docs using Docker cache
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker cache..."
|
||||
docker run --rm -v "$(pwd):/workspace" -w /workspace dance-lessons-coach-build-cache:latest sh -c "cd pkg/server && go generate"
|
||||
docker run --rm -v "$(pwd):/workspace" -w /workspace ${{ env.CACHE_IMAGE }} sh -c "cd pkg/server && go generate"
|
||||
else
|
||||
echo "Running natively..."
|
||||
cd pkg/server && go generate
|
||||
fi
|
||||
|
||||
- name: Build all packages
|
||||
- name: Build all packages using Docker cache
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker cache..."
|
||||
docker run --rm -v "$(pwd):/workspace" -w /workspace dance-lessons-coach-build-cache:latest sh -c "go build ./..."
|
||||
docker run --rm -v "$(pwd):/workspace" -w /workspace ${{ env.CACHE_IMAGE }} sh -c "go build ./..."
|
||||
else
|
||||
echo "Running natively..."
|
||||
go build ./...
|
||||
fi
|
||||
|
||||
- name: Run tests with coverage
|
||||
- name: Run tests with coverage using Docker cache
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker cache..."
|
||||
docker run --rm \
|
||||
-v "$(pwd):/workspace" \
|
||||
-w /workspace \
|
||||
dance-lessons-coach-build-cache:latest \
|
||||
${{ env.CACHE_IMAGE }} \
|
||||
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||
else
|
||||
echo "Running natively..."
|
||||
@@ -271,10 +236,6 @@ jobs:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
if: github.ref == 'refs/heads/main'
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push Docker image
|
||||
if: github.ref == 'refs/heads/main'
|
||||
run: |
|
||||
@@ -283,7 +244,9 @@ jobs:
|
||||
|
||||
TAGS="$IMAGE_VERSION latest ${{ github.sha }}"
|
||||
echo "Building Docker image with tags: $TAGS"
|
||||
docker build -t dance-lessons-coach .
|
||||
|
||||
# Use the production Dockerfile that leverages the build cache
|
||||
docker build -t dance-lessons-coach -f Dockerfile.prod .
|
||||
|
||||
for TAG in $TAGS; do
|
||||
IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}:$TAG"
|
||||
|
||||
Reference in New Issue
Block a user