action-pr-comment/README.md
2024-07-01 16:56:38 -05:00

1.4 KiB

action-pr-comment

An action to add or update an existing comment anchored in a PR for test results, status messages, etc.

Example

name: Some Workflow

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  some-workflow:
    name: Send PR Comment
    runs-on: ubuntu-act-latest
    steps:
      - name: Clone Repo into Workspace
        uses: https://git.auengun.net/homelab/action-common-setup

      - name: "`make test`"
        if: ${{ github.event_name == 'pull_request' && !cancelled() }}
        shell: bash
        run: |
          set +e
          make test 2>&1 | tee make_test.log
          RESULT="$?"
          set -e
          {
            echo "# Automated Forgejo Actions Report"
            echo ""
            echo "\`\`\`shell"
            cat make_test.log
            echo "\`\`\`"
          } 2>&1 >> "${{github.workspace}}/.pr-comment.md"
          echo "Saved to '${{github.workspace}}/.pr-comment.md'"
          exit $RESULT

      # Posts a comment back to the PR that spawned this CI
      # and keeps it in sync whenever there is a change.
      - name: Post/Update PR Comment
        if: ${{ github.event_name == 'pull_request' && !cancelled() }}
        continue-on-error: true
        uses: https://git.auengun.net/homelab/action-pr-comment
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          path: "${{github.workspace}}/.pr-comment.md"