Skip to content

Commit

Permalink
Fix pull request workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
codetheweb committed Aug 18, 2024
1 parent 4841c07 commit deec536
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 24 deletions.
87 changes: 65 additions & 22 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
name: PR Workflow

on: pull_request_target
on: pull_request

env:
REGISTRY_IMAGE: ghcr.io/museofficial/muse

jobs:
release-snapshot:
name: Release snapshot
build:
name: Build snapshot
strategy:
matrix:
runner-platform:
- ubuntu-latest
- macos-14 # ARM
- buildjet-4vcpu-ubuntu-2204-arm
include:
- runner-platform: ubuntu-latest
build-arch: linux/amd64
tagged-platform: amd64
- runner-platform: macos-14
- runner-platform: buildjet-4vcpu-ubuntu-2204-arm
build-arch: linux/arm64
tagged-platform: arm64
runs-on: ${{ matrix.runner-platform }}
Expand All @@ -24,8 +27,20 @@ jobs:
attestations: write
id-token: write
steps:
- name: Prepare
run: |
platform=${{ matrix.build-arch }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY_IMAGE }}
tags: type=ref,event=pr

- name: Set up Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -38,31 +53,52 @@ jobs:
uses: josStorer/get-current-time@v2
id: current-time

- name: Build and push
id: docker_build
- name: Build
id: build
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}-${{ matrix.tagged-platform }}
outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
labels: ${{ steps.meta.outputs.labels }}
platforms: ${{ matrix.build-arch }}
build-args: |
COMMIT_HASH=${{ github.sha }}
BUILD_DATE=${{ steps.current-time.outputs.time }}
combine-and-comment:
name: Combine platform tags and leave comment
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs: release-snapshot
needs:
- build
steps:
- name: Set up Buildx
uses: docker/setup-buildx-action@v1
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

- name: Login to DockerHub
uses: docker/login-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
images: ${{ env.REGISTRY_IMAGE }}
tags: type=ref,event=pr

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -71,8 +107,15 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Combine tags
run: docker buildx imagetools create -t 'ghcr.io/museofficial/muse:pr-${{ github.event.number }}' -t 'ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}' 'ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}-arm64' 'ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}-amd64'
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
- name: Create comment
uses: marocchino/sticky-pull-request-comment@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
matrix:
runner-platform:
- ubuntu-latest
- macos-14 # ARM
- buildjet-4vcpu-ubuntu-2204-arm
include:
- runner-platform: ubuntu-latest
build-arch: linux/amd64
tagged-platform: amd64
- runner-platform: macos-14
- runner-platform: buildjet-4vcpu-ubuntu-2204-arm
build-arch: linux/arm64
tagged-platform: arm64
runs-on: ${{ matrix.runner-platform }}
Expand Down

0 comments on commit deec536

Please sign in to comment.