From 8055f29029067d200bf2b9b60d65f1aeb77fbb45 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Tue, 6 May 2025 15:53:05 -0400 Subject: [PATCH 1/5] Check report char count before adding to PR Checks the char count of the lychee broken link report prior to attaching to the PR. This is to help avoid a scenario where the report hits the 65536 char max count of the GH API --- .github/workflows/build-pr-preview.yml | 34 +++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 66cc41dbd5..762ee1cf90 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 && steps.char-count.outputs.size >= 65536 + 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 && steps.char-count.outputs.size >= 65536 + uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 + with: + header: Link Checker Report + message: | + ## Broken Link Checker + Report exceeds max length of 65536 characters. See ${{steps.upload-artifact.outputs.artifact-url}} for full report + + - name: Comment on PR with link checker report + if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size < 65536 uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 with: header: Link Checker Report From b383d73c40809861c311e9979a9eb34296aee74d Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Tue, 6 May 2025 16:35:28 -0400 Subject: [PATCH 2/5] Replace hard coded max char count with variable This allows us more flexibility to adjust the max length in the future without doing a find-and-replace accross the workflow file --- .github/workflows/build-pr-preview.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 762ee1cf90..28e48ab87b 100644 --- a/.github/workflows/build-pr-preview.yml +++ b/.github/workflows/build-pr-preview.yml @@ -337,23 +337,23 @@ jobs: # artifacts and just link to that instead - name: Upload lychee report to GitHub artifacts id: upload-artifact - if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size >= 65536 + if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size >= 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 && steps.char-count.outputs.size >= 65536 + if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size >= 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 65536 characters. See ${{steps.upload-artifact.outputs.artifact-url}} for full report + Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters. See ${{steps.upload-artifact.outputs.artifact-url}} for full report - name: Comment on PR with link checker report - if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size < 65536 + if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size < vars.BROKEN_LINK_REPORT_CHAR_MAX uses: marocchino/sticky-pull-request-comment@52423e01640425a022ef5fd42c6fb5f633a02728 # v2.9.1 with: header: Link Checker Report From e719427ea42a40049b6254cc5dcfff6711efe4e8 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Wed, 7 May 2025 13:11:49 -0400 Subject: [PATCH 3/5] Compare char count using fromJson function This compares the char count to the action variable numerically (integer to integer) rather than lexicographically. In this case, the report char count was '1209122' which is _technically_ greater than 65536(the configured max), but since the values were being compared lexicographically, and the string '1209122' begins with a 1, this expression was evaluating to '1209122' >= '65536'(since '1209122' begins with a 1). --- .github/workflows/build-pr-preview.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 28e48ab87b..92312fd9fe 100644 --- a/.github/workflows/build-pr-preview.yml +++ b/.github/workflows/build-pr-preview.yml @@ -337,14 +337,14 @@ jobs: # artifacts and just link to that instead - name: Upload lychee report to GitHub artifacts id: upload-artifact - if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size >= vars.BROKEN_LINK_REPORT_CHAR_MAX + 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 && steps.char-count.outputs.size >= vars.BROKEN_LINK_REPORT_CHAR_MAX + 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 @@ -353,7 +353,7 @@ jobs: Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters. See ${{steps.upload-artifact.outputs.artifact-url}} for full report - name: Comment on PR with link checker report - if: steps.lychee.outputs.exit_code != 0 && steps.char-count.outputs.size < vars.BROKEN_LINK_REPORT_CHAR_MAX + 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 From 998cd1b15095c6c398efc6396b77f8770e28074c Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Thu, 8 May 2025 15:36:44 -0400 Subject: [PATCH 4/5] Reword report link comment "Download full report" is a more actionable sentence than "See for full report" --- .github/workflows/build-pr-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 92312fd9fe..35121b3bf5 100644 --- a/.github/workflows/build-pr-preview.yml +++ b/.github/workflows/build-pr-preview.yml @@ -350,7 +350,7 @@ jobs: header: Link Checker Report message: | ## Broken Link Checker - Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters. See ${{steps.upload-artifact.outputs.artifact-url}} for full report + Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters. [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) From 4a73758f68d8cada9d0b911c21ed5a59253c9828 Mon Sep 17 00:00:00 2001 From: Robert Main <50675045+rmainwork@users.noreply.github.com> Date: Thu, 8 May 2025 15:40:23 -0400 Subject: [PATCH 5/5] Provide additional context regarding char limit --- .github/workflows/build-pr-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr-preview.yml b/.github/workflows/build-pr-preview.yml index 35121b3bf5..03c269b5a7 100644 --- a/.github/workflows/build-pr-preview.yml +++ b/.github/workflows/build-pr-preview.yml @@ -350,7 +350,7 @@ jobs: header: Link Checker Report message: | ## Broken Link Checker - Report exceeds max length of ${{vars.BROKEN_LINK_REPORT_CHAR_MAX}} characters. [Download full report.](${{steps.upload-artifact.outputs.artifact-url}}) + 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)