From efdab39933710de5b6d1de3531cf0bd814cc6896 Mon Sep 17 00:00:00 2001 From: Mayne0213 Date: Mon, 24 Nov 2025 21:10:35 +0900 Subject: [PATCH] FIX(ci): fix SHA tag extraction - Handle both full and short SHA formats - Improve tag parsing logic --- .github/workflows/build.yml | 35 ++++++++++++++------- deploy/k8s/overlays/prod/kustomization.yaml | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c6d6a9..25f01b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -75,23 +75,35 @@ jobs: echo "$TAGS" echo "---" - # Try multiple methods to extract SHA tag - # Method 1: Extract from full image tag (ghcr.io/.../image:main-sha-xxxxx) - SHA_TAG=$(echo "$TAGS" | grep -oE 'main-sha-[a-f0-9]+' | head -n 1) + # Get commit SHA and create short SHA (7 characters) + COMMIT_SHA="${{ github.sha }}" + SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7) + EXPECTED_TAG="main-sha-$SHORT_SHA" - # Method 2: If Method 1 fails, try extracting from any line containing main-sha- + # Method 1: Try to find the tag matching our expected format (main-sha-xxxxxxx) + SHA_TAG=$(echo "$TAGS" | grep -oE "main-sha-$SHORT_SHA" | head -n 1) + + # Method 2: If not found, try to extract any main-sha- tag (could be full SHA) if [ -z "$SHA_TAG" ]; then - SHA_TAG=$(echo "$TAGS" | grep 'main-sha-' | sed -n 's/.*main-sha-\([a-f0-9]\+\).*/\1/p' | head -n 1) - if [ -n "$SHA_TAG" ]; then - SHA_TAG="main-sha-$SHA_TAG" + # Extract the SHA part from main-sha- format + EXTRACTED_SHA=$(echo "$TAGS" | grep -oE 'main-sha-[a-f0-9]+' | sed 's/main-sha-//' | head -n 1) + if [ -n "$EXTRACTED_SHA" ]; then + # Check if extracted SHA starts with our short SHA + if echo "$EXTRACTED_SHA" | grep -q "^$SHORT_SHA"; then + # Use the short SHA format for consistency + SHA_TAG="$EXPECTED_TAG" + echo "⚠️ Found full SHA tag, using short SHA format: $SHA_TAG" + else + # Use the extracted SHA as-is + SHA_TAG="main-sha-$EXTRACTED_SHA" + echo "⚠️ Using extracted SHA tag: $SHA_TAG" + fi fi fi - # Method 3: Extract SHA from commit SHA directly + # Method 3: Fallback to commit SHA directly (most reliable) if [ -z "$SHA_TAG" ]; then - COMMIT_SHA="${{ github.sha }}" - SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7) - SHA_TAG="main-sha-$SHORT_SHA" + SHA_TAG="$EXPECTED_TAG" echo "⚠️ Could not extract from tags, using commit SHA: $SHA_TAG" fi @@ -102,6 +114,7 @@ jobs: echo "sha-tag=$SHA_TAG" >> $GITHUB_OUTPUT echo "✅ Extracted SHA tag: $SHA_TAG" + echo "📝 Expected tag format: $EXPECTED_TAG" - name: Update kustomization with new image tag env: diff --git a/deploy/k8s/overlays/prod/kustomization.yaml b/deploy/k8s/overlays/prod/kustomization.yaml index 3739646..1919e7f 100644 --- a/deploy/k8s/overlays/prod/kustomization.yaml +++ b/deploy/k8s/overlays/prod/kustomization.yaml @@ -13,7 +13,7 @@ commonLabels: # 이미지 태그 설정 images: - name: ghcr.io/mayne0213/jovies - newTag: + newTag: main-sha-231955a patchesStrategicMerge: - deployment-patch.yaml