|
6 | 6 | - cron: '0 6 * * *' |
7 | 7 |
|
8 | 8 | jobs: |
9 | | - check-and-build: |
| 9 | + check-missing-images: |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 | steps: |
12 | 12 | - name: Checkout repository |
13 | | - uses: actions/checkout@v4 |
| 13 | + uses: actions/checkout@v5 |
14 | 14 | with: |
15 | 15 | fetch-depth: 0 |
16 | 16 | fetch-tags: true |
17 | 17 |
|
18 | 18 | - name: List version tags |
19 | 19 | id: list_tags |
| 20 | + env: |
| 21 | + VERSION_PREFIX: ${{ vars.VERSION_PREFIX || 'v' }} |
20 | 22 | 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 |
21 | 30 | { |
22 | | - tags=$(git tag | grep '^v' | sort -r) |
23 | 31 | echo "tags<<EOF" |
24 | | - echo "$tags" |
| 32 | + printf "%s\n" "${tags}" |
25 | 33 | echo "EOF" |
26 | 34 | } >> "$GITHUB_OUTPUT" |
27 | 35 |
|
28 | 36 | - name: Check GHCR for existing images |
29 | 37 | id: check_images |
30 | 38 | env: |
31 | 39 | 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 }} |
32 | 43 | run: | |
33 | 44 | missing_tags=() |
| 45 | +
|
34 | 46 | # Use GitHub REST API to list container image versions (tags) |
35 | 47 | ghcr_tags=$(curl -sSL \ |
36 | 48 | -H "Accept: application/vnd.github+json" \ |
37 | 49 | -H "X-GitHub-Api-Version: 2022-11-28" \ |
38 | 50 | -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" \ |
40 | 52 | | jq -r '.[].metadata.container.tags[]?' 2>/dev/null || true) |
41 | 53 |
|
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 |
43 | 68 |
|
44 | 69 | 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" |
47 | 78 | missing_tags+=("$tag") |
48 | 79 | fi |
49 | 80 | done <<< "${{ steps.list_tags.outputs.tags }}" |
50 | 81 |
|
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 |
52 | 88 | { |
53 | 89 | echo "missing_tags<<EOF" |
54 | 90 | printf "%s\n" "${missing_tags[@]}" |
|
66 | 102 | if: steps.check_images.outputs.missing_tags != '' |
67 | 103 | env: |
68 | 104 | GH_TOKEN: ${{ steps.app_token.outputs.token }} |
| 105 | + WORKFLOW: ${{ vars.BUILD_WORKFLOW || 'build-and-deploy.yml' }} |
69 | 106 | run: | |
70 | 107 | while read -r tag; do |
71 | 108 | 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" |
73 | 110 | done <<< "${{ steps.check_images.outputs.missing_tags }}" |
0 commit comments