fix(woodpecker): handle shallow git clone for change detection

This commit is contained in:
Ashwin Kumar 2026-04-10 17:42:53 +02:00
parent a6c88666ec
commit a9227252e8

View file

@ -11,7 +11,17 @@ steps:
#!/bin/bash
set -e
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD || echo "")
# Fetch previous commit for comparison
git fetch --depth=2 origin +refs/heads/${CI_COMMIT_BRANCH}:refs/remotes/origin/${CI_COMMIT_BRANCH} || true
# Get changed files (handle shallow clone)
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || git diff --name-only origin/${CI_COMMIT_BRANCH}~1 origin/${CI_COMMIT_BRANCH} 2>/dev/null || echo "ALL")
# If we can't detect changes, assume we should build
if [ "$CHANGED_FILES" = "ALL" ] || [ -z "$CHANGED_FILES" ]; then
echo "⚠️ Cannot detect changes, assuming build needed"
exit 0
fi
# Skip if only docs changed
if echo "$CHANGED_FILES" | grep -qE "^\.github/|^\.woodpecker|\.md$"; then
@ -38,7 +48,6 @@ steps:
- name: build-and-push
image: woodpeckerci/plugin-docker-buildx:5.0.0
settings:
# Use internal registry
registry: docker-registry.registry.svc.cluster.local:5000
repo: docker-registry.registry.svc.cluster.local:5000/nxtgauge-admin-solid
dockerfile: Dockerfile
@ -46,7 +55,6 @@ steps:
- ${CI_COMMIT_SHA}
- latest
- high-performance-latest
# Use Docker Hub for base images
logins:
- registry: https://index.docker.io/v1/
username:
@ -54,6 +62,5 @@ steps:
password:
from_secret: DOCKERHUB_TOKEN
platforms: linux/amd64
# Enable caching from/to internal registry
cache_from: docker-registry.registry.svc.cluster.local:5000/nxtgauge-admin-solid:cache
cache_to: docker-registry.registry.svc.cluster.local:5000/nxtgauge-admin-solid:cache