Skip to content

Commit c4ebafd

Browse files
author
Impre-visible
committed
♻️ refactor: Enhance image tag and cache reference handling for Docker publish workflow
1 parent 4337e79 commit c4ebafd

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

.github/workflows/docker-publish.yml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,39 @@ jobs:
2727
- name: Lowercase repo name
2828
run: echo "REPO_NAME_LOWER=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
2929

30-
- name: Set image tags
30+
- name: Set image tags and cache reference
3131
run: |
3232
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
33+
# Pour les releases (tags)
3334
TAG=${GITHUB_REF#refs/tags/}
3435
echo "IMAGE_TAGS=ghcr.io/${REPO_NAME_LOWER}:${TAG},ghcr.io/${REPO_NAME_LOWER}:latest" >> $GITHUB_ENV
36+
echo "CACHE_REF=release" >> $GITHUB_ENV
37+
echo "Build type: Release (tag: ${TAG})"
38+
elif [[ "${GITHUB_REF}" == refs/heads/test/workflow ]]; then
39+
# Pour la branche test/workflow spécifiquement
40+
echo "IMAGE_TAGS=ghcr.io/${REPO_NAME_LOWER}:test-workflow" >> $GITHUB_ENV
41+
echo "CACHE_REF=test-workflow" >> $GITHUB_ENV
42+
echo "Build type: Test workflow branch"
3543
elif [[ "${GITHUB_REF}" == refs/heads/* ]]; then
44+
# Pour les autres branches (au cas où)
3645
BRANCH_NAME=${GITHUB_REF#refs/heads/}
3746
SAFE_BRANCH_NAME=${BRANCH_NAME//\//-}
3847
echo "IMAGE_TAGS=ghcr.io/${REPO_NAME_LOWER}:${SAFE_BRANCH_NAME}" >> $GITHUB_ENV
48+
echo "CACHE_REF=branch-${SAFE_BRANCH_NAME}" >> $GITHUB_ENV
49+
echo "Build type: Other branch (${BRANCH_NAME})"
3950
else
51+
# Fallback
4052
echo "IMAGE_TAGS=ghcr.io/${REPO_NAME_LOWER}:latest" >> $GITHUB_ENV
53+
echo "CACHE_REF=default" >> $GITHUB_ENV
54+
echo "Build type: Default"
4155
fi
4256
43-
- name: Set CACHE_REF based on Git ref
57+
- name: Display cache configuration
4458
run: |
45-
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
46-
echo "CACHE_REF=release" >> $GITHUB_ENV
47-
else
48-
echo "CACHE_REF=test_cache" >> $GITHUB_ENV
49-
fi
59+
echo "🚀 Cache configuration:"
60+
echo " Cache reference: ${{ env.CACHE_REF }}"
61+
echo " Image tags: ${{ env.IMAGE_TAGS }}"
62+
echo " Git ref: ${GITHUB_REF}"
5063
5164
- name: Extract metadata
5265
id: meta
@@ -66,8 +79,10 @@ jobs:
6679
[worker.oci]
6780
max-parallelism = 8
6881
69-
- name: Check Docker cache
70-
run: docker buildx du
82+
- name: Check existing Docker cache
83+
run: |
84+
echo "🔍 Checking existing cache for scope: ${{ env.CACHE_REF }}"
85+
docker buildx du || true
7186
7287
- name: Build and push Docker image
7388
uses: docker/build-push-action@v5
@@ -79,3 +94,9 @@ jobs:
7994
platforms: linux/amd64,linux/arm64
8095
cache-from: type=gha,mode=max,scope=${{ env.CACHE_REF }}
8196
cache-to: type=gha,mode=max,scope=${{ env.CACHE_REF }}
97+
98+
- name: Display build summary
99+
run: |
100+
echo "✅ Build completed successfully!"
101+
echo " Images pushed: ${{ env.IMAGE_TAGS }}"
102+
echo " Cache scope used: ${{ env.CACHE_REF }}"

0 commit comments

Comments
 (0)