Skip to content

feat(ci,codequality): post sticky PR quality reports via check_run workflow - #1273

Merged
kyasbal merged 1 commit into
mainfrom
push-onslnvqszqwy
Nov 13, 2026
Merged

kyasbal merged 1 commit into
mainfrom
push-onslnvqszqwy

Conversation

@kyasbal

@kyasbal kyasbal commented Nov 13, 2026

Copy link
Copy Markdown
Member

Summary

Adds a token-free sticky GitHub PR comment reporter for the Cloud Build github-codequality check using GitHub Actions' native on: check_run event and built-in secrets.GITHUB_TOKEN (github-actions[bot]) — requiring zero Personal Access Tokens, GitHub Apps, or Secret Manager secrets.

How It Works

  1. Cloud Build Check Run Envelope (scripts/codequality, scripts/run-codequality-ci.sh, .cloudbuild/github-codequality.yaml):
    • When --comment-envelope is enabled (automatically enabled in Cloud Build when BUILD_ID is present), codequality appends a Base64-encoded Markdown summary (<!-- khi-codequality-report --> + RenderGitHubSummary + commit SHA and Cloud Build log link, capped at 24 KB raw / 32 KB Base64) delimited by KHI_CODEQUALITY_B64_BEGIN and KHI_CODEQUALITY_B64_END.
    • Cloud Build's INCLUDE_BUILD_LOGS_WITH_STATUS attaches this output directly to the GitHub Check Run (output.text).
  2. Lightweight check_run Comment Poster (.github/workflows/codequality-comment.yaml, scripts/post-codequality-pr-comment.sh):
    • Triggers on check_run: [completed] when app.slug == 'google-cloud-build' and startsWith(name, 'github-codequality').
    • Uses sparse checkout (scripts only) on the default branch (main) and secrets.GITHUB_TOKEN (permissions: pull-requests: write, checks: read).
    • Resolves open PR(s) whose current head.sha matches check_run.head_sha (preventing stale out-of-order runs from overwriting newer commit reports), decodes the embedded Base64 Markdown report (or generates a fallback summary if Cloud Build failed before codequality ran), and creates or PATCH-updates the single sticky comment (<!-- khi-codequality-report -->).

Note: Per GitHub Actions webhook rules, on: check_run workflows activate once merged into the repository's default branch (main).

Verification

  • go test ./scripts/... (including hermetic post-codequality-pr-comment.sh integration tests): PASS
  • make codequality-ci: PASS (0 violations) — Patch coverage 100.0% (79/79), Mutation score 100.0% (29/29 killed)
  • make pre-commit: PASS

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism to post and update sticky code quality reports as PR comments from Google Cloud Build. It adds a new bash script scripts/post-codequality-pr-comment.sh to extract Base64-encoded report envelopes from Check Run logs and upsert them to GitHub, along with corresponding Go CLI flags, formatting logic, and comprehensive unit tests. Feedback on the PR highlights a potential SIGPIPE crash (exit code 141) in the bash script when using head -n 1 in a pipeline with set -o pipefail, suggesting a safer way to extract the first comment ID using bash parameter expansion.

Comment on lines +93 to +98
local existing_id
existing_id="$(
gh api --paginate "repos/${GITHUB_REPO}/issues/${pr_number}/comments" \
--jq ".[] | select(.body | contains(\"${COMMENT_MARKER}\")) | .id" \
| head -n 1
)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using head -n 1 in a pipeline with set -o pipefail can cause the script to crash with a SIGPIPE error (exit code 141) if the upstream command (gh api) produces more output than head reads. This is highly likely to happen on PRs with many comments. To prevent this, fetch all matching comment IDs into a variable and extract the first ID using bash parameter expansion, which avoids the pipeline and SIGPIPE entirely.

Suggested change
local existing_id
existing_id="$(
gh api --paginate "repos/${GITHUB_REPO}/issues/${pr_number}/comments" \
--jq ".[] | select(.body | contains(\"${COMMENT_MARKER}\")) | .id" \
| head -n 1
)"
local existing_ids
existing_ids="$(gh api --paginate "repos/${GITHUB_REPO}/issues/${pr_number}/comments" --jq ".[] | select(.body | contains(\"${COMMENT_MARKER}\")) | .id")"
local existing_id="${existing_ids%%$'\n'*}"
@kyasbal
kyasbal added this pull request to the merge queue Nov 13, 2026
Merged via the queue into main with commit a9f42c0 Nov 13, 2026
22 checks passed
@kyasbal
kyasbal deleted the push-onslnvqszqwy branch November 13, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant