FIX(ci): fix SHA tag extraction
- Handle both full and short SHA formats - Improve tag parsing logic
This commit is contained in:
35
.github/workflows/build.yml
vendored
35
.github/workflows/build.yml
vendored
@@ -75,23 +75,35 @@ jobs:
|
|||||||
echo "$TAGS"
|
echo "$TAGS"
|
||||||
echo "---"
|
echo "---"
|
||||||
|
|
||||||
# Try multiple methods to extract SHA tag
|
# Get commit SHA and create short SHA (7 characters)
|
||||||
# Method 1: Extract from full image tag (ghcr.io/.../image:main-sha-xxxxx)
|
COMMIT_SHA="${{ github.sha }}"
|
||||||
SHA_TAG=$(echo "$TAGS" | grep -oE 'main-sha-[a-f0-9]+' | head -n 1)
|
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
|
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)
|
# Extract the SHA part from main-sha-<sha> format
|
||||||
if [ -n "$SHA_TAG" ]; then
|
EXTRACTED_SHA=$(echo "$TAGS" | grep -oE 'main-sha-[a-f0-9]+' | sed 's/main-sha-//' | head -n 1)
|
||||||
SHA_TAG="main-sha-$SHA_TAG"
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Method 3: Extract SHA from commit SHA directly
|
# Method 3: Fallback to commit SHA directly (most reliable)
|
||||||
if [ -z "$SHA_TAG" ]; then
|
if [ -z "$SHA_TAG" ]; then
|
||||||
COMMIT_SHA="${{ github.sha }}"
|
SHA_TAG="$EXPECTED_TAG"
|
||||||
SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7)
|
|
||||||
SHA_TAG="main-sha-$SHORT_SHA"
|
|
||||||
echo "⚠️ Could not extract from tags, using commit SHA: $SHA_TAG"
|
echo "⚠️ Could not extract from tags, using commit SHA: $SHA_TAG"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -102,6 +114,7 @@ jobs:
|
|||||||
|
|
||||||
echo "sha-tag=$SHA_TAG" >> $GITHUB_OUTPUT
|
echo "sha-tag=$SHA_TAG" >> $GITHUB_OUTPUT
|
||||||
echo "✅ Extracted SHA tag: $SHA_TAG"
|
echo "✅ Extracted SHA tag: $SHA_TAG"
|
||||||
|
echo "📝 Expected tag format: $EXPECTED_TAG"
|
||||||
|
|
||||||
- name: Update kustomization with new image tag
|
- name: Update kustomization with new image tag
|
||||||
env:
|
env:
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ commonLabels:
|
|||||||
# 이미지 태그 설정
|
# 이미지 태그 설정
|
||||||
images:
|
images:
|
||||||
- name: ghcr.io/mayne0213/jovies
|
- name: ghcr.io/mayne0213/jovies
|
||||||
newTag:
|
newTag: main-sha-231955a
|
||||||
|
|
||||||
patchesStrategicMerge:
|
patchesStrategicMerge:
|
||||||
- deployment-patch.yaml
|
- deployment-patch.yaml
|
||||||
|
|||||||
Reference in New Issue
Block a user