🔧 refactor: simplify CI/CD workflow by removing redundant cache checks
- Remove duplicate steps section - Eliminate redundant cache availability checks - Simplify logic since build-cache job guarantees cache availability - Remove unnecessary conditional execution - Streamline Docker Compose usage Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -151,69 +151,29 @@ jobs:
|
||||
echo "❌ PostgreSQL failed to start"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ env.CI_REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||
|
||||
- name: Set up build environment
|
||||
run: |
|
||||
IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }}"
|
||||
echo "Build cache image: $IMAGE_NAME"
|
||||
echo "CACHE_IMAGE=$IMAGE_NAME" >> $GITHUB_ENV
|
||||
|
||||
# Try to use Docker cache if available
|
||||
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: Check dependencies
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "✅ Using pre-installed dependencies from Docker cache"
|
||||
# No need to run go mod tidy - dependencies are already in the cache
|
||||
else
|
||||
echo "Running natively - ensuring dependencies are up to date..."
|
||||
go mod tidy
|
||||
fi
|
||||
# Cache is guaranteed to be available since build-cache job succeeded
|
||||
echo "✅ Using Docker build cache (guaranteed by build-cache job)"
|
||||
echo "CACHE_AVAILABLE=true" >> $GITHUB_ENV
|
||||
|
||||
- name: Start build cache container with Docker Compose
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Starting build cache container..."
|
||||
export DEPS_HASH="${{ needs.build-cache.outputs.deps_hash }}"
|
||||
docker compose -f docker-compose.build.yml up -d build-cache
|
||||
fi
|
||||
echo "Starting build cache container..."
|
||||
export DEPS_HASH="${{ needs.build-cache.outputs.deps_hash }}"
|
||||
docker compose -f docker-compose.build.yml up -d build-cache
|
||||
|
||||
- name: Generate Swagger Docs using Docker Compose
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker Compose container..."
|
||||
docker compose -f docker-compose.build.yml exec -w /workspace/pkg/server build-cache sh -c "go generate"
|
||||
else
|
||||
echo "Running natively..."
|
||||
cd pkg/server && go generate
|
||||
fi
|
||||
run: docker compose -f docker-compose.build.yml exec -w /workspace/pkg/server build-cache sh -c "go generate"
|
||||
|
||||
- name: Build all packages using Docker Compose
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker Compose container..."
|
||||
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
|
||||
else
|
||||
echo "Running natively..."
|
||||
go build ./...
|
||||
fi
|
||||
run: docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
|
||||
|
||||
|
||||
- name: Wait for PostgreSQL to be ready
|
||||
run: |
|
||||
@@ -235,27 +195,16 @@ jobs:
|
||||
|
||||
- name: Run tests with coverage using Docker Compose
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker Compose container with PostgreSQL..."
|
||||
docker compose -f docker-compose.build.yml exec \
|
||||
-e PGHOST=dance-lessons-coach-postgres \
|
||||
-e PGPORT=5432 \
|
||||
-e PGUSER=postgres \
|
||||
-e PGPASSWORD=postgres \
|
||||
-e PGDATABASE=dance_lessons_coach_bdd_test \
|
||||
-w /workspace \
|
||||
build-cache \
|
||||
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||
else
|
||||
echo "Running natively with Docker Compose PostgreSQL..."
|
||||
export PGHOST=dance-lessons-coach-postgres
|
||||
export PGPORT=5432
|
||||
export PGUSER=postgres
|
||||
export PGPASSWORD=postgres
|
||||
export PGDATABASE=dance_lessons_coach_bdd_test
|
||||
go test ./... -coverprofile=coverage.out -v
|
||||
go tool cover -func=coverage.out > coverage.txt
|
||||
fi
|
||||
echo "Running in Docker Compose container with PostgreSQL..."
|
||||
docker compose -f docker-compose.build.yml exec \
|
||||
-e PGHOST=dance-lessons-coach-postgres \
|
||||
-e PGPORT=5432 \
|
||||
-e PGUSER=postgres \
|
||||
-e PGPASSWORD=postgres \
|
||||
-e PGDATABASE=dance_lessons_coach_bdd_test \
|
||||
-w /workspace \
|
||||
build-cache \
|
||||
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||
|
||||
# Extract coverage percentage
|
||||
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||
@@ -273,14 +222,7 @@ jobs:
|
||||
run: swag fmt
|
||||
|
||||
- name: Build binaries
|
||||
run: |
|
||||
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||
echo "Running in Docker Compose container..."
|
||||
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh"
|
||||
else
|
||||
echo "Running natively..."
|
||||
./scripts/build.sh
|
||||
fi
|
||||
run: docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh"
|
||||
|
||||
# NOTE: Artifact upload disabled - actions/upload-artifact@v4 not available on Gitea
|
||||
# TODO: Replace with Gitea-specific upload action when available
|
||||
|
||||
Reference in New Issue
Block a user