name: pr-title
on:
pull_request_target:
types: [opened, edited, reopened, synchronize]
permissions: {}
jobs:
pr-title:
name: pr-title
runs-on: ubuntu-latest
steps:
- name: the title is a RK_SCOPEDConventional Commit
env:
TITLE: ${{ github.event.pull_request.title }}
BODY: ${{ github.event.pull_request.body }}
run: |
#RK_IF_RELEASE_ A request that names a security advisory releases: its title takes
#RK_IF_RELEASE_ feat, fix, or perf, or marks a breaking change, and a security update
#RK_IF_RELEASE_ is fix(deps). The release bot's own request is exempt.
RK_IF_RELEASE_printf '%s\n%s\n' "$TITLE" "${BODY:-}" | grep -Eq '(^|[^A-Za-z0-9])(RUSTSEC-[0-9]{4}-[0-9]{4}|CVE-[0-9]{4}-[0-9]{4,}|GHSA(-[0-9a-z]{4}){3})' && advisory=yes
RK_IF_RELEASE_printf '%s' "$TITLE" | grep -Eq '^((feat|fix|perf)(\([^)]*\)){0,1}!{0,1}|[a-z]+(\([^)]*\)){0,1}!): |^chore(\((release|master|main)\))?: (release|v)' && advisory=
RK_IF_RELEASE_printf '%s\n' "${BODY:-}" | grep -Eq '^BREAKING[ -]CHANGE:' && advisory=
RK_IF_RELEASE_test -z "${advisory:-}" || { echo "the request names a security advisory, so its title takes a releasing type: feat, fix, or perf, or a breaking change; a security update is fix(deps)"; exit 1; }
printf '%s' "$TITLE" | grep -Eq \
'^((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)RK_SCOPE_OPEN\((RK_SCOPE_SHAPE)\)RK_SCOPE_CLOSE!?: .+|chore(\((release|master|main)\))?: (release|v).+)$' \
&& exit 0
RK_IF_RELEASE_echo "the title '$TITLE' must read type(scope) then a colon and a description, with the scope lowercase letters, digits, and _ . / -"
RK_IF_NO_RELEASE_echo "the title '$TITLE' must read type or type(scope) then a colon and a description, with any scope lowercase letters, digits, and _ . / -"
exit 1
- name: the body carries no attribution and no internal path
env:
TITLE: ${{ github.event.pull_request.title }}
BODY: ${{ github.event.pull_request.body }}
run: |
printf '%s' "$TITLE" | grep -Eq \
'^chore(\((release|master|main)\))?: (release|v).+$' \
&& exit 0
fail=0
while IFS='|' read -r class pattern; do
if printf '%s' "$BODY" | grep -Eq "$pattern"; then
echo "the body carries a $class finding: a line matches $pattern"
fail=1
fi
done <<'GUARDS'
attribution|[Gg]enerated with \[?Claude
attribution|🤖 Generated with
attribution|[Cc]o-[Aa]uthored-[Bb]y:.*([Cc]laude|[Cc]opilot|Codex|ChatGPT)
attribution|noreply@anthropic\.com
internal-path|(^|[^A-Za-z0-9])\.draft/
GUARDS
exit "$fail"