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 b59118c
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 48 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/pr-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release snapshot of PR
on:
workflow_run:
workflows: ["PR Workflow"]
types:
- completed

jobs:
release-and-comment:
name: Release snapshot and comment in PR
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.WORKFLOW_PAT }}

- name: Download PR number
uses: actions/download-artifact@v4
with:
path: /tmp/pull_request_number
pattern: pull_request_number
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.WORKFLOW_PAT }}

- name: Read the pull_request_number.txt file
id: pull_request_number_reader
uses: juliangruber/[email protected]
with:
path: ./pull_request_number/pull_request_number.txt

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

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push
working-directory: /tmp/digests
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 comment
uses: marocchino/sticky-pull-request-comment@v2
with:
header: "pr-release"
number: ${{ steps.pull_request_number_reader.outputs.content }}
message: |
#### :package: A new release has been made for this pull request.
To play around with this PR, pull `ghcr.io/museofficial/muse:pr-${{ github.event.number }}` or `ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}`.
Images are available for x86_64 and ARM64.
> Latest commit: ${{ github.event.pull_request.head.sha }}
75 changes: 29 additions & 46 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
name: PR Workflow

on: pull_request_target
on: pull_request

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 }}
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- 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 @@ -39,50 +34,38 @@ jobs:
id: current-time

- name: Build and push
id: docker_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: ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}-${{ matrix.tagged-platform }}
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
runs-on: ubuntu-latest
needs: release-snapshot
steps:
- name: Set up Buildx
uses: docker/setup-buildx-action@v1

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
- name: Upload digest
uses: actions/upload-artifact@v4
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

- 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: Save the PR number in an artifact
shell: bash
env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}
run: echo $PULL_REQUEST_NUMBER > pull_request_number.txt

- name: Create comment
uses: marocchino/sticky-pull-request-comment@v2
- name: Upload the PULL REQUEST number
uses: actions/upload-artifact@v2
with:
header: "pr-release"
message: |
#### :package: A new release has been made for this pull request.
To play around with this PR, pull `ghcr.io/museofficial/muse:pr-${{ github.event.number }}` or `ghcr.io/museofficial/muse:${{ github.event.pull_request.head.sha }}`.
Images are available for x86_64 and ARM64.
> Latest commit: ${{ github.event.pull_request.head.sha }}
name: pull_request_number
path: ./pull_request_number.txt
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 b59118c

Please sign in to comment.