From aa037d57c8247baa0418060142d02f3782b9a6c4 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Fri, 18 Oct 2024 15:42:34 +0200 Subject: [PATCH] ci: Prefer repository owner image if it exists Only fall back to the actor's image if the repository owner ones does not exist. --- .github/workflows/container.yml | 36 +++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 6484068d2..61aa7679c 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -1,5 +1,5 @@ env: - IMAGE_TAG: 20241016-2 + IMAGE_TAG: 20241016-3 on: workflow_call: @@ -27,22 +27,28 @@ jobs: username: ${{ github.actor }} password: ${{ github.token }} - - name: Find the registry owner to use - run: | - if [[ "${{github.event_name}}" == "pull_request" ]] ; then - OWNER="${{ github.actor }}" - else - OWNER="${{ github.repository_owner }}" - fi - echo "REGISTRY_OWNER=${OWNER,,}" >> ${GITHUB_ENV} - - name: Check if image already exists on GHCR id: check run: | - image=ghcr.io/${{ env.REGISTRY_OWNER }}/xdg-desktop-portal:${{ env.IMAGE_TAG }} - echo "exists=$(docker manifest inspect $image >/dev/null && echo 'true' || echo 'false')" \ - >> "$GITHUB_OUTPUT" - echo "image=$image" >> "$GITHUB_OUTPUT" + ACTOR="${{ github.actor }}" + OWNER="${{ github.repository_owner }}" + image_actor="ghcr.io/${ACTOR,,}/xdg-desktop-portal:${{ env.IMAGE_TAG }}" + image_owner="ghcr.io/${OWNER,,}/xdg-desktop-portal:${{ env.IMAGE_TAG }}" + + if docker manifest inspect "${image_owner}" >/dev/null ; then + echo "exists=true" >> "$GITHUB_OUTPUT" + echo "image=${image_owner}" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if docker manifest inspect "${image_actor}" >/dev/null ; then + echo "exists=true" >> "$GITHUB_OUTPUT" + echo "image=${image_actor}" >> "$GITHUB_OUTPUT" + exit 0 + fi + + echo "exists=false" >> "$GITHUB_OUTPUT" + echo "image=${image_owner}" >> "$GITHUB_OUTPUT" - name: Build and push if: ${{ steps.check.outputs.exists == 'false' }} @@ -50,4 +56,4 @@ jobs: with: push: true file: .github/workflows/Containerfile - tags: ghcr.io/${{ env.REGISTRY_OWNER }}/xdg-desktop-portal:${{ env.IMAGE_TAG }} + tags: ${{ steps.check.outputs.image }}