🔄 fix: simplify Docker cache approach and integrate properly
This commit is contained in:
@@ -137,11 +137,19 @@ jobs:
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||
|
||||
- name: Pull Docker build cache
|
||||
- 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 "Using build cache image: $IMAGE_NAME"
|
||||
docker pull "$IMAGE_NAME" || echo "Cache pull failed, will use regular setup"
|
||||
echo "Build cache image: $IMAGE_NAME"
|
||||
|
||||
# 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
|
||||
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
|
||||
@@ -157,16 +165,39 @@ jobs:
|
||||
run: go install github.com/swaggo/swag/cmd/swag@latest
|
||||
|
||||
- name: Generate Swagger Docs
|
||||
run: cd pkg/server && go generate
|
||||
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"
|
||||
else
|
||||
echo "Running natively..."
|
||||
cd pkg/server && go generate
|
||||
fi
|
||||
|
||||
- name: Build all packages
|
||||
run: go build ./...
|
||||
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 ./..."
|
||||
else
|
||||
echo "Running natively..."
|
||||
go build ./...
|
||||
fi
|
||||
|
||||
- name: Run tests with coverage
|
||||
run: |
|
||||
# Run tests with coverage
|
||||
go test ./... -coverprofile=coverage.out -v
|
||||
go tool cover -func=coverage.out > coverage.txt
|
||||
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 test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
|
||||
else
|
||||
echo "Running natively..."
|
||||
go test ./... -coverprofile=coverage.out -v
|
||||
go tool cover -func=coverage.out > coverage.txt
|
||||
fi
|
||||
|
||||
# Extract coverage percentage
|
||||
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||
|
||||
Reference in New Issue
Block a user