From e968c797b4162a0b279c980826ca6c884d8a43cc Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Mon, 24 Jun 2024 20:29:07 -0400 Subject: [PATCH] build: push container image after successful PR merge --- .github/workflows/build.yml | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0eba3ad..e0e65b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,14 +6,35 @@ on: pull_request: branches: [main] +env: + TAG_NAME: ${{ github.event_name == 'push' && github.ref_name || format('pr-{0}', github.event.pull_request.number) }} + jobs: - build-docker: + build-container-image: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Buildah Action + + - name: build image + id: build-image uses: redhat-actions/buildah-build@v2 with: - image: quips - tags: ${{ github.sha }} + image: infinitewarp/quips + tags: ${{ github.sha }} ${{ env.TAG_NAME }} containerfiles: ./compose/django/Dockerfile + + - name: push image + id: push-to-registry + # Push *only* after the merge. Until I actually need to push PR images, why waste storage? + if: github.event.pull_request.merged == true + uses: redhat-actions/push-to-registry@v2 + with: + image: ${{ steps.build-image.outputs.image }} + tags: ${{ steps.build-image.outputs.tags }} + registry: ${{ secrets.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Show image url + if: github.event.pull_request.merged != true + run: echo "Image pushed to ${{ steps.push-to-registry.outputs.registry-paths }}"