From ac05ded844a742fb2f0821eead5b6704b2835a87 Mon Sep 17 00:00:00 2001 From: softworkz Date: Mon, 17 Nov 2025 02:49:45 +0100 Subject: [PATCH] Move PR comment creation to separate workflow on:pull_request_target --- .github/workflows/integration-tests.yml | 32 ++++++------- .github/workflows/pr-comment.yml | 61 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/pr-comment.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index ea520a7..adc9170 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -144,7 +144,6 @@ jobs: done echo "Processed $conv TRX file(s)" - - name: Publish Test Report if: always() uses: ctrf-io/github-test-reporter@v1 @@ -186,24 +185,21 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} + - name: Save PR Number + if: github.event_name == 'pull_request' + run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV - - name: Create PR Comment - if: always() - uses: ctrf-io/github-test-reporter@v1 + - name: Write PR Number to File + if: github.event_name == 'pull_request' + run: echo "$PR_NUMBER" > pr_number.txt + shell: bash + + - name: Upload PR Number Artifact + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@v4 with: - report-path: 'ctrf/**/*.json' - - summary: true - pull-request: true - use-suite-name: true - update-comment: true - always-group-by: true - overwrite-comment: true - upload-artifact: false - - pull-request-report: true - env: - GITHUB_TOKEN: ${{ github.token }} + name: pr_number + path: pr_number.txt - name: Summary - run: echo "All matrix test jobs completed." \ No newline at end of file + run: echo "All matrix test jobs completed." diff --git a/.github/workflows/pr-comment.yml b/.github/workflows/pr-comment.yml new file mode 100644 index 0000000..4edf1c1 --- /dev/null +++ b/.github/workflows/pr-comment.yml @@ -0,0 +1,61 @@ +name: Create PR Comments + +on: + workflow_run: + workflows: ["Tests"] + types: [completed] + +permissions: + contents: read + actions: read + pull-requests: write + +jobs: + pr-comment: + name: Post Test Result as PR comment + runs-on: ubuntu-24.04 + if: github.event.workflow_run.event == 'pull_request' + + steps: + - name: Download CTRF artifact + uses: dawidd6/action-download-artifact@v8 + with: + github_token: ${{ github.token }} + run_id: ${{ github.event.workflow_run.id }} + name: ctrf-report + path: ctrf + + - name: Download PR Number Artifact + uses: dawidd6/action-download-artifact@v8 + with: + github_token: ${{ github.token }} + run_id: ${{ github.event.workflow_run.id }} + name: pr_number + path: pr_number + + - name: Read PR Number + run: | + PR_NUMBER=$(cat pr_number/pr_number.txt | grep -E '^[0-9]+$') + if [ -z "$PR_NUMBER" ]; then + echo "Error: PR_NUMBER is not a valid integer." + exit 1 + fi + echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV + + - name: Post PR Comment + uses: ctrf-io/github-test-reporter@v1 + with: + report-path: 'ctrf/**/*.json' + issue: ${{ env.PR_NUMBER }} + + summary: true + pull-request: true + use-suite-name: true + update-comment: true + always-group-by: true + overwrite-comment: true + upload-artifact: false + + pull-request-report: true + env: + GITHUB_TOKEN: ${{ github.token }}