Skip to content

Commit

Permalink
ci: Prefer repository owner image if it exists
Browse files Browse the repository at this point in the history
Only fall back to the actor's image if the repository owner ones does
not exist.
  • Loading branch information
swick committed Oct 18, 2024
1 parent ff460df commit aa037d5
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
IMAGE_TAG: 20241016-2
IMAGE_TAG: 20241016-3

on:
workflow_call:
Expand Down Expand Up @@ -27,27 +27,33 @@ 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' }}
uses: docker/build-push-action@v5
with:
push: true
file: .github/workflows/Containerfile
tags: ghcr.io/${{ env.REGISTRY_OWNER }}/xdg-desktop-portal:${{ env.IMAGE_TAG }}
tags: ${{ steps.check.outputs.image }}

0 comments on commit aa037d5

Please sign in to comment.