mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 09:47:56 -05:00
ci: run the per-PR hygiene checks in one job and skip drafts without a gate job (#4703)
* ci: run the per-PR hygiene checks in one job The signed commits, AI attribution, Conventional Commits, em-dash and PR template checks were five workflows with one job each, so every push to a pull request started five runners for about ten seconds of work apiece. 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. They now run as steps of a single "PR hygiene" job. Each step keeps the old check's name, script and annotations, and runs under !cancelled() so one failure does not hide the others. The signature check also runs on "edited" now: with one job, an edit-triggered run replaces the whole result, and skipping signatures there would turn an unsigned PR green. A per-PR concurrency group cancels superseded runs. The path-filtered checks (docs tables, partition literals, changelog guard) keep their own workflows. * ci: skip draft PRs with a job condition instead of a gate job CI and Compatibility Tests reached the draft rule through a reusable workflow that started its own job on every run. That job did about three seconds of work, but every other job in the run needed it, so under the account's concurrent-job limit its queue wait sat at the head of the critical path: on recent PR runs a median of about 35 seconds, and nine to thirteen minutes at the tail, before a shard or native build could even be queued. The same condition now sits on the root jobs as a job-level if:, which GitHub evaluates without a runner. Drafts, closed PRs and edited events still skip the suites and pushes to main still run; the native suites follow build-native. CI summary keeps always() so a failed shard still reaches the partition check and report, and uses the same condition so it does not run on a draft. pr-draft-gate.yml has no callers left and is removed.
This commit is contained in:
1 parent
99c1c4129a
commit
8ff1eae121
10 files changed
+503
-586
No files matched your search
@@ -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 <login>" 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
|
||||
+21
-10
@@ -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'
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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:
|
||||
# <type>[optional scope]: <description>
|
||||
#
|
||||
# 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: <type>[optional scope]: <description>"
|
||||
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: <type>[optional scope]: <description>"
|
||||
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
|
||||
@@ -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
|
||||
@@ -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."
|
||||
@@ -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 <login>" 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:
|
||||
# <type>[optional scope]: <description>
|
||||
#
|
||||
# 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: <type>[optional scope]: <description>"
|
||||
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
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user