🔄 fix: simplify Docker cache approach and integrate properly
This commit is contained in:
@@ -137,11 +137,19 @@ jobs:
|
|||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
password: ${{ secrets.PACKAGES_TOKEN }}
|
password: ${{ secrets.PACKAGES_TOKEN }}
|
||||||
|
|
||||||
- name: Pull Docker build cache
|
- name: Set up build environment
|
||||||
run: |
|
run: |
|
||||||
IMAGE_NAME="${{ env.CI_REGISTRY }}/${{ env.GITEA_ORG }}/${{ env.GITEA_REPO }}-build-cache:${{ needs.build-cache.outputs.deps_hash }}"
|
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"
|
echo "Build cache image: $IMAGE_NAME"
|
||||||
docker pull "$IMAGE_NAME" || echo "Cache pull failed, will use regular setup"
|
|
||||||
|
# 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
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v4
|
||||||
@@ -157,16 +165,39 @@ jobs:
|
|||||||
run: go install github.com/swaggo/swag/cmd/swag@latest
|
run: go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
|
|
||||||
- name: Generate Swagger Docs
|
- 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
|
- 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
|
- name: Run tests with coverage
|
||||||
run: |
|
run: |
|
||||||
# Run tests with coverage
|
if [ "${{ env.CACHE_AVAILABLE }}" = "true" ]; then
|
||||||
go test ./... -coverprofile=coverage.out -v
|
echo "Running in Docker cache..."
|
||||||
go tool cover -func=coverage.out > coverage.txt
|
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
|
# Extract coverage percentage
|
||||||
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
|
||||||
|
|||||||
@@ -31,9 +31,16 @@ RUN go install github.com/swaggo/swag/cmd/swag@latest && \
|
|||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download && go mod verify
|
RUN go mod download && go mod verify
|
||||||
|
|
||||||
# Copy the rest of the source (this happens in CI)
|
# Simple build environment - source code is mounted at runtime
|
||||||
# COPY . .
|
WORKDIR /workspace
|
||||||
|
|
||||||
# Build command (will be run in CI)
|
# Install basic CI tools
|
||||||
# RUN go build -o /out/server ./cmd/server && \
|
RUN apk add --no-cache \
|
||||||
# go build -o /out/greet ./cmd/greet
|
git \
|
||||||
|
bash \
|
||||||
|
make \
|
||||||
|
gcc \
|
||||||
|
musl-dev
|
||||||
|
|
||||||
|
# Pre-download common Go tools
|
||||||
|
RUN go install github.com/swaggo/swag/cmd/swag@latest
|
||||||
Reference in New Issue
Block a user