build-push-pr.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. name: Build container image for PR
  2. on:
  3. pull_request:
  4. types: [labeled, synchronize, reopened, ready_for_review, opened]
  5. permissions:
  6. contents: read
  7. packages: write
  8. jobs:
  9. compute-suffix:
  10. runs-on: ubuntu-latest
  11. # This is only allowed to run if:
  12. # - the PR branch is in the `mastodon/mastodon` repository
  13. # - the PR is not a draft
  14. # - the PR has the "build-image" label
  15. if: ${{ github.event.pull_request.head.repo.full_name == github.repository && !github.event.pull_request.draft && contains(github.event.pull_request.labels.*.name, 'build-image') }}
  16. steps:
  17. # Repository needs to be cloned so `git rev-parse` below works
  18. - name: Clone repository
  19. uses: actions/checkout@v4
  20. - id: version_vars
  21. run: |
  22. echo mastodon_version_metadata=pr-${{ github.event.pull_request.number }}-$(git rev-parse --short ${{github.event.pull_request.head.sha}}) >> $GITHUB_OUTPUT
  23. echo mastodon_short_sha=$(git rev-parse --short ${{github.event.pull_request.head.sha}}) >> $GITHUB_OUTPUT
  24. outputs:
  25. metadata: ${{ steps.version_vars.outputs.mastodon_version_metadata }}
  26. short_sha: ${{ steps.version_vars.outputs.mastodon_short_sha }}
  27. build-image:
  28. needs: compute-suffix
  29. uses: ./.github/workflows/build-container-image.yml
  30. with:
  31. file_to_build: Dockerfile
  32. platforms: linux/amd64,linux/arm64
  33. use_native_arm64_builder: true
  34. push_to_images: |
  35. ghcr.io/mastodon/mastodon
  36. version_metadata: ${{ needs.compute-suffix.outputs.metadata }}
  37. flavor: |
  38. latest=auto
  39. tags: |
  40. type=ref,event=pr
  41. type=ref,event=pr,suffix=-${{ needs.compute-suffix.outputs.short_sha }}
  42. secrets: inherit
  43. build-image-streaming:
  44. needs: compute-suffix
  45. uses: ./.github/workflows/build-container-image.yml
  46. with:
  47. file_to_build: streaming/Dockerfile
  48. platforms: linux/amd64,linux/arm64
  49. use_native_arm64_builder: true
  50. push_to_images: |
  51. ghcr.io/mastodon/mastodon-streaming
  52. version_metadata: ${{ needs.compute-suffix.outputs.metadata }}
  53. flavor: |
  54. latest=auto
  55. tags: |
  56. type=ref,event=pr
  57. type=ref,event=pr,suffix=-${{ needs.compute-suffix.outputs.short_sha }}
  58. secrets: inherit