Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/attribution-guard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Attribution Guard

on:
pull_request:
types: [opened, reopened, synchronize, edited, labeled, unlabeled, ready_for_review]
push:
branches: [main]

permissions:
contents: read
pull-requests: read

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
attribution-guard:
name: Attribution Guard
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout trusted helper from base commit
if: github.event_name == 'pull_request'
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.base.sha }}
path: trusted
persist-credentials: false

- name: Locate helper
id: helper
if: github.event_name == 'pull_request'
run: |
if [[ -f trusted/scripts/attribution_guard.py ]]; then
echo "path=trusted/scripts/attribution_guard.py" >> "$GITHUB_OUTPUT"
else
echo "::notice::Base commit has no guard helper; bootstrapping from the pull request head."
echo "path=bootstrap/scripts/attribution_guard.py" >> "$GITHUB_OUTPUT"
echo "bootstrap=true" >> "$GITHUB_OUTPUT"
fi

- name: Checkout pull request helper (bootstrap only)
if: github.event_name == 'pull_request' && steps.helper.outputs.bootstrap == 'true'
uses: actions/checkout@v7
with:
ref: ${{ github.event.pull_request.head.sha }}
path: bootstrap
persist-credentials: false

- name: Checkout pushed history
if: github.event_name == 'push'
uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: "3.12"

- name: Check pull request metadata
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ github.token }}
HELPER: ${{ steps.helper.outputs.path }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: python "$HELPER" pull-request --repo "$GITHUB_REPOSITORY" --number "$PR_NUMBER"

- name: Audit pushed commits
if: github.event_name == 'push'
env:
BEFORE_SHA: ${{ github.event.before }}
AFTER_SHA: ${{ github.sha }}
run: python scripts/attribution_guard.py push --before "$BEFORE_SHA" --after "$AFTER_SHA"
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
default_install_hook_types: [commit-msg]

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.22.0
Expand Down Expand Up @@ -51,6 +53,18 @@ repos:
language: system
pass_filenames: false
stages: [pre-push]
- id: attribution-guard-commit-msg
name: attribution-guard (commit message)
entry: python scripts/attribution_guard.py commit-msg
language: python
stages: [commit-msg]
- id: attribution-guard-pre-push
name: attribution-guard (pushed refs and commits)
entry: python scripts/attribution_guard.py pre-push
language: python
pass_filenames: false
always_run: true
stages: [pre-push]
- id: pyright
name: pyright
entry: uv run --frozen --extra dev pyright --pythonversion 3.12 ser tests
Expand Down
19 changes: 18 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,29 @@ Install or refresh git hooks manually:
./scripts/install_git_hooks.sh
```

The generated `.git/hooks/pre-push` runs `bash ./scripts/run_prepush_gate.sh`, which:
The generated `.git/hooks/pre-push` first runs the attribution guard on the pushed refs (see below), then runs `bash ./scripts/run_prepush_gate.sh`, which:
- runs `make prepush` to attempt formatter/linter auto-fixes first
- reruns the canonical pre-push verification lane
- aborts the push if non-fixable issues remain
- aborts the push if the hook changed the working tree, so you can review, stage, and commit the fixes first

The installer also runs `pre-commit install --hook-type commit-msg` (the only type in `default_install_hook_types`; the pre-push hook stays owned by the installer).

## Attribution Guard
`scripts/attribution_guard.py` rejects AI-tool attribution in branch and tag names, commit messages,
author/committer emails, pull request titles and bodies, and labels. Naming a provider or dependency
as the subject of a change stays allowed; only attribution (co-author trailers, "generated with"
footers, session links, tool-namespaced refs) is rejected. Its pattern block is vendored
byte-for-byte from the shared source and pinned by a digest test; re-vendor it, never edit it.

- `commit-msg` stage: checks the message being committed.
- `pre-push`: checks every pushed ref name and each commit it introduces. Under
`pre-commit run --hook-stage pre-push` it checks the current branch and its unpushed commits.
- CI: `.github/workflows/attribution-guard.yml` publishes the `Attribution Guard` check. It
refetches pull request metadata from the API on every PR event (including edits and label
changes) and audits each push to `main`. It is a separate required status check on the `main`
ruleset, alongside `required-ci`, so metadata-only events re-evaluate it without new commits.

## Boundary Commands (When Required)
Run the boundary lane whenever your change touches `ser/api.py`, `ser/_internal/api/*`, `ser/__main__.py`, or boundary contract tests:

Expand Down
Loading
Loading