|
| 1 | +name: Check Missing Container Images |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + schedule: |
| 6 | + - cron: '0 6 * * *' |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-and-build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout repository |
| 13 | + uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + fetch-tags: true |
| 17 | + |
| 18 | + - name: List version tags |
| 19 | + id: list_tags |
| 20 | + run: | |
| 21 | + { |
| 22 | + tags=$(git tag | grep '^v' | sort -r) |
| 23 | + echo "tags<<EOF" |
| 24 | + echo "$tags" |
| 25 | + echo "EOF" |
| 26 | + } >> "$GITHUB_OUTPUT" |
| 27 | +
|
| 28 | + - name: Check GHCR for existing images |
| 29 | + id: check_images |
| 30 | + env: |
| 31 | + TOKEN: ${{ secrets.GHCR_READ_TOKEN || secrets.GITHUB_TOKEN }} |
| 32 | + run: | |
| 33 | + missing_tags=() |
| 34 | + # Use GitHub REST API to list container image versions (tags) |
| 35 | + ghcr_tags=$(curl -sSL \ |
| 36 | + -H "Accept: application/vnd.github+json" \ |
| 37 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 38 | + -H "Authorization: Bearer ${TOKEN}" \ |
| 39 | + https://api.github.com/orgs/ophiosdev/packages/container/codex-cli/versions \ |
| 40 | + | jq -r '.[].metadata.container.tags[]?' 2>/dev/null || true) |
| 41 | +
|
| 42 | + echo "Existing GHCR tags: $ghcr_tags" |
| 43 | +
|
| 44 | + while IFS= read -r tag; do |
| 45 | + if ! grep -qx "${tag#v}" <<< "$ghcr_tags"; then |
| 46 | + echo "Image missing for $tag" |
| 47 | + missing_tags+=("$tag") |
| 48 | + fi |
| 49 | + done <<< "${{ steps.list_tags.outputs.tags }}" |
| 50 | +
|
| 51 | + # Output missing tags correctly to GITHUB_OUTPUT |
| 52 | + { |
| 53 | + echo "missing_tags<<EOF" |
| 54 | + printf "%s\n" "${missing_tags[@]}" |
| 55 | + echo "EOF" |
| 56 | + } >> "$GITHUB_OUTPUT" |
| 57 | +
|
| 58 | + - name: Generate GitHub App token |
| 59 | + id: app_token |
| 60 | + uses: actions/create-github-app-token@v2 |
| 61 | + with: |
| 62 | + app-id: ${{ secrets.WORKFLOW_APP_ID }} |
| 63 | + private-key: ${{ secrets.WORKFLOW_APP_PRIVATE_KEY }} |
| 64 | + |
| 65 | + - name: Trigger build-and-deploy for missing tags |
| 66 | + if: steps.check_images.outputs.missing_tags != '' |
| 67 | + env: |
| 68 | + GH_TOKEN: ${{ steps.app_token.outputs.token }} |
| 69 | + run: | |
| 70 | + while read -r tag; do |
| 71 | + echo "Triggering build-and-deploy for $tag" |
| 72 | + gh workflow run build-and-deploy.yml --ref "$tag" |
| 73 | + done <<< "${{ steps.check_images.outputs.missing_tags }}" |
0 commit comments