diff --git a/.github/workflows/ai-attribution.yml b/.github/workflows/ai-attribution.yml deleted file mode 100644 index d53d9834dc..0000000000 --- a/.github/workflows/ai-attribution.yml +++ /dev/null @@ -1,180 +0,0 @@ -name: AI Attribution - -on: - pull_request: - types: [opened, edited, synchronize, reopened] - -permissions: - contents: read - -jobs: - lint-trailers: - name: Commits omit AI attribution trailers - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - - name: Check commit trailers - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - GH_TOKEN: ${{ github.token }} - run: | - # CONTRIBUTING.md and AGENTS.md both state: - # - # "Do not include Co-Authored-By trailers for AI tools in commit - # messages. Attribution should be limited to human contributors." - # - # This job enforces that. It does NOT try to recognise an AI by its - # name. Names are not a usable signal in either direction: Claude and - # Devin are ordinary human given names, so matching on them rejects - # real contributors, while any list of product names is stale the - # moment a new agent ships. - # - # Instead a co-author is rejected only on evidence that the identity - # is not a person: - # - # 1. Its GitHub privacy address resolves to an account of type Bot. - # GitHub is the authority here, and agents commit through GitHub - # Apps, so this keeps working for tools that do not exist yet. - # 2. Its address is a noreply@ mailbox on some other domain - a - # fabricated, uncontactable address. No person's git identity is - # noreply@. - # - # A false positive costs far more than a false negative here: a - # missed trailer is untidy attribution, but a blocked contributor is - # a person turned away by a linter. So anything this cannot resolve - # is allowed through, and a GitHub API failure never fails the build. - # - # Merge commits are skipped via --no-merges, matching the - # Conventional Commits job. - - # Bot accounts that may legitimately co-author. Keep this short. - ALLOWED_BOTS='dependabot[bot]' - - # Trailer keys and generator markers that are AI-only by construction. - # These are literal strings no person writes, not identity matching. - AI_ONLY_TRAILER='^(claude-session|codex-session|chatgpt-session):' - AI_MARKER='(Generated with \[Claude Code\]|🤖 Generated with)' - - CACHE=$(mktemp) - FAILED=0 - - # Prints "bot " if the address belongs to a bot account, - # "noreply" for a fabricated noreply mailbox, nothing otherwise. - classify() { - local email="$1" local_part login id cached type - local_part=${email%@*} - - case "$email" in - *@users.noreply.github.com) - case "$local_part" in - *+*) id=${local_part%%+*}; login=${local_part#*+} ;; - *) id=""; login=$local_part ;; - esac - - # A [bot] suffix is GitHub's own convention; no lookup needed. - case "$login" in - *'[bot]'*) printf 'bot %s' "$login"; return ;; - esac - - cached=$(grep -m1 "^${id}|${login} " "$CACHE" 2>/dev/null || true) - if [ -n "$cached" ]; then - type=${cached##* } - else - if [ -n "$id" ]; then - type=$(gh api "user/$id" --jq .type 2>/dev/null || echo "") - else - type=$(gh api "users/$login" --jq .type 2>/dev/null || echo "") - fi - # Unresolvable (deleted account, API trouble) is not evidence. - [ -z "$type" ] && type="Unknown" - printf '%s|%s %s\n' "$id" "$login" "$type" >> "$CACHE" - fi - - if [ "$type" = "Bot" ]; then - printf 'bot %s' "$login" - fi - ;; - *) - # noreply@example.com, but not GitHub's own privacy domain. - case "$local_part" in - noreply|no-reply) printf 'noreply' ;; - esac - ;; - esac - # Never let a "this is a person" verdict look like a failure: - # the job runs under set -e and this is called in a $( ). - return 0 - } - - for sha in $(git log --no-merges --format=%H "$BASE_SHA".."$HEAD_SHA"); do - subject=$(git show -s --format=%s "$sha") - offending="" - - while IFS= read -r line; do - lower=$(printf '%s' "$line" | tr '[:upper:]' '[:lower:]') - - case "$lower" in - co-authored-by:*) - email=$(printf '%s' "$lower" | sed -n 's/.*<\(.*\)>.*/\1/p') - [ -z "$email" ] && continue - - verdict=$(classify "$email") - case "$verdict" in - bot\ *) - login=${verdict#bot } - # -F because a login like dependabot[bot] is not a pattern. - if ! printf '%s\n' "$ALLOWED_BOTS" | grep -Fxq "$login"; then - offending="${offending}${line} <- ${login} is a bot account"$'\n' - fi - ;; - noreply) - offending="${offending}${line} <- noreply address, not a contactable person"$'\n' - ;; - esac - ;; - *) - offending="${offending}${line}"$'\n' - ;; - esac - done < <(git show -s --format=%B "$sha" | grep -iE "^co-authored-by:|$AI_ONLY_TRAILER|$AI_MARKER" || true) - - if [ -n "$offending" ]; then - echo "::error::Commit carries AI attribution: $sha $subject" - echo "" - echo " Commit: $sha" - echo " $subject" - echo "" - echo " Offending line(s):" - printf '%s' "$offending" | sed 's/^/ /' - echo "" - FAILED=1 - else - echo "ok: $sha $subject" - fi - done - - if [ "$FAILED" -ne 0 ]; then - echo "" - echo " CONTRIBUTING.md: \"Do not include Co-Authored-By trailers for AI tools in" - echo " commit messages. Attribution should be limited to human contributors.\"" - echo "" - echo " Co-authoring a person is fine and is never rejected — this only fires when" - echo " the address belongs to a bot account or is a noreply mailbox." - echo "" - echo " To fix a single commit:" - echo " git commit --amend # delete the trailer lines, save" - echo " git push --force-with-lease" - echo "" - echo " To fix several:" - echo " git rebase --root -x 'git commit --amend --no-edit'" - echo "" - echo " Configure your agent not to add them in the first place — for Claude Code," - echo " set includeCoAuthoredBy: false in .claude/settings.json." - fi - - exit $FAILED diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb9d12c5bf..7cd940395d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,6 @@ on: - 'pom.xml' - '.github/ci/**' - '.github/workflows/ci.yml' - - '.github/workflows/pr-draft-gate.yml' pull_request: # ready_for_review is not a default type: without it, marking a draft ready # would not start the run the draft skipped. @@ -19,7 +18,6 @@ on: - 'pom.xml' - '.github/ci/**' - '.github/workflows/ci.yml' - - '.github/workflows/pr-draft-gate.yml' permissions: contents: read @@ -35,10 +33,6 @@ env: SHARD_TOTAL: 4 jobs: - # Drafts skip the suite to spare runners; it runs once the PR is ready for review. - draft-gate: - uses: ./.github/workflows/pr-draft-gate.yml - test: name: Build and Test (shard ${{ matrix.shard }}) runs-on: ubuntu-latest @@ -46,7 +40,16 @@ jobs: # runner spent it. This is a runaway-job kill switch, not a budget: Actions bills the minutes a # job actually uses, so a higher ceiling costs nothing until something hangs. timeout-minutes: 20 - needs: draft-gate + # Drafts skip the suite to spare runners; it runs once the PR is ready for review. + # Written on the job rather than as a gate job so it costs no runner. Pushes to main + # always run; `closed` and `edited` are excluded so widening the trigger types cannot + # let those events through. + if: >- + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) strategy: fail-fast: false matrix: @@ -174,9 +177,17 @@ jobs: name: CI summary runs-on: ubuntu-latest timeout-minutes: 10 - needs: [draft-gate, test] - # Without the gate check, always() would run this on a draft and fail on the skipped shards. - if: always() && needs.draft-gate.result == 'success' + needs: test + # always() so a failed shard still reaches the partition check and report, but not on a + # draft: there the shards are skipped and this would fail on them. Same condition as the shards. + if: >- + always() && ( + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) + ) steps: - name: Fail if any shard failed if: needs.test.result != 'success' diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml index 9fd3673869..2ad3991445 100644 --- a/.github/workflows/compatibility.yml +++ b/.github/workflows/compatibility.yml @@ -21,7 +21,6 @@ on: - '.github/ci/compat-opentofu-allowlist-tf-only.txt' - '.github/ci/compat-opentofu-allowlist-otf-only.txt' - '.github/workflows/compatibility.yml' - - '.github/workflows/pr-draft-gate.yml' permissions: contents: read @@ -31,15 +30,20 @@ concurrency: cancel-in-progress: true jobs: - # Drafts skip the suite to spare runners; it runs once the PR is ready for review. - draft-gate: - uses: ./.github/workflows/pr-draft-gate.yml - docker-runner-regression: name: compat / Docker runner failure aggregation runs-on: ubuntu-24.04 timeout-minutes: 5 - needs: draft-gate + # Drafts skip the suite to spare runners; it runs once the PR is ready for review. + # Written on the job rather than as a gate job so it costs no runner. Pushes to main + # always run; `closed` and `edited` are excluded so widening the trigger types cannot + # let those events through. + if: >- + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -50,7 +54,13 @@ jobs: name: compat / aws CLI endpoint resolution runs-on: ubuntu-24.04-arm timeout-minutes: 10 - needs: draft-gate + # Same draft condition as docker-runner-regression above. + if: >- + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -129,7 +139,13 @@ jobs: name: compat / opentofu resource parity runs-on: ubuntu-24.04-arm timeout-minutes: 5 - needs: draft-gate + # Same draft condition as docker-runner-regression above. + if: >- + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: @@ -144,7 +160,13 @@ jobs: name: Build native floci image (${{ matrix.arch }}) runs-on: ${{ matrix.runner }} timeout-minutes: 30 - needs: draft-gate + # Same draft condition as docker-runner-regression above. + if: >- + github.event_name != 'pull_request' || ( + github.event.pull_request.draft == false && + github.event.pull_request.state != 'closed' && + github.event.action != 'edited' + ) # Both published architectures. The native image is the only place an # arch-specific resource can go missing (snappy-java's JNI library is # registered per platform), and one arch cannot prove the other. diff --git a/.github/workflows/conventional-commits.yml b/.github/workflows/conventional-commits.yml deleted file mode 100644 index d3ea3552c4..0000000000 --- a/.github/workflows/conventional-commits.yml +++ /dev/null @@ -1,92 +0,0 @@ -name: Conventional Commits - -on: - pull_request: - types: [opened, edited, synchronize, reopened] - -permissions: - contents: read - -jobs: - lint-commits: - name: Title and commits follow Conventional Commits - runs-on: ubuntu-latest - - env: - # Conventional Commits pattern: - # [optional scope]: - # - # Types recognised by semantic-release (commit-analyzer defaults): - # feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci - # - # Breaking changes are signalled by appending ! before the colon: - # feat!: or feat(scope)!: - # - # References: - # https://www.conventionalcommits.org/en/v1.0.0/ - PATTERN: '^(feat|fix|perf|revert|docs|style|chore|refactor|test|build|ci)(\([-a-zA-Z0-9_.,]+\))?!?: .{1,}' - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - - name: Validate PR title - env: - PR_TITLE: ${{ github.event.pull_request.title }} - run: | - # The PR title becomes the squash-merge commit message on main, - # which is what semantic-release actually reads - so it must be - # conventional even when the individual commits on the branch - # are just WIP history that gets squashed away. - - if echo "$PR_TITLE" | grep -qE "$PATTERN"; then - echo "ok: $PR_TITLE" - else - echo "::error::PR title does not follow Conventional Commits: $PR_TITLE" - echo "" - echo " Got: $PR_TITLE" - echo "" - echo " Expected format: [optional scope]: " - echo " Examples:" - echo " feat(dynamodb): add PartiQL ExecuteStatement support" - echo " fix(s3): make us-east-1 bucket creation idempotent" - echo " chore: release 1.5.16" - echo " feat!: remove legacy endpoint" - echo "" - echo " Valid types: feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci" - echo " See: https://www.conventionalcommits.org/en/v1.0.0/" - exit 1 - fi - - - name: Validate commit messages - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - # Merge commits are skipped automatically via --no-merges. - - FAILED=0 - - while IFS= read -r msg; do - if echo "$msg" | grep -qE "$PATTERN"; then - echo "ok: $msg" - else - echo "::error::Commit does not follow Conventional Commits: $msg" - echo "" - echo " Got: $msg" - echo "" - echo " Expected format: [optional scope]: " - echo " Examples:" - echo " feat(dynamodb): add PartiQL ExecuteStatement support" - echo " fix(s3): make us-east-1 bucket creation idempotent" - echo " chore: release 1.5.16" - echo " feat!: remove legacy endpoint" - echo "" - echo " Valid types: feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci" - echo " See: https://www.conventionalcommits.org/en/v1.0.0/" - FAILED=1 - fi - done < <(git log --no-merges --format="%s" "$BASE_SHA".."$HEAD_SHA") - - exit $FAILED diff --git a/.github/workflows/doc-style.yml b/.github/workflows/doc-style.yml deleted file mode 100644 index 381ec62604..0000000000 --- a/.github/workflows/doc-style.yml +++ /dev/null @@ -1,65 +0,0 @@ -name: Documentation Style - -on: - pull_request: - # "edited" also fires when the PR is retargeted to a different base - # branch, which changes what counts as a newly added file. - types: [opened, edited, synchronize, reopened] - -permissions: - contents: read - -jobs: - no-em-dashes: - name: New files omit em-dashes - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - - name: Check new files for em-dashes - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - # AGENTS.md: "No em-dashes anywhere, in any content. Use colons, - # commas, or periods." - # - # Scoped to files this PR adds, not lines changed in existing - # ones: plenty of existing content already has em-dashes, and - # flagging every PR that happens to touch one of those files - # would make this check noise rather than signal. New files - # start clean. - - # Written as an escape, not the literal glyph: this workflow file - # is itself a new file the first time it's added, and the check - # below would otherwise flag itself for containing the character - # it's searching for. - EM_DASH=$'\u2014' - FAILED=0 - - # -z / -d '' throughout: plain --name-only C-quotes paths with - # non-ASCII or special characters (e.g. "caf\303\251.md"), which - # then fail to match the real file on disk and get silently - # skipped. NUL-delimited output/reads sidestep that. - while IFS= read -r -d '' file; do - [ -z "$file" ] && continue - - MATCHES=$(grep -InH "$EM_DASH" -- "$file" || true) - [ -z "$MATCHES" ] && continue - - FAILED=1 - while IFS=: read -r path lineno content; do - echo "::error file=$path,line=$lineno::Em-dash found in new file (AGENTS.md: no em-dashes anywhere, in any content)" - echo " $path:$lineno: $content" - done <<< "$MATCHES" - done < <(git diff -z --diff-filter=A --name-only "$BASE_SHA" "$HEAD_SHA") - - if [ "$FAILED" -eq 1 ]; then - echo "" - echo "Use colons, commas, or periods instead of em-dashes (U+2014). See AGENTS.md, Documentation Style." - fi - - exit $FAILED diff --git a/.github/workflows/pr-draft-gate.yml b/.github/workflows/pr-draft-gate.yml deleted file mode 100644 index 20ad48a3d1..0000000000 --- a/.github/workflows/pr-draft-gate.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: PR Draft Gate - -# Reusable gate for the expensive PR workflows (CI, Compatibility Tests). Callers -# make their jobs `needs:` the `gate` job: when it is skipped, every job that needs -# it is skipped too, so a draft PR spends no runner time on the heavy suites. -# -# A reusable workflow sees the caller's `github` context, so the condition below -# evaluates against the caller's event. Non-PR events (push to main) always pass. -# `closed` and `edited` are excluded as well, so a caller can widen its trigger -# types without this gate letting those events through. -# -# Callers must list `ready_for_review` in their pull_request types: it is not a -# default type, and without it marking a draft ready would not start the run the -# draft skipped. - -on: - workflow_call: - -permissions: {} - -jobs: - gate: - name: Skip draft PRs - runs-on: ubuntu-latest - timeout-minutes: 1 - if: >- - github.event_name != 'pull_request' || ( - github.event.pull_request.draft == false && - github.event.pull_request.state != 'closed' && - github.event.action != 'edited' - ) - steps: - - name: Not a draft - run: echo "Not a draft PR, running the suite." diff --git a/.github/workflows/pr-hygiene.yml b/.github/workflows/pr-hygiene.yml new file mode 100644 index 0000000000..0dfc75baee --- /dev/null +++ b/.github/workflows/pr-hygiene.yml @@ -0,0 +1,450 @@ +name: PR Hygiene + +# The per-PR checks that need no build: commit signatures, AI attribution +# trailers, Conventional Commits, em-dashes in new files and the PR template. +# They used to be five workflows with one job each. Every push then started +# five runners for about ten seconds of work apiece, and at busy times those +# jobs queued for up to twenty minutes behind the CI shards and the +# compatibility suites under the account's concurrent-job limit. One job with +# one step per check keeps each check's name, log section and annotations +# while taking a single runner. +# +# Every check step runs under `!cancelled()`, so a failure in one does not +# hide the others: the job fails if any of them failed, and the step that +# failed names the check. +# +# All five checks run on every event, including `edited`. With one job, the +# latest run's result replaces the previous one, so skipping the signature +# check on a title or body edit would turn an unsigned PR green. It is one +# API call, so running it on edits costs nothing. + +on: + pull_request: + # "edited" also fires when the PR is retargeted to a different base + # branch, which changes the commit range and what counts as a new file. + types: [opened, edited, synchronize, reopened] + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + hygiene: + name: PR hygiene + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + + - name: Commits are signed and verified + if: ${{ !cancelled() }} + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + run: | + # The repo's branch protection already requires every commit to be + # signed and verified before a PR can merge, but that only shows up + # as a generic red status on the merge button. This front-runs it + # with a per-commit annotation, using the same signal GitHub's merge + # gate uses (the commit's `verification` field from the API). + # + # Local `git log --show-signature` only verifies against keys the + # runner already trusts, which is nobody's, so it would report every + # commit as unsigned. Merge commits are skipped via --no-merges, + # matching the other commit checks below. + # + # An unresolvable API call is a hard failure here, unlike the AI + # attribution check, which lets a commit through when it cannot + # resolve an author. A false positive there accuses a person of + # being a bot; an unverifiable signature here only withholds a + # verdict that branch protection enforces at the merge button + # anyway, so failing closed costs a re-run, not a blocked person. + + FAILED=0 + UNSIGNED=0 + + # One call gets verification for up to 250 commits (the endpoint's + # documented cap); any sha it does not cover falls back to the + # per-commit call below. --paginate re-runs --jq per page, so this + # emits one JSON object per commit, which jq reads as a stream. + pr_commits=$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits" --paginate --jq '.[] | {sha: .sha, verification: .commit.verification}') || pr_commits='' + + for sha in $(git log --no-merges --format=%H "$BASE_SHA".."$HEAD_SHA"); do + subject=$(git show -s --format=%s "$sha") + + verification=$(echo "$pr_commits" | jq -c --arg sha "$sha" 'select(.sha == $sha) | .verification') + + if [ -z "$verification" ] && ! verification=$(gh api "repos/$REPO/commits/$sha" --jq '.commit.verification'); then + echo "::error::Could not check verification status for commit: $sha $subject (GitHub API call failed - this is not a signature failure, re-run the job)" + FAILED=1 + continue + fi + + verified=$(echo "$verification" | jq -r '.verified') + reason=$(echo "$verification" | jq -r '.reason') + + if [ "$verified" = "true" ]; then + echo "ok: $sha $subject" + else + echo "::error::Commit is not signed/verified: $sha $subject ($reason)" + UNSIGNED=1 + FAILED=1 + fi + done + + if [ "$UNSIGNED" -ne 0 ]; then + echo "" + echo " This repo requires every commit to be GPG or SSH signed and verified" + echo " by GitHub before a PR can merge - the commit(s) flagged above aren't." + echo "" + echo " Set up commit signing (GPG or SSH):" + echo " https://docs.github.com/en/authentication/managing-commit-signature-verification" + echo "" + echo " Then re-sign the commits this PR adds and force-push:" + echo " git rebase --exec 'git commit --amend --no-edit -S' origin/main" + echo " git push --force-with-lease" + fi + + exit $FAILED + + - name: Commits omit AI attribution trailers + if: ${{ !cancelled() }} + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GH_TOKEN: ${{ github.token }} + run: | + # CONTRIBUTING.md and AGENTS.md both state: + # + # "Do not include Co-Authored-By trailers for AI tools in commit + # messages. Attribution should be limited to human contributors." + # + # This does NOT try to recognise an AI by its name. Names are not a + # usable signal in either direction: Claude and Devin are ordinary + # human given names, so matching on them rejects real contributors, + # while any list of product names is stale the moment a new agent + # ships. + # + # Instead a co-author is rejected only on evidence that the identity + # is not a person: + # + # 1. Its GitHub privacy address resolves to an account of type Bot. + # GitHub is the authority here, and agents commit through GitHub + # Apps, so this keeps working for tools that do not exist yet. + # 2. Its address is a noreply@ mailbox on some other domain - a + # fabricated, uncontactable address. No person's git identity is + # noreply@. + # + # A false positive costs far more than a false negative here: a + # missed trailer is untidy attribution, but a blocked contributor is + # a person turned away by a linter. So anything this cannot resolve + # is allowed through, and a GitHub API failure never fails the build. + # + # Merge commits are skipped via --no-merges. + + # Bot accounts that may legitimately co-author. Keep this short. + ALLOWED_BOTS='dependabot[bot]' + + # Trailer keys and generator markers that are AI-only by construction. + # These are literal strings no person writes, not identity matching. + AI_ONLY_TRAILER='^(claude-session|codex-session|chatgpt-session):' + AI_MARKER='(Generated with \[Claude Code\]|🤖 Generated with)' + + CACHE=$(mktemp) + FAILED=0 + + # Prints "bot " if the address belongs to a bot account, + # "noreply" for a fabricated noreply mailbox, nothing otherwise. + classify() { + local email="$1" local_part login id cached type + local_part=${email%@*} + + case "$email" in + *@users.noreply.github.com) + case "$local_part" in + *+*) id=${local_part%%+*}; login=${local_part#*+} ;; + *) id=""; login=$local_part ;; + esac + + # A [bot] suffix is GitHub's own convention; no lookup needed. + case "$login" in + *'[bot]'*) printf 'bot %s' "$login"; return ;; + esac + + cached=$(grep -m1 "^${id}|${login} " "$CACHE" 2>/dev/null || true) + if [ -n "$cached" ]; then + type=${cached##* } + else + if [ -n "$id" ]; then + type=$(gh api "user/$id" --jq .type 2>/dev/null || echo "") + else + type=$(gh api "users/$login" --jq .type 2>/dev/null || echo "") + fi + # Unresolvable (deleted account, API trouble) is not evidence. + [ -z "$type" ] && type="Unknown" + printf '%s|%s %s\n' "$id" "$login" "$type" >> "$CACHE" + fi + + if [ "$type" = "Bot" ]; then + printf 'bot %s' "$login" + fi + ;; + *) + # noreply@example.com, but not GitHub's own privacy domain. + case "$local_part" in + noreply|no-reply) printf 'noreply' ;; + esac + ;; + esac + # Never let a "this is a person" verdict look like a failure: + # the step runs under set -e and this is called in a $( ). + return 0 + } + + for sha in $(git log --no-merges --format=%H "$BASE_SHA".."$HEAD_SHA"); do + subject=$(git show -s --format=%s "$sha") + offending="" + + while IFS= read -r line; do + lower=$(printf '%s' "$line" | tr '[:upper:]' '[:lower:]') + + case "$lower" in + co-authored-by:*) + email=$(printf '%s' "$lower" | sed -n 's/.*<\(.*\)>.*/\1/p') + [ -z "$email" ] && continue + + verdict=$(classify "$email") + case "$verdict" in + bot\ *) + login=${verdict#bot } + # -F because a login like dependabot[bot] is not a pattern. + if ! printf '%s\n' "$ALLOWED_BOTS" | grep -Fxq "$login"; then + offending="${offending}${line} <- ${login} is a bot account"$'\n' + fi + ;; + noreply) + offending="${offending}${line} <- noreply address, not a contactable person"$'\n' + ;; + esac + ;; + *) + offending="${offending}${line}"$'\n' + ;; + esac + done < <(git show -s --format=%B "$sha" | grep -iE "^co-authored-by:|$AI_ONLY_TRAILER|$AI_MARKER" || true) + + if [ -n "$offending" ]; then + echo "::error::Commit carries AI attribution: $sha $subject" + echo "" + echo " Commit: $sha" + echo " $subject" + echo "" + echo " Offending line(s):" + printf '%s' "$offending" | sed 's/^/ /' + echo "" + FAILED=1 + else + echo "ok: $sha $subject" + fi + done + + if [ "$FAILED" -ne 0 ]; then + echo "" + echo " CONTRIBUTING.md: \"Do not include Co-Authored-By trailers for AI tools in" + echo " commit messages. Attribution should be limited to human contributors.\"" + echo "" + echo " Co-authoring a person is fine and is never rejected: this only fires when" + echo " the address belongs to a bot account or is a noreply mailbox." + echo "" + echo " To fix a single commit:" + echo " git commit --amend # delete the trailer lines, save" + echo " git push --force-with-lease" + echo "" + echo " To fix several:" + echo " git rebase --root -x 'git commit --amend --no-edit'" + echo "" + echo " Configure your agent not to add them in the first place. For Claude Code," + echo " set includeCoAuthoredBy: false in .claude/settings.json." + fi + + exit $FAILED + + - name: Title and commits follow Conventional Commits + if: ${{ !cancelled() }} + env: + PR_TITLE: ${{ github.event.pull_request.title }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + # Conventional Commits pattern: + # [optional scope]: + # + # Types recognised by semantic-release (commit-analyzer defaults): + # feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci + # + # Breaking changes are signalled by appending ! before the colon: + # feat!: or feat(scope)!: + # + # References: + # https://www.conventionalcommits.org/en/v1.0.0/ + PATTERN: '^(feat|fix|perf|revert|docs|style|chore|refactor|test|build|ci)(\([-a-zA-Z0-9_.,]+\))?!?: .{1,}' + run: | + # The PR title is checked as well as the commits: the title becomes + # the squash-merge commit title on main, which is what + # semantic-release reads, so it must be conventional even when the + # commits on the branch are WIP history that gets squashed away. + # Merge commits are skipped via --no-merges. + + FAILED=0 + + usage() { + echo "" + echo " Got: $1" + echo "" + echo " Expected format: [optional scope]: " + echo " Examples:" + echo " feat(dynamodb): add PartiQL ExecuteStatement support" + echo " fix(s3): make us-east-1 bucket creation idempotent" + echo " chore: release 1.5.16" + echo " feat!: remove legacy endpoint" + echo "" + echo " Valid types: feat, fix, perf, revert, docs, style, chore, refactor, test, build, ci" + echo " See: https://www.conventionalcommits.org/en/v1.0.0/" + } + + if echo "$PR_TITLE" | grep -qE "$PATTERN"; then + echo "ok: PR title: $PR_TITLE" + else + echo "::error::PR title does not follow Conventional Commits: $PR_TITLE" + usage "$PR_TITLE" + FAILED=1 + fi + + while IFS= read -r msg; do + if echo "$msg" | grep -qE "$PATTERN"; then + echo "ok: $msg" + else + echo "::error::Commit does not follow Conventional Commits: $msg" + usage "$msg" + FAILED=1 + fi + done < <(git log --no-merges --format="%s" "$BASE_SHA".."$HEAD_SHA") + + exit $FAILED + + - name: New files omit em-dashes + if: ${{ !cancelled() }} + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + # AGENTS.md: "No em-dashes anywhere, in any content. Use colons, + # commas, or periods." + # + # Scoped to files this PR adds, not lines changed in existing ones: + # plenty of existing content already has em-dashes, and flagging + # every PR that happens to touch one of those files would make this + # check noise rather than signal. New files start clean. + + # Written as an escape, not the literal glyph: this workflow file is + # itself a new file the first time it is added, and the check below + # would otherwise flag itself for containing the character it is + # searching for. + EM_DASH=$'\u2014' + FAILED=0 + + # -z / -d '' throughout: plain --name-only C-quotes paths with + # non-ASCII or special characters (e.g. "caf\303\251.md"), which then + # fail to match the real file on disk and get silently skipped. + # NUL-delimited output/reads sidestep that. + while IFS= read -r -d '' file; do + [ -z "$file" ] && continue + + MATCHES=$(grep -InH "$EM_DASH" -- "$file" || true) + [ -z "$MATCHES" ] && continue + + FAILED=1 + while IFS=: read -r path lineno content; do + echo "::error file=$path,line=$lineno::Em-dash found in new file (AGENTS.md: no em-dashes anywhere, in any content)" + echo " $path:$lineno: $content" + done <<< "$MATCHES" + done < <(git diff -z --diff-filter=A --name-only "$BASE_SHA" "$HEAD_SHA") + + if [ "$FAILED" -eq 1 ]; then + echo "" + echo "Use colons, commas, or periods instead of em-dashes (U+2014). See AGENTS.md, Documentation Style." + fi + + exit $FAILED + + - name: PR body keeps the required template sections + # Bot PRs (dependabot) do not use the template. + if: ${{ !cancelled() && github.event.pull_request.user.type != 'Bot' }} + env: + PR_BODY: ${{ github.event.pull_request.body }} + run: | + # Guards against PRs that dropped the pull request template (or + # stripped a section) rather than filling it in. It only checks that + # the required section headers survive in the body: what a + # contributor wrote under each one is a human review call. + # + # AWS Compatibility is deliberately not required: plenty of PRs are + # not AWS-behaviour changes (chores, refactors, docs). + # + # Keep REQUIRED_HEADERS in sync with .github/pull_request_template.md. + REQUIRED_HEADERS=( + "## Summary" + "## Type of change" + "## Checklist" + ) + + # Single pass over lines, tracking fenced code blocks so a header + # string quoted or pasted inside one does not count. Leading + # indentation is restricted to 0-3 plain spaces (no tab): CommonMark + # treats a tab, or 4+ spaces, as an indented code block rather than + # an ATX heading, and so does this check. + declare -A FOUND + for header in "${REQUIRED_HEADERS[@]}"; do FOUND["$header"]=0; done + FENCE_RE='^[[:space:]]{0,3}(```|~~~)' + in_fence=0 + + while IFS= read -r line; do + if [[ "$line" =~ $FENCE_RE ]]; then + in_fence=$((1 - in_fence)) + continue + fi + [ "$in_fence" -eq 1 ] && continue + + for header in "${REQUIRED_HEADERS[@]}"; do + header_re="^[ ]{0,3}${header}[[:space:]]*\$" + [[ "$line" =~ $header_re ]] && FOUND["$header"]=1 + done + done <<< "$PR_BODY" + + MISSING=() + for header in "${REQUIRED_HEADERS[@]}"; do + [ "${FOUND[$header]}" -eq 0 ] && MISSING+=("$header") + done + + if [ "${#MISSING[@]}" -eq 0 ]; then + echo "ok: all required template sections present" + exit 0 + fi + + echo "::error::PR description is missing required template section(s):" + for header in "${MISSING[@]}"; do + echo "::error:: - $header" + done + echo "" + echo " It looks like the pull request template was edited or removed." + echo " Please restore the missing section(s) from .github/pull_request_template.md" + echo " and fill them in: you can edit the PR description directly on GitHub." + exit 1 diff --git a/.github/workflows/pr-template.yml b/.github/workflows/pr-template.yml deleted file mode 100644 index fee6084fee..0000000000 --- a/.github/workflows/pr-template.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: PR Template - -# Guards against PRs that dropped the pull request template entirely (or -# stripped out a section) rather than filling it in. This only checks that -# the required section headers survive in the PR body: it does not judge -# what a contributor wrote under each one, since that's a human review call, -# not something CI can score. -# -# AWS Compatibility is deliberately not required here: plenty of PRs are not -# AWS-behavior changes (chores, refactors, docs), so an empty/missing section -# there is not evidence of a dropped template. -# -# Keep REQUIRED_HEADERS in sync with .github/pull_request_template.md. -# -# No grandfathering: this applies to every open PR immediately, including -# ones opened before this rule existed, so they start failing on their next -# push/edit/reopen until the description is fixed up. - -on: - pull_request: - types: [opened, edited, synchronize, reopened] - -permissions: - contents: read - -jobs: - check-template: - name: PR body keeps the required template sections - runs-on: ubuntu-latest - if: github.event.pull_request.user.type != 'Bot' - - steps: - - name: Check required sections are present - env: - PR_BODY: ${{ github.event.pull_request.body }} - run: | - REQUIRED_HEADERS=( - "## Summary" - "## Type of change" - "## Checklist" - ) - - # Single pass over lines, tracking fenced code blocks so a header - # string quoted or pasted inside one doesn't count. Leading - # indentation is restricted to 0-3 plain spaces (no tab): CommonMark - # treats a tab, or 4+ spaces, as an indented code block rather than - # an ATX heading, and so does this check. - declare -A FOUND - for header in "${REQUIRED_HEADERS[@]}"; do FOUND["$header"]=0; done - FENCE_RE='^[[:space:]]{0,3}(```|~~~)' - in_fence=0 - - while IFS= read -r line; do - if [[ "$line" =~ $FENCE_RE ]]; then - in_fence=$((1 - in_fence)) - continue - fi - [ "$in_fence" -eq 1 ] && continue - - for header in "${REQUIRED_HEADERS[@]}"; do - header_re="^[ ]{0,3}${header}[[:space:]]*\$" - [[ "$line" =~ $header_re ]] && FOUND["$header"]=1 - done - done <<< "$PR_BODY" - - MISSING=() - for header in "${REQUIRED_HEADERS[@]}"; do - [ "${FOUND[$header]}" -eq 0 ] && MISSING+=("$header") - done - - if [ "${#MISSING[@]}" -eq 0 ]; then - echo "ok: all required template sections present" - exit 0 - fi - - echo "::error::PR description is missing required template section(s):" - for header in "${MISSING[@]}"; do - echo "::error:: - $header" - done - echo "" - echo " It looks like the pull request template was edited or removed." - echo " Please restore the missing section(s) from .github/pull_request_template.md" - echo " and fill them in: you can edit the PR description directly on GitHub." - exit 1 diff --git a/.github/workflows/signed-commits.yml b/.github/workflows/signed-commits.yml deleted file mode 100644 index 2a314da750..0000000000 --- a/.github/workflows/signed-commits.yml +++ /dev/null @@ -1,111 +0,0 @@ -name: Signed Commits - -# The repo's branch protection already requires every commit to be signed -# and verified before a PR can merge, but that only shows up as a generic -# red status on the merge button - it doesn't say which commit, or why. This -# job front-runs that with a per-commit annotation in the Checks tab, using -# the same signal GitHub's own merge gate uses (the commit's `verification` -# field from the API), so a contributor gets a specific, actionable failure -# instead of discovering the block only when they try to merge. -# -# 'edited' is deliberately left out of the trigger: editing the PR title or -# body doesn't change which commits are on the branch, so there's nothing -# new to check. - -on: - pull_request: - types: [opened, synchronize, reopened] - -permissions: - contents: read - pull-requests: read - -jobs: - check-signatures: - name: Commits are signed and verified - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - fetch-depth: 0 - - - name: Check commit signatures - env: - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - GH_TOKEN: ${{ github.token }} - REPO: ${{ github.repository }} - PR_NUMBER: ${{ github.event.pull_request.number }} - run: | - # Local `git log --show-signature` only verifies against keys the - # runner already trusts, which is nobody's - it would report every - # commit as unsigned regardless of reality. GitHub's own merge gate - # checks the commit's `verification` field instead (matched against - # the key the author uploaded to their GitHub account), so this - # checks the same field via the API to give the same verdict the - # merge button will, just earlier and per-commit. - # - # Merge commits are skipped via --no-merges, matching the - # Conventional Commits and AI Attribution jobs. - # - # An unresolvable API call is treated as a hard failure here, - # unlike ai-attribution.yml's classify(), which lets a commit - # through when it can't resolve an author ("Unresolvable (deleted - # account, API trouble) is not evidence"). The two jobs weigh the - # mistake differently: a false positive in AI Attribution accuses a - # human contributor of being a bot, while an unverifiable signature - # here only withholds a verdict that branch protection enforces at - # the merge button anyway - failing closed costs a re-run, not a - # wrongly blocked contributor. - - FAILED=0 - UNSIGNED=0 - - # One call gets verification for up to 250 commits (this - # endpoint's documented cap). The loop below still walks the same - # git-log range as before, so this is only a lookup cache: any sha - # it doesn't cover (over the cap, or absent for any other reason) - # falls back to the per-commit call that already handles API - # failures. --paginate re-runs --jq per page and concatenates the - # output, so this emits one JSON object per commit rather than a - # single array - jq reads that as a stream of values just fine. - pr_commits=$(gh api "repos/$REPO/pulls/$PR_NUMBER/commits" --paginate --jq '.[] | {sha: .sha, verification: .commit.verification}') || pr_commits='' - - for sha in $(git log --no-merges --format=%H "$BASE_SHA".."$HEAD_SHA"); do - subject=$(git show -s --format=%s "$sha") - - verification=$(echo "$pr_commits" | jq -c --arg sha "$sha" 'select(.sha == $sha) | .verification') - - if [ -z "$verification" ] && ! verification=$(gh api "repos/$REPO/commits/$sha" --jq '.commit.verification'); then - echo "::error::Could not check verification status for commit: $sha $subject (GitHub API call failed - this is not a signature failure, re-run the job)" - FAILED=1 - continue - fi - - verified=$(echo "$verification" | jq -r '.verified') - reason=$(echo "$verification" | jq -r '.reason') - - if [ "$verified" = "true" ]; then - echo "ok: $sha $subject" - else - echo "::error::Commit is not signed/verified: $sha $subject ($reason)" - UNSIGNED=1 - FAILED=1 - fi - done - - if [ "$UNSIGNED" -ne 0 ]; then - echo "" - echo " This repo requires every commit to be GPG or SSH signed and verified" - echo " by GitHub before a PR can merge - the commit(s) flagged above aren't." - echo "" - echo " Set up commit signing (GPG or SSH):" - echo " https://docs.github.com/en/authentication/managing-commit-signature-verification" - echo "" - echo " Then re-sign the commits this PR adds and force-push:" - echo " git rebase --exec 'git commit --amend --no-edit -S' origin/main" - echo " git push --force-with-lease" - fi - - exit $FAILED diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1dc9da919..1b32de1729 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -126,7 +126,7 @@ wip: still working on this # "wip" is not a recognised type Do not include `Co-Authored-By` trailers for AI tools in commit messages. Attribution should be limited to human contributors. -CI enforces this: the **Commits omit AI attribution trailers** check fails a pull request whose commits carry a `Co-Authored-By` for an identity that is not a person (one whose GitHub address belongs to a bot account, or that uses a `noreply@` mailbox), along with the session and generator lines such tools add on their own. It never judges a co-author by name, so co-authoring a person is always fine; that trailer is how GitHub credits reviewers on a squash merge. `dependabot[bot]` is allowlisted. If the check fires, drop the offending lines with `git commit --amend` (or a rebase for several commits) and force-push. +CI enforces this: the **Commits omit AI attribution trailers** step of the **PR hygiene** check fails a pull request whose commits carry a `Co-Authored-By` for an identity that is not a person (one whose GitHub address belongs to a bot account, or that uses a `noreply@` mailbox), along with the session and generator lines such tools add on their own. It never judges a co-author by name, so co-authoring a person is always fine; that trailer is how GitHub credits reviewers on a squash merge. `dependabot[bot]` is allowlisted. If the check fires, drop the offending lines with `git commit --amend` (or a rebase for several commits) and force-push. ## Architecture