From 9e18b0e00128eb833efd35804ef2293305a7f525 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 20 Mar 2024 01:27:09 +0000 Subject: [PATCH 1/4] fix: isolated report download directory, fix read-pr-number step --- .github/workflows/comment-on-pr.yaml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/comment-on-pr.yaml b/.github/workflows/comment-on-pr.yaml index a6e7597..096c43b 100644 --- a/.github/workflows/comment-on-pr.yaml +++ b/.github/workflows/comment-on-pr.yaml @@ -19,12 +19,21 @@ jobs: id: report with: name: report + path: ${{ github.workspace }}/reports run-id: ${{ github.event.workflow_run.id }} github-token: ${{ secrets.GITHUB_TOKEN }} - name: Read PR number id: pr-number - run: echo "number=${$(basename -- ${{ steps.report.outputs.download-path }}/*.md)%.*}" >> "$GITHUB_OUTPUT" + # Glob the downloaded folder for reports, should only be one in the artifact; + # Then extract the PR number from the report name and write it to the output file. + run: | + reports=( "${{ steps.report.outputs.download-path }}/*.md" ) + if [ ${#reports[@]} -ne 1 ]; then + echo "Expected 1 report, found ${#reports[@]}" + exit 1 + fi + echo "number=$(basename -- ${reports[0]%.*})" >> "$GITHUB_OUTPUT" - name: Find Comment uses: peter-evans/find-comment@v3 From d919424e4338a04175b6d583185d0a19df16cefd Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 20 Mar 2024 01:34:48 +0000 Subject: [PATCH 2/4] fix: use basename instead of bash parameter expansion to get pr-number --- .github/workflows/comment-on-pr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/comment-on-pr.yaml b/.github/workflows/comment-on-pr.yaml index 096c43b..77d15a9 100644 --- a/.github/workflows/comment-on-pr.yaml +++ b/.github/workflows/comment-on-pr.yaml @@ -33,7 +33,7 @@ jobs: echo "Expected 1 report, found ${#reports[@]}" exit 1 fi - echo "number=$(basename -- ${reports[0]%.*})" >> "$GITHUB_OUTPUT" + echo "number=$(basename -- ${reports[0]} .md)" >> "$GITHUB_OUTPUT" - name: Find Comment uses: peter-evans/find-comment@v3 From 0720e4855ee45e492a0f0fda9cd47da519eee134 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 20 Mar 2024 01:40:59 +0000 Subject: [PATCH 3/4] fix: reporting conditions and wrong path to artifact --- .github/workflows/comment-on-pr.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/comment-on-pr.yaml b/.github/workflows/comment-on-pr.yaml index 77d15a9..6b17757 100644 --- a/.github/workflows/comment-on-pr.yaml +++ b/.github/workflows/comment-on-pr.yaml @@ -8,7 +8,7 @@ on: - completed jobs: - check-links: + comment-on-pr: runs-on: ubuntu-latest if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'skipped' permissions: @@ -46,7 +46,7 @@ jobs: # An comment exists here already, and now there's no issues from the link checker - name: Clear report - if: steps.fc.outputs.comment-id != '' + if: ${{ github.event.workflow_run.conclusion == 'success' && steps.fc.outputs.comment-id != '' }} uses: peter-evans/create-or-update-comment@v4 with: comment-id: ${{ steps.fc.outputs.comment-id }} @@ -57,7 +57,7 @@ jobs: # No comment exists here, and link checking found no issues - name: No issues - if: steps.fc.outputs.comment-id == '' + if: ${{ github.event.workflow_run.conclusion == 'success' && steps.fc.outputs.comment-id == '' }} uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ steps.pr-number.outputs.number }} @@ -71,7 +71,7 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: issue-number: ${{ steps.pr-number.outputs.number }} - body-path: "report.md" + body-path: "reports/${{ steps.pr-number.outputs.number }}.md" # Update existing comment with new report - name: Update report @@ -79,5 +79,5 @@ jobs: uses: peter-evans/create-or-update-comment@v4 with: comment-id: ${{ steps.fc.outputs.comment-id }} + body-path: "reports/${{ steps.pr-number.outputs.number }}.md" edit-mode: replace - body-path: report.md From ee6b3d28a92ce5a1ac02e02904d91e1f8b75847e Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Wed, 20 Mar 2024 01:45:10 +0000 Subject: [PATCH 4/4] docs: add a comment about workflow_run to the commenting actions workflow --- .github/workflows/comment-on-pr.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/comment-on-pr.yaml b/.github/workflows/comment-on-pr.yaml index 6b17757..b5b39fe 100644 --- a/.github/workflows/comment-on-pr.yaml +++ b/.github/workflows/comment-on-pr.yaml @@ -1,6 +1,11 @@ name: Comment on PR on: + # This workflow doesn't show up in the PR, only in the actions tab. We need to use this + # separated workflow because pull_request events from forks are not allowed to have a + # write-token, and we need that to comment on the incoming PR. Changes to this file will + # not take place during the PR, this workflow runs using the version of this file on the + # default branch. workflow_run: workflows: - Link Checking