mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
Enforce human authorship with automatic trailer scrubbing (#1325)
Install commit and push hooks that remove bot co-author trailers, preserve human credits, and reject bot primary authors. Add a trusted default-branch CI checker and publish its required status on the exact proposed commit. Validate main pushes as well. Ten regression tests pass, including real Git hook tests and the --no-verify case.
This commit is contained in:
1 parent
7bb1b5b74b
commit
4421e851dd
6 files changed
+321
-9
No files matched your search
@@ -0,0 +1,58 @@
|
||||
name: Human authorship
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [opened, synchronize, reopened, edited, ready_for_review]
|
||||
push:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
statuses: write
|
||||
|
||||
jobs:
|
||||
authorship:
|
||||
name: Validate human authorship
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 5
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.repository.default_branch }}
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
- name: Check the proposed or merged history
|
||||
id: validate
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
BEFORE: ${{ github.event.before }}
|
||||
AFTER: ${{ github.sha }}
|
||||
PR_HEAD: ${{ github.event.pull_request.head.sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "$EVENT_NAME" = pull_request_target ]; then
|
||||
gh auth setup-git
|
||||
git fetch --no-tags origin "refs/pull/$PR_NUMBER/head"
|
||||
test "$(git rev-parse FETCH_HEAD)" = "$PR_HEAD"
|
||||
base=$(git merge-base HEAD FETCH_HEAD)
|
||||
python3 tools/release/check_authorship.py "$base..FETCH_HEAD" --event "$GITHUB_EVENT_PATH"
|
||||
elif [ "$EVENT_NAME" = push ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ]; then
|
||||
python3 tools/release/check_authorship.py "$BEFORE..$AFTER"
|
||||
else
|
||||
python3 tools/release/check_authorship.py HEAD
|
||||
fi
|
||||
- name: Publish the required result on the actual proposed commit
|
||||
if: always()
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
TARGET_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
|
||||
RESULT: ${{ steps.validate.outcome == 'success' && 'success' || 'failure' }}
|
||||
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
||||
run: |
|
||||
gh api --method POST "repos/$GITHUB_REPOSITORY/statuses/$TARGET_SHA" \
|
||||
-f context='Human authorship' -f state="$RESULT" -f target_url="$RUN_URL" \
|
||||
-f description='Bot authors and bot co-author trailers are forbidden'
|
||||
@@ -100,17 +100,22 @@ jobs:
|
||||
fetch-depth: 0
|
||||
persist-credentials: false
|
||||
|
||||
- name: Check co-authors
|
||||
if: github.event_name == 'pull_request'
|
||||
- name: Check human authorship
|
||||
env:
|
||||
EVENT_NAME: ${{ github.event_name }}
|
||||
BEFORE: ${{ github.event.before }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git fetch --no-tags origin main
|
||||
base=$(git merge-base origin/main HEAD)
|
||||
messages=$(git log --format=%B "$base..HEAD")
|
||||
messages+=$'\n'"$(jq -r '.pull_request.title, (.pull_request.body // "")' "$GITHUB_EVENT_PATH")"
|
||||
if grep -Eiq '^[[:space:]]*Co-authored-by:.*(Claude|Anthropic|OpenAI|ChatGPT|GPT|Copilot|Cursor|Gemini|Codex|Devin|Windsurf|Codeium|Amazon Q|Tabnine|Cody|\[bot\])' <<<"$messages"; then
|
||||
echo "::error::AI and bot identities cannot be co-authors; remove the Co-authored-by trailer."
|
||||
exit 1
|
||||
if [ "$EVENT_NAME" = pull_request ]; then
|
||||
git fetch --no-tags origin main
|
||||
base=$(git merge-base origin/main HEAD)
|
||||
checker="$RUNNER_TEMP/droiddeck-check-authorship.py"
|
||||
git show origin/main:tools/release/check_authorship.py > "$checker"
|
||||
python3 "$checker" "$base..HEAD" --event "$GITHUB_EVENT_PATH"
|
||||
elif [ "$EVENT_NAME" = push ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ]; then
|
||||
python3 tools/release/check_authorship.py "$BEFORE..HEAD"
|
||||
else
|
||||
python3 tools/release/check_authorship.py HEAD
|
||||
fi
|
||||
|
||||
- name: The packages a signed build ships as
|
||||
|
||||
Reference in new issue
Block a user