Skip to content

Commit 6a2d3f9

Browse files
committed
refactor(ci): ⚙️ update check-missing-images workflow to improve tag handling and skip pattern logic
1 parent f84ca89 commit 6a2d3f9

1 file changed

Lines changed: 47 additions & 10 deletions

File tree

.github/workflows/check-missing-images.yml

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,85 @@ on:
66
- cron: '0 6 * * *'
77

88
jobs:
9-
check-and-build:
9+
check-missing-images:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout repository
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@v5
1414
with:
1515
fetch-depth: 0
1616
fetch-tags: true
1717

1818
- name: List version tags
1919
id: list_tags
20+
env:
21+
VERSION_PREFIX: ${{ vars.VERSION_PREFIX || 'v' }}
2022
run: |
23+
if [[ -n "${VERSION_PREFIX}" ]]; then
24+
tags=$(git tag | grep "^${VERSION_PREFIX}" | sort -r)
25+
else
26+
tags=$(git tag | sort -r)
27+
fi
28+
29+
# Output tags for next step
2130
{
22-
tags=$(git tag | grep '^v' | sort -r)
2331
echo "tags<<EOF"
24-
echo "$tags"
32+
printf "%s\n" "${tags}"
2533
echo "EOF"
2634
} >> "$GITHUB_OUTPUT"
2735
2836
- name: Check GHCR for existing images
2937
id: check_images
3038
env:
3139
TOKEN: ${{ secrets.GHCR_READ_TOKEN || secrets.GITHUB_TOKEN }}
40+
SKIP_TAGS: ${{ vars.SKIP_TAGS }}
41+
GHCR_ORG: ${{ vars.GHCR_ORG || github.repository_owner }}
42+
GHCR_CONTAINER: ${{ vars.GHCR_CONTAINER }}
3243
run: |
3344
missing_tags=()
45+
3446
# Use GitHub REST API to list container image versions (tags)
3547
ghcr_tags=$(curl -sSL \
3648
-H "Accept: application/vnd.github+json" \
3749
-H "X-GitHub-Api-Version: 2022-11-28" \
3850
-H "Authorization: Bearer ${TOKEN}" \
39-
https://api.github.com/orgs/ophiosdev/packages/container/codex-cli/versions \
51+
"https://api.github.com/orgs/${GHCR_ORG}/packages/container/${GHCR_CONTAINER}/versions" \
4052
| jq -r '.[].metadata.container.tags[]?' 2>/dev/null || true)
4153
42-
echo "Existing GHCR tags: $ghcr_tags"
54+
echo "📦 Existing GHCR tags:"
55+
echo "$ghcr_tags"
56+
57+
# Combine multiline skip patterns into single regex
58+
skip_regex=""
59+
if [[ -n "${SKIP_TAGS:-}" ]]; then
60+
skip_regex=$(echo "$SKIP_TAGS" | tr -s '\r\n' '|' | sed 's/|$//')
61+
echo "🚫 Skip regex: $skip_regex"
62+
else
63+
echo "ℹ️ No skip patterns defined."
64+
fi
65+
66+
declare -i skipped_count=0
67+
declare -i total_tags=0
4368
4469
while IFS= read -r tag; do
45-
if ! grep -qx "${tag#v}" <<< "$ghcr_tags"; then
46-
echo "Image missing for $tag"
70+
total_tags+=1
71+
if [[ -n "$skip_regex" && "$tag" =~ $skip_regex ]]; then
72+
echo "➡️ Skipping $tag (matches skip pattern)"
73+
skipped_count+=1
74+
continue
75+
fi
76+
if ! grep -qx "${tag#v}" <<< "$ghcr_tags" >/dev/null 2>&1; then
77+
echo "❌ Image missing for $tag"
4778
missing_tags+=("$tag")
4879
fi
4980
done <<< "${{ steps.list_tags.outputs.tags }}"
5081
51-
# Output missing tags correctly to GITHUB_OUTPUT
82+
echo "===== Summary ====="
83+
echo " Total tags checked: $total_tags"
84+
echo " Skipped tags: $skipped_count"
85+
echo " Missing images found: ${#missing_tags[@]}"
86+
87+
# Output missing tags for next step
5288
{
5389
echo "missing_tags<<EOF"
5490
printf "%s\n" "${missing_tags[@]}"
@@ -66,8 +102,9 @@ jobs:
66102
if: steps.check_images.outputs.missing_tags != ''
67103
env:
68104
GH_TOKEN: ${{ steps.app_token.outputs.token }}
105+
WORKFLOW: ${{ vars.BUILD_WORKFLOW || 'build-and-deploy.yml' }}
69106
run: |
70107
while read -r tag; do
71108
echo "Triggering build-and-deploy for $tag"
72-
gh workflow run build-and-deploy.yml --ref "$tag"
109+
gh workflow run "${BUILD_WORKFLOW}" --ref "$tag"
73110
done <<< "${{ steps.check_images.outputs.missing_tags }}"

0 commit comments

Comments
 (0)