aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/pr-release.yml
blob: 454a023c5576748bd4c26fed97c317d8545c8a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Release snapshot of PR
on:
  workflow_run:
    workflows: ["Build snapshot of PR"]
    types:
      - completed

env:
  REGISTRY_IMAGE: ghcr.io/museofficial/muse

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 images
        uses: actions/download-artifact@v4
        with:
          path: /tmp/images
          pattern: image-linux-*
          merge-multiple: true
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GH_PAT }}

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

      - name: Load image
        shell: bash
        id: load-image
        run: |
          echo "AMD64_IMAGE_SHA=$(docker image import --platform linux/amd64 /tmp/images/image-linux-amd64.tar)" >> $GITHUB_ENV"
          echo "ARM64_IMAGE_SHA=$(docker image import --platform linux/arm64 /tmp/images/image-linux-arm64.tar)" >> $GITHUB_ENV"

      - name: Download Docker metadata
        uses: actions/download-artifact@v4
        with:
          path: /tmp/metadata
          pattern: metadata
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ secrets.GH_PAT }}

      - name: Read the metadata.json file
        id: metadata_reader
        uses: juliangruber/[email protected]
        with:
          path: /tmp/metadata/metadata/metadata.json

      - 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.GH_PAT }}

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

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

      - 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.GH_PAT }}

      - name: Create manifest list and push
        working-directory: /tmp/digests
        run: |
          docker buildx imagetools create $(cat /tmp/metadata/metadata/metadata.json | jq -cr '.tags | map("-t " + .) | join(" ")') \
            $(echo ${{ steps.load-image.outputs.AMD64_IMAGE_SHA }} | sed 's/sha256://g' | tr '\n' ' ') \
            $(echo ${{ steps.load-image.outputs.ARM64_IMAGE_SHA }} | sed 's/sha256://g' | tr '\n' ' ')

      - name: Create comment
        uses: marocchino/sticky-pull-request-comment@v2
        with:
          header: "pr-release"
          number: ${{ steps.pull_request_number_reader.outputs.content }}
          message: |
            #### :package: :robot: A new release has been made for this pull request.

            To play around with this PR, pull `${{ env.REGISTRY_IMAGE }}:pr-${{ github.event.number }}` or `${{ env.REGISTRY_IMAGE }}:${{ github.event.pull_request.head.sha }}`.

            Images are available for x86_64 and ARM64.

            > Latest commit: ${{ github.event.pull_request.head.sha }}