diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 66cc41dbd5..03c269b5a7 100644 --- a/.github/workflows/build-pr-preview.yml +++ b/.github/workflows/build-pr-preview.yml @@ -320,8 +320,40 @@ jobs: run: | sed -i '1s/^/## Broken Link Checker\n/' ./lychee/out.md - - name: Comment on PR about a failed link check + # Get length of lychee output + - name: lychee output size check + id: char-count + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 if: steps.lychee.outputs.exit_code != 0 + with: + script: | + const size = require('fs').readFileSync('./lychee/out.md').length; + console.log(`${size} characters`); + core.setOutput('size', size); + + # If the char count of the lychee report is too long, it's going to break + # the sticky-pull-request-comment action because of a body size limitation + # on the GitHub PR comment API. So, instead, upload the full report to GH + # artifacts and just link to that instead + - name: Upload lychee report to GitHub artifacts + id: upload-artifact + if: steps.lychee.outputs.exit_code != 0 && fromJson(steps.char-count.outputs.size) >= fromJson(vars.BROKEN_LINK_REPORT_CHAR_MAX) + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2 + with: + path: ./lychee/out.md + name: Link Checker Report + + - name: Comment on PR with link to full link checker report + if: steps.lychee.outputs.exit_code != 0 && fromJson(steps.char-count.outputs.size) >= fromJson(vars.BROKEN_LINK_REPORT_CHAR_MAX) + uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 + with: + header: Link Checker Report + message: | + ## Broken Link Checker + Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters, so it cannot be displayed in GitHub comments. [Download full report.](${{steps.upload-artifact.outputs.artifact-url}}) + + - name: Comment on PR with link checker report + if: steps.lychee.outputs.exit_code != 0 && fromJson(steps.char-count.outputs.size) < fromJson(vars.BROKEN_LINK_REPORT_CHAR_MAX) uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 with: header: Link Checker Report