FIX(ci): fix SHA tag extraction

- Handle both full and short SHA formats
- Improve tag parsing logic
This commit is contained in:
2025-11-24 21:10:35 +09:00
parent 0740504a0a
commit efdab39933
2 changed files with 25 additions and 12 deletions

View File

@@ -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-<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:

View File

@@ -13,7 +13,7 @@ commonLabels:
# 이미지 태그 설정
images:
- name: ghcr.io/mayne0213/jovies
newTag:
newTag: main-sha-231955a
patchesStrategicMerge:
- deployment-patch.yaml