|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +subject="${1:-}" |
| 5 | +base_ref="${2:-origin/main}" |
| 6 | +head_ref="${3:-HEAD}" |
| 7 | +head_branch="${4:-}" |
| 8 | + |
| 9 | +if [[ -z "${subject}" ]]; then |
| 10 | + echo "expected a non-empty PR title or commit subject" >&2 |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
| 14 | +release_pattern='^((feat|fix|perf|refactor|revert)(\([a-z0-9][a-z0-9._/-]*\))?(!)?|[a-z]+(\([a-z0-9][a-z0-9._/-]*\))?!): .+' |
| 15 | +release_pr_pattern='^chore\(release\): .+' |
| 16 | + |
| 17 | +affected_files=() |
| 18 | + |
| 19 | +while IFS= read -r file; do |
| 20 | + [[ -z "${file}" ]] && continue |
| 21 | + |
| 22 | + case "${file}" in |
| 23 | + Cargo.toml | Cargo.lock | build.rs | src/* | assets/* | examples/* | benches/*) |
| 24 | + affected_files+=("${file}") |
| 25 | + ;; |
| 26 | + esac |
| 27 | +done < <(git diff --name-only "${base_ref}...${head_ref}" --) |
| 28 | + |
| 29 | +if (( ${#affected_files[@]} == 0 )); then |
| 30 | + exit 0 |
| 31 | +fi |
| 32 | + |
| 33 | +if [[ "${subject}" =~ ${release_pattern} ]]; then |
| 34 | + exit 0 |
| 35 | +fi |
| 36 | + |
| 37 | +if [[ "${subject}" =~ ${release_pr_pattern} && "${head_branch}" == release-plz-* ]]; then |
| 38 | + exit 0 |
| 39 | +fi |
| 40 | + |
| 41 | +cat >&2 <<EOF |
| 42 | +This PR changes release-affecting package files, but its title does not carry |
| 43 | +release intent for release-plz. |
| 44 | +
|
| 45 | +Use one of these Conventional Commit types in the PR title: |
| 46 | + feat, fix, perf, refactor, revert |
| 47 | +
|
| 48 | +Breaking changes may use any type with !, for example: |
| 49 | + chore!: remove a deprecated API |
| 50 | +
|
| 51 | +release-plz PRs are exempt only when their branch starts with release-plz- and |
| 52 | +their title starts with chore(release):. |
| 53 | +
|
| 54 | +Docs, CI, issue-template, and repository-only changes can keep non-release types |
| 55 | +such as docs:, ci:, chore:, style:, or test: when they do not touch package code. |
| 56 | +
|
| 57 | +Received: |
| 58 | + ${subject} |
| 59 | +
|
| 60 | +Release-affecting files: |
| 61 | +EOF |
| 62 | + |
| 63 | +printf ' %s\n' "${affected_files[@]}" >&2 |
| 64 | +exit 1 |
0 commit comments