From 333228e3f1327f55cb343a82db930cf6b6294129 Mon Sep 17 00:00:00 2001 From: Graham Beckley Date: Fri, 20 Feb 2026 12:13:50 -0500 Subject: [PATCH 1/2] chore(helm-diff): Use step summary or uploaded artifact in comments When we post helm diff comments in PRs, the diffs can be long and are split up across many comments. In this commit, we instead send the diff to the job summary or upload it as an artifact if it's too large, then link to that summary or artifact in the comment instead. This will hopefully lead to fewer comments and unified diffs. --- .github/workflows/diff-rendered-charts.yml | 101 ++++++++++----------- 1 file changed, 47 insertions(+), 54 deletions(-) diff --git a/.github/workflows/diff-rendered-charts.yml b/.github/workflows/diff-rendered-charts.yml index 94685d3..a91289a 100644 --- a/.github/workflows/diff-rendered-charts.yml +++ b/.github/workflows/diff-rendered-charts.yml @@ -3,7 +3,7 @@ # file, You can obtain one at https://mozilla.org/MPL/2.0/. # Reusable workflow to render and diff helm charts between the head and base ref of a pull request -# A comment is made on the pull request containing the diff output +# The diff output is posted as a job summary name: render and diff helm charts on: @@ -123,58 +123,51 @@ jobs: done env: CHARTS: ${{ needs.get_changed_helm_charts.outputs.charts }} - - name: post diff as comment on pull request + - name: post diff as job summary + id: post_diff if: needs.get_changed_helm_charts.outputs.charts != '' - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 + run: | + if [ ! -f diff.log ]; then + echo "diff.log not found" + exit 0 + fi + max_size=$((1024 * 1024)) + file_size=$(stat --format=%s diff.log) + if [ "$file_size" -gt "$max_size" ]; then + echo "diff_too_large=true" >> "$GITHUB_OUTPUT" + echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" + echo '' >> "$GITHUB_STEP_SUMMARY" + echo "Diff output exceeds 1MiB and is too large to display inline. Download the \`helm-diff\` artifact to view the full diff." >> "$GITHUB_STEP_SUMMARY" + else + echo "diff_too_large=false" >> "$GITHUB_OUTPUT" + echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" + echo '
Show Output' >> "$GITHUB_STEP_SUMMARY" + echo '' >> "$GITHUB_STEP_SUMMARY" + echo '```diff' >> "$GITHUB_STEP_SUMMARY" + cat diff.log >> "$GITHUB_STEP_SUMMARY" + echo '```' >> "$GITHUB_STEP_SUMMARY" + echo '
' >> "$GITHUB_STEP_SUMMARY" + fi + + - name: upload diff artifact + if: steps.post_diff.outputs.diff_too_large == 'true' + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f #v6.0.0 with: - script: | - const fs = require('fs'); - const comment_char_limit = 65536; // GitHub comment character limit - const diff_file = 'diff.log'; - - if (fs.existsSync(diff_file)) { - var diff = fs.readFileSync(diff_file, 'utf8'); - } else { - console.log(diff_file + " not found") - return - } - - function splitComment(comment, maxSize, sepEnd, sepStart, comStart) { - // Adapted from Atlantis SplitComment function - // https://github.com/runatlantis/atlantis/blob/main/server/events/vcs/common/common.go#L18 - if (comment.length <= (comment_char_limit - comStart.length)) { - return [comStart + diff] - } - maxWithSep = comment_char_limit - sepEnd.length - sepStart.length; - var comments = []; - var numComments = Math.ceil(comment.length / maxWithSep); - for (var i = 0; i < numComments; i++) { - var upTo = Math.min(comment.length, (i + 1) * maxWithSep); - var portion = comment.slice(i * maxWithSep, upTo); - if (i < numComments - 1) { - portion += sepEnd; - } - if (i > 0) { - portion = sepStart + portion - } else { - portion = comStart + portion - } - comments.push(portion); - } - return comments; - } - - var sepEnd = "\n```\n" + "\n
\n\n**Warning**: Output length greater than max comment size. Continued in next comment."; - var sepStart = "Continued from previous comment.\n
Show Output\n\n" + "```diff\n"; - var comStart = "Changes found in Helm charts.\n
Show Output\n\n" + "```diff\n"; - - comments = splitComment(diff, comment_char_limit, sepEnd, sepStart, comStart); - - for (const comment of comments) { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: comment - }) - } + name: helm-diff + path: diff.log + + - name: comment on pull request + if: steps.post_diff.outputs.diff_too_large != '' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + DIFF_TOO_LARGE: ${{ steps.post_diff.outputs.diff_too_large }} + PR_NUMBER: ${{ github.event.number }} + run: | + run_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" + if [ "$DIFF_TOO_LARGE" = "true" ]; then + body="Helm chart changes detected. The diff is too large for the job summary. Download the \`helm-diff\` artifact from the [workflow run](${run_url})." + else + body="Helm chart changes detected. View the diff in the [job summary](${run_url})." + fi + gh pr comment "$PR_NUMBER" --body "$body" From 3672e425f62e99f803244c0961598b5841e793db Mon Sep 17 00:00:00 2001 From: Graham Beckley Date: Thu, 5 Mar 2026 12:39:57 -0500 Subject: [PATCH 2/2] chore(helm-diff): Post the helm diff in the comment if it will fit - If the diff can fit in one comment, post it in the comment as well as the step summary - if the diff would span multiple comments, link to the step summary -if the diff can't fit in the step summary, link to an uploaded artifact --- .github/workflows/diff-rendered-charts.yml | 85 ++++++++++++++++------ 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/.github/workflows/diff-rendered-charts.yml b/.github/workflows/diff-rendered-charts.yml index a91289a..e3e3823 100644 --- a/.github/workflows/diff-rendered-charts.yml +++ b/.github/workflows/diff-rendered-charts.yml @@ -123,8 +123,8 @@ jobs: done env: CHARTS: ${{ needs.get_changed_helm_charts.outputs.charts }} - - name: post diff as job summary - id: post_diff + - name: classify diff + id: classify_diff if: needs.get_changed_helm_charts.outputs.charts != '' run: | if [ ! -f diff.log ]; then @@ -132,42 +132,81 @@ jobs: exit 0 fi max_size=$((1024 * 1024)) + comment_limit=65000 file_size=$(stat --format=%s diff.log) if [ "$file_size" -gt "$max_size" ]; then echo "diff_too_large=true" >> "$GITHUB_OUTPUT" - echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" - echo '' >> "$GITHUB_STEP_SUMMARY" - echo "Diff output exceeds 1MiB and is too large to display inline. Download the \`helm-diff\` artifact to view the full diff." >> "$GITHUB_STEP_SUMMARY" + echo "diff_fits_in_comment=false" >> "$GITHUB_OUTPUT" else echo "diff_too_large=false" >> "$GITHUB_OUTPUT" - echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" - echo '
Show Output' >> "$GITHUB_STEP_SUMMARY" - echo '' >> "$GITHUB_STEP_SUMMARY" - echo '```diff' >> "$GITHUB_STEP_SUMMARY" - cat diff.log >> "$GITHUB_STEP_SUMMARY" - echo '```' >> "$GITHUB_STEP_SUMMARY" - echo '
' >> "$GITHUB_STEP_SUMMARY" + if [ "$file_size" -le "$comment_limit" ]; then + echo "diff_fits_in_comment=true" >> "$GITHUB_OUTPUT" + else + echo "diff_fits_in_comment=false" >> "$GITHUB_OUTPUT" + fi fi + - name: post diff as comment + if: steps.classify_diff.outputs.diff_fits_in_comment == 'true' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.number }} + run: | + { + echo "Helm chart changes detected." + echo "" + echo "
Show Diff" + echo "" + echo '```diff' + cat diff.log + echo '```' + echo "" + echo "
" + } > comment_body.txt + gh pr comment "$PR_NUMBER" --body-file comment_body.txt + echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" + echo '
Show Output' >> "$GITHUB_STEP_SUMMARY" + echo '' >> "$GITHUB_STEP_SUMMARY" + echo '```diff' >> "$GITHUB_STEP_SUMMARY" + cat diff.log >> "$GITHUB_STEP_SUMMARY" + echo '```' >> "$GITHUB_STEP_SUMMARY" + echo '
' >> "$GITHUB_STEP_SUMMARY" + + - name: post diff as job summary + if: steps.classify_diff.outputs.diff_fits_in_comment == 'false' && steps.classify_diff.outputs.diff_too_large == 'false' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.number }} + run: | + echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" + echo '
Show Output' >> "$GITHUB_STEP_SUMMARY" + echo '' >> "$GITHUB_STEP_SUMMARY" + echo '```diff' >> "$GITHUB_STEP_SUMMARY" + cat diff.log >> "$GITHUB_STEP_SUMMARY" + echo '```' >> "$GITHUB_STEP_SUMMARY" + echo '
' >> "$GITHUB_STEP_SUMMARY" + run_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" + gh pr comment "$PR_NUMBER" --body "Helm chart changes detected. View the diff in the [job summary](${run_url})." + - name: upload diff artifact - if: steps.post_diff.outputs.diff_too_large == 'true' + id: upload_artifact + if: steps.classify_diff.outputs.diff_too_large == 'true' uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f #v6.0.0 with: name: helm-diff path: diff.log - - name: comment on pull request - if: steps.post_diff.outputs.diff_too_large != '' + - name: post artifact link + if: steps.classify_diff.outputs.diff_too_large == 'true' env: GH_TOKEN: ${{ github.token }} GH_REPO: ${{ github.repository }} - DIFF_TOO_LARGE: ${{ steps.post_diff.outputs.diff_too_large }} PR_NUMBER: ${{ github.event.number }} + ARTIFACT_URL: ${{ steps.upload_artifact.outputs.artifact-url }} run: | - run_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" - if [ "$DIFF_TOO_LARGE" = "true" ]; then - body="Helm chart changes detected. The diff is too large for the job summary. Download the \`helm-diff\` artifact from the [workflow run](${run_url})." - else - body="Helm chart changes detected. View the diff in the [job summary](${run_url})." - fi - gh pr comment "$PR_NUMBER" --body "$body" + echo "Changes found in Helm charts." >> "$GITHUB_STEP_SUMMARY" + echo '' >> "$GITHUB_STEP_SUMMARY" + echo "Diff output exceeds 1MiB and is too large to display inline. [Download the helm-diff artifact](${ARTIFACT_URL}) to view the full diff." >> "$GITHUB_STEP_SUMMARY" + gh pr comment "$PR_NUMBER" --body "Helm chart changes detected. The diff is too large to display inline. [Download the helm-diff artifact](${ARTIFACT_URL}) to view the full diff."