Skip to content

Commit

Permalink
Fix Docker build errors when opening a PR from a fork.
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinevg committed Jul 30, 2024
1 parent 3013b6c commit de35e6b
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions .github/workflows/appimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ jobs:
echo "IMAGE_NAME: ${{ env.IMAGE_NAME }}"
echo "IMAGE_TAG: ${{ env.IMAGE_TAG }}"
- name: Use 'main' Docker image tag if this is a PR from a fork
id: origin
shell: bash
if: github.event.pull_request.head.repo.fork
run: |
echo 'IMAGE_TAG=main' >> $GITHUB_ENV
- name: Check if Dockerfile has changed
uses: dorny/paths-filter@v3
id: changed
Expand All @@ -56,23 +63,29 @@ jobs:
echo 'dockerimage<<EOF' >> $GITHUB_OUTPUT
echo ${RESULT} | jq 'has("manifests")' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
echo
echo exists: ${{ steps.changed.outputs.dockerfile }}
- name: Check if we need to build the Docker image
id: dockerimage
if: |
! github.event.pull_request.head.repo.fork &&
(steps.changed.outputs.dockerfile == 'true' || steps.exists.outputs.dockerimage == 'false')
run: |
echo 'build=true' >> $GITHUB_OUTPUT
- name: Log in to the Container registry
if: ${{ steps.changed.outputs.dockerfile == 'true' || steps.exists.outputs.dockerimage == 'false' }}
if: steps.dockerimage.outputs.build
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
if: ${{ steps.changed.outputs.dockerfile == 'true' || steps.exists.outputs.dockerimage == 'false' }}
if: steps.dockerimage.outputs.build
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
if: ${{ steps.changed.outputs.dockerfile == 'true' || steps.exists.outputs.dockerimage == 'false' }}
if: steps.dockerimage.outputs.build
id: push
uses: docker/build-push-action@v6
with:
Expand All @@ -83,7 +96,7 @@ jobs:
cache-to: type=gha, scope=${{ env.IMAGE_TAG }}, mode=max

- name: Generate artifact attestation
if: ${{ steps.changed.outputs.dockerfile == 'true' || steps.exists.outputs.dockerimage == 'false' }}
if: steps.dockerimage.outputs.build
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ env.IMAGE_NAME }}
Expand All @@ -108,6 +121,11 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Check image name & tag
run: |
echo "NAME: ${{ needs.create-docker-image.outputs.NAME }}"
echo "TAG: ${{ needs.create-docker-image.outputs.TAG }}"
- name: Checkout repository
uses: actions/checkout@v4

Expand Down

0 comments on commit de35e6b

Please sign in to comment.