Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Docker build errors when opening a PR from a fork. #149

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading