From d604d8ef8eb93805fba1128cd52f5e433c835026 Mon Sep 17 00:00:00 2001 From: Samuel Giffard Date: Mon, 26 Feb 2024 14:11:21 +0100 Subject: [PATCH] feat: Events: Auto PR comments Signed-off-by: Samuel Giffard --- .github/workflows/deploy-image.yml | 49 ++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-image.yml b/.github/workflows/deploy-image.yml index a1b83b4ff93..ffe352e5ad3 100644 --- a/.github/workflows/deploy-image.yml +++ b/.github/workflows/deploy-image.yml @@ -12,14 +12,19 @@ on: env: REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository_owner }}/dvalin-tools-event-agent + IMAGE_NAME: dvalin-tools-event-agent + IMAGE_NAME_DOUBLE_DASH: dvalin--tools--event--agent + TAG_NAME: ${{ github.repository_owner }}/dvalin-tools-event-agent + COMMENT_ANCHOR: "" jobs: build-and-push-image: runs-on: ubuntu-latest permissions: contents: read + issues: write packages: write + pull-requests: write steps: - name: Checkout repository @@ -36,7 +41,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + images: ${{ env.REGISTRY }}/${{ env.TAG_NAME }} tags: | type=ref,event=branch type=ref,event=pr @@ -53,3 +58,43 @@ jobs: target: runtime-prod build-args: | DVALIN_REPO_ROOT_DIR=/usr/src/repo/dvalin-data + + - name: Find Comment + uses: peter-evans/find-comment@v3 + id: fc + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: 'github-actions[bot]' + body-includes: ${{ env.COMMENT_ANCHOR }} + + - name: Add PR comment with Docker image info + if: github.event_name == 'pull_request' + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + issue-number: ${{ github.event.pull_request.number }} + edit-mode: replace + reactions: rocket + body: | + ${env.COMMENT_ANCHOR} + + :whale: Docker image for PR #${{ github.event.pull_request.number }} has been built and pushed! + + ![Static Badge][badge-docker-pr] + + **Image:** `${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }}` + + Install from the command line + ```bash + docker pull ${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }} + ``` + + Use as base image in Dockerfile: + ```Dockerfile + FROM ${{ env.REGISTRY }}/${{ env.TAG_NAME }}:pr-${{ github.event.pull_request.number }} + ``` + + For more details, visit our [GitHub Packages][gh-packages]. + + [gh-packages]: https://github.com/${{ github.repository }}/pkgs/container/${{ env.IMAGE_NAME }} + [badge-docker-pr]: https://img.shields.io/badge/${{ env.IMAGE_NAME_DOUBLE_DASH }}-PR--${{ github.event.pull_request.number }}-blue?logo=docker