diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml index 9af7437..1a06c12 100644 --- a/.forgejo/workflows/ci.yml +++ b/.forgejo/workflows/ci.yml @@ -32,7 +32,27 @@ jobs: HASH="$(sha256sum composer.lock | cut -c1-12)" echo "tag=php8.3-${HASH}" >> "$GITHUB_OUTPUT" + - name: Check whether image already exists + id: exists + run: | + set -euo pipefail + TOKEN="$(curl -sf "https://forge.lvl0.xyz/v2/token?service=container_registry&scope=repository:lvl0/dishplanner-ci:pull" | grep -o '"token":"[^"]*"' | head -n1 | cut -d'"' -f4)" + if [ -z "$TOKEN" ]; then + echo "Registry token fetch failed; cannot check for an existing image." >&2 + exit 1 + fi + CODE="$(curl -s -o /dev/null -w '%{http_code}' \ + -H "Authorization: Bearer $TOKEN" \ + -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.docker.distribution.manifest.v2+json' \ + "https://forge.lvl0.xyz/v2/lvl0/dishplanner-ci/manifests/${{ steps.meta.outputs.tag }}")" + if [ "$CODE" = "200" ]; then + echo "found=true" >> "$GITHUB_OUTPUT" + else + echo "found=false" >> "$GITHUB_OUTPUT" + fi + - name: Build and push CI image + if: steps.exists.outputs.found == 'false' uses: https://data.forgejo.org/docker/build-push-action@v5 with: context: .