diff --git a/.github/workflows/commit-checks.yml b/.github/workflows/commit-checks.yml index c9b71e46..0b6d3921 100644 --- a/.github/workflows/commit-checks.yml +++ b/.github/workflows/commit-checks.yml @@ -5,6 +5,7 @@ on: permissions: contents: read + pull-requests: write jobs: check-commits: @@ -25,10 +26,11 @@ jobs: HEAD_SHA: ${{ github.event.pull_request.head.sha }} run: scripts/ci/check-authorship.sh "$BASE_SHA" "$HEAD_SHA" - - name: Check GitHub Verified badge on each commit + - name: Advisory GitHub Verified badge check (comment only) env: BASE_SHA: ${{ github.event.pull_request.base.sha }} HEAD_SHA: ${{ github.event.pull_request.head.sha }} GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} run: scripts/ci/check-commit-verification.sh "$BASE_SHA" "$HEAD_SHA" diff --git a/AGENTS.md b/AGENTS.md index 2188ebaa..9b771bdb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,6 +5,19 @@ Follow [`CONTRIBUTING.md`](CONTRIBUTING.md). It is the source of truth for proje ## Agent workflow - Work on a feature branch off `main`; do not commit to `main`. -- Match this repo's commit checks CI: human author/committer (no AI-tool identities or AI `Co-authored-by` trailers), and every commit GitHub-**Verified**. Do not leave Cursor-signed commits on a human author (`Unverified` / `unknown_key`); the human author must re-sign with their GitHub signing key before merge (see CONTRIBUTING "Commit signatures"). +- Match this repo's commit checks CI; authors should sign commits with their GitHub signing key before merge (see CONTRIBUTING "Commit signatures"). +- Encode CI check behavior in scripts/workflows. Do not expand CONTRIBUTING or AGENTS to narrate soft-fail / advisory mechanics unless asked. - Before review, run `/no-comments` on the diff. - Prefer the smallest change that satisfies CONTRIBUTING; do not expand scope. + +## Comments + +Avoid code comments. Prefer types, names, tests, and structure so the code states intent without narration. + +- Do not add why-comments, how-comments, or section banners. +- Do not leave a comment that explains a workaround or hack — fix the root cause in the same change. +- Do not document temporary debt in comments; fix it or open a tracked issue and link the issue from the PR. +- Shell / CI scripts: Usage lines only when needed; no purpose essays above the shebang body. +- Allowed exceptions match CONTRIBUTING "Comments" (license headers, public API contracts, issue/RFC links for constraints code cannot express, behavior forced by an external dependency we cannot reshape). + +Rationale: [Lauren Tan (@poteto) on comments](https://x.com/poteto/status/2110758788525621282). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6114c44..7e79393d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -135,6 +135,7 @@ Rules: go test -covermode=atomic -coverprofile=coverage.out ./... go tool cover -func=coverage.out ``` + Coverage is not yet enforced in CI, but is a goal to work toward. All lines of code touched by changes should be covered by tests. ### Linting & Formatting @@ -182,7 +183,7 @@ Rationale: [Lauren Tan (@poteto) on comments](https://x.com/poteto/status/211075 ## CI Pipeline -- Build CI jobs (`test`, `mockup-syntax`, `lint`, `frontend`) run on `[self-hosted, Linux]` runners on every PR and push to `main`. Commit checks (`Check commits`: authorship + GitHub Verified) run on `ubuntu-latest` on every PR. +- Build CI jobs (`test`, `mockup-syntax`, `lint`, `frontend`) run on `[self-hosted, Linux]` runners on every PR and push to `main`. Commit checks run on `ubuntu-latest` on every PR. - macOS / Windows CI was removed in commit `9a0dae1` — cross-platform validation now lives in `.github/workflows/release.yml`. - All GitHub Actions must be SHA-pinned (no floating tags like `@v4`) @@ -193,17 +194,10 @@ Rationale: [Lauren Tan (@poteto) on comments](https://x.com/poteto/status/211075 ## Commit signatures -Every commit on a pull request must show as **Verified** on GitHub. CI runs -`scripts/ci/check-commit-verification.sh` as part of workflow **Check commits**. - - Sign with a GPG or SSH key registered to the commit author under GitHub → Settings → SSH and GPG keys (**Signing keys**, not only Authentication). - Enable signing locally (`git config commit.gpgsign true`, and for SSH: `gpg.format ssh` + `user.signingkey` pointing at your public key). -- **Unverified** means the commit is signed, but GitHub does not trust the key - for that author (common reason: `unknown_key`). Cursor / Cloud Agent SSH - signatures on human-authored commits produce this badge — re-sign as the - author before review: ```sh # After your signing key is registered on GitHub: diff --git a/scripts/ci/check-commit-verification.sh b/scripts/ci/check-commit-verification.sh index 2961c052..0bac8bdb 100755 --- a/scripts/ci/check-commit-verification.sh +++ b/scripts/ci/check-commit-verification.sh @@ -1,13 +1,12 @@ #!/usr/bin/env bash # -# Fail if any commit in a range is not GitHub-verified. -# GitHub's Commits API is authoritative; local git verify-commit is not. -# # Usage: check-commit-verification.sh [head-ref] # check-commit-verification.sh set -euo pipefail +COMMENT_MARKER='' + usage() { echo "usage: $0 [head-ref]" >&2 echo " $0 " >&2 @@ -37,29 +36,34 @@ if [ -z "$commits" ]; then fi api="https://api.github.com/repos/${GITHUB_REPOSITORY}/commits" +comments_api="https://api.github.com/repos/${GITHUB_REPOSITORY}/issues" auth_args=() if [ -n "${GITHUB_TOKEN:-}" ]; then auth_args=(-H "Authorization: Bearer ${GITHUB_TOKEN}") fi +gh_api() { + curl -sS \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${auth_args[@]}" \ + "$@" +} + violations=0 +report_lines=() for sha in $commits; do subject="$(git show -s --format='%s' "$sha")" - payload="$( - curl -sS \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "${auth_args[@]}" \ - "${api}/${sha}" - )" + payload="$(gh_api "${api}/${sha}")" if ! printf '%s' "$payload" | jq -e '.commit.verification' >/dev/null 2>&1; then violations=$((violations + 1)) - echo "FAILED: ${sha} ${subject}" + echo "UNVERIFIED: ${sha} ${subject}" echo " could not read commit.verification from GitHub API" msg="$(printf '%s' "$payload" | jq -r '.message // empty' 2>/dev/null || true)" [ -n "$msg" ] && echo " api: ${msg}" + report_lines+=("- \`${sha:0:7}\` ${subject} — API: could not read verification${msg:+ (${msg})}") continue fi @@ -68,19 +72,146 @@ for sha in $commits; do if [ "$verified" != "true" ]; then violations=$((violations + 1)) - echo "FAILED: ${sha} ${subject}" + echo "UNVERIFIED: ${sha} ${subject}" echo " verified: false (reason: ${reason})" + report_lines+=("- \`${sha:0:7}\` ${subject} — reason: \`${reason}\`") fi done +pr_number="${GITHUB_PR_NUMBER:-}" +if [ -z "$pr_number" ] && [ -n "${GITHUB_EVENT_PATH:-}" ] && [ -f "${GITHUB_EVENT_PATH}" ]; then + pr_number="$(jq -r '.pull_request.number // empty' "${GITHUB_EVENT_PATH}")" +fi + +find_sticky_comment_id() { + local page=1 + local payload + local id + while true; do + payload="$(gh_api "${comments_api}/${pr_number}/comments?per_page=100&page=${page}")" + if ! printf '%s' "$payload" | jq -e 'type == "array"' >/dev/null 2>&1; then + echo "warning: could not list PR comments" >&2 + msg="$(printf '%s' "$payload" | jq -r '.message // empty' 2>/dev/null || true)" + [ -n "$msg" ] && echo " api: ${msg}" >&2 + return 1 + fi + id="$(printf '%s' "$payload" | jq -r --arg m "$COMMENT_MARKER" '.[] | select(.body | contains($m)) | .id' | head -n1)" + if [ -n "$id" ]; then + printf '%s' "$id" + return 0 + fi + if [ "$(printf '%s' "$payload" | jq 'length')" -lt 100 ]; then + return 1 + fi + page=$((page + 1)) + done +} + +post_or_update_comment() { + local body="$1" + local existing_id + local http_code + local tmp + + if [ -z "${GITHUB_TOKEN:-}" ] || [ -z "$pr_number" ]; then + echo "advisory: skipping PR comment (GITHUB_TOKEN or GITHUB_PR_NUMBER unset)" + return 0 + fi + + existing_id="" + existing_id="$(find_sticky_comment_id || true)" + + tmp="$(mktemp)" + if [ -n "$existing_id" ]; then + http_code="$( + curl -sS -o "$tmp" -w '%{http_code}' \ + -X PATCH \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${auth_args[@]}" \ + -H "Content-Type: application/json" \ + --data "$(jq -n --arg body "$body" '{body: $body}')" \ + "${comments_api}/comments/${existing_id}" + )" + else + http_code="$( + curl -sS -o "$tmp" -w '%{http_code}' \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${auth_args[@]}" \ + -H "Content-Type: application/json" \ + --data "$(jq -n --arg body "$body" '{body: $body}')" \ + "${comments_api}/${pr_number}/comments" + )" + fi + + case "$http_code" in + 200 | 201) + echo "advisory: posted PR comment on #${pr_number}" + ;; + *) + echo "warning: failed to post PR comment (HTTP ${http_code}); check stays green" >&2 + jq -r '.message // empty' "$tmp" 2>/dev/null | sed '/^$/d' | sed 's/^/ api: /' >&2 || true + ;; + esac + rm -f "$tmp" +} + +delete_sticky_comment() { + local existing_id + local http_code + local tmp + + if [ -z "${GITHUB_TOKEN:-}" ] || [ -z "$pr_number" ]; then + return 0 + fi + + existing_id="" + existing_id="$(find_sticky_comment_id || true)" + [ -n "$existing_id" ] || return 0 + + tmp="$(mktemp)" + http_code="$( + curl -sS -o "$tmp" -w '%{http_code}' \ + -X DELETE \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${auth_args[@]}" \ + "${comments_api}/comments/${existing_id}" + )" + case "$http_code" in + 204) + echo "advisory: cleared stale PR comment on #${pr_number}" + ;; + *) + echo "warning: failed to delete stale PR comment (HTTP ${http_code})" >&2 + ;; + esac + rm -f "$tmp" +} + if [ "$violations" -gt 0 ]; then echo - echo "${violations} commit(s) are not GitHub-verified in range ${range}." - echo "Sign each commit with a GPG or SSH key registered to the commit" - echo "author on GitHub (Settings → SSH and GPG keys → Signing keys), then" - echo "force-push. A Cursor/Cloud-Agent SSH signature on a human-authored" - echo "commit yields reason=unknown_key (Unverified) — re-sign as the author." - exit 1 + echo "${violations} commit(s) are not GitHub-verified in range ${range} (advisory)." + + body="$( + cat <