From 8cd313fd58cb163d4ee83a6a845d0d52cb0f9fc0 Mon Sep 17 00:00:00 2001 From: Zev Isert Date: Mon, 18 Mar 2024 13:13:57 -0700 Subject: [PATCH] ci: comment on PR workflow (#315) * ci: insecure comment on PR workflow * ci: more secure comment on PR workflow * ci: create reports/ dir --- .github/workflows/comment-on-pr.yaml | 74 ++++++++++++++++++++++++++++ .github/workflows/link-checker.yaml | 54 +++----------------- 2 files changed, 82 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/comment-on-pr.yaml diff --git a/.github/workflows/comment-on-pr.yaml b/.github/workflows/comment-on-pr.yaml new file mode 100644 index 0000000..a6e7597 --- /dev/null +++ b/.github/workflows/comment-on-pr.yaml @@ -0,0 +1,74 @@ +name: Comment on PR + +on: + workflow_run: + workflows: + - Link Checking + types: + - completed + +jobs: + check-links: + runs-on: ubuntu-latest + if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion != 'skipped' + permissions: + pull-requests: write + steps: + - name: Download Report + uses: actions/download-artifact@v4 + id: report + with: + name: report + 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" + + - name: Find Comment + uses: peter-evans/find-comment@v3 + id: fc + if: github.event.workflow_run.event == 'pull_request' + with: + issue-number: ${{ steps.pr-number.outputs.number }} + comment-author: "github-actions[bot]" + body-includes: + + # An comment exists here already, and now there's no issues from the link checker + - name: Clear report + if: steps.fc.outputs.comment-id != '' + uses: peter-evans/create-or-update-comment@v4 + with: + comment-id: ${{ steps.fc.outputs.comment-id }} + edit-mode: replace + body: | + + Link checker still sees no broken links, all good! :tada: + + # No comment exists here, and link checking found no issues + - name: No issues + if: steps.fc.outputs.comment-id == '' + uses: peter-evans/create-or-update-comment@v4 + with: + issue-number: ${{ steps.pr-number.outputs.number }} + body: | + + Link checker found no broken links! :sparkles: + + # No comment exists here, and the link checker has found issues + - name: Create new report + 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 }} + body-path: "report.md" + + # Update existing comment with new report + - name: Update report + 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 }} + edit-mode: replace + body-path: report.md diff --git a/.github/workflows/link-checker.yaml b/.github/workflows/link-checker.yaml index 5d0251b..2184003 100644 --- a/.github/workflows/link-checker.yaml +++ b/.github/workflows/link-checker.yaml @@ -20,53 +20,15 @@ jobs: sudo apt-get update sudo apt-get install -y curl bash ca-certificates - - name: Find Comment - uses: peter-evans/find-comment@v3 - id: fc - if: github.event_name == 'pull_request' - with: - issue-number: ${{ github.event.pull_request.number }} - comment-author: "github-actions[bot]" - body-includes: - - name: Check links id: report - run: bash link_checker/check.sh README.md --markdown > report.md - - # An existing comment now has no issues - - name: Clear report - if: ${{ github.event_name == 'pull_request' && steps.fc.outputs.comment-id != '' }} - uses: peter-evans/create-or-update-comment@v4 - with: - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body: | - - Link checker still sees no broken links, all good! :tada: - - # No existing comment, and no issues found - - name: No issues - if: ${{ github.event_name == 'pull_request' && steps.fc.outputs.comment-id == '' }} - uses: peter-evans/create-or-update-comment@v4 - with: - issue-number: ${{ github.event.pull_request.number }} - body: | - - Link checker found no broken links! :sparkles: - - # No existing comment, but issues found - - name: Create new report - if: ${{ failure() && github.event_name == 'pull_request' && steps.report.conclusion == 'failure' && steps.fc.outputs.comment-id == '' }} - uses: peter-evans/create-or-update-comment@v4 - with: - issue-number: ${{ github.event.pull_request.number }} - body-path: "report.md" + run: | + mkdir -p reports + bash link_checker/check.sh README.md --markdown > reports/${{ github.event.pull_request.number }}.md - # Update existing comment with new report - - name: Update report - if: ${{ failure() && github.event_name == 'pull_request' && steps.report.conclusion == 'failure' && steps.fc.outputs.comment-id != '' }} - uses: peter-evans/create-or-update-comment@v4 + - uses: actions/upload-artifact@v4 + if: always() with: - comment-id: ${{ steps.fc.outputs.comment-id }} - edit-mode: replace - body-path: report.md + name: report + path: reports/${{ github.event.pull_request.number }}.md + retention-days: 5