| 1 | #!/usr/bin/env bash |
| 2 | # Require issue-linked feature commits in a release range to leave a durable |
| 3 | # changelog receipt. This catches shipped user-visible features that otherwise |
| 4 | # disappear when the GitHub Release body is generated from CHANGELOG.md. |
| 5 | set -euo pipefail |
| 6 | |
| 7 | base_ref="${1:?usage: $0 <base-ref> <head-ref> [notes-file ...]}" |
| 8 | head_ref="${2:?usage: $0 <base-ref> <head-ref> [notes-file ...]}" |
| 9 | shift 2 |
| 10 | |
| 11 | repo_root="${RELEASE_NOTE_REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}" |
| 12 | cd "${repo_root}" |
| 13 | |
| 14 | if [[ "$#" -gt 0 ]]; then |
| 15 | notes_files=("$@") |
| 16 | else |
| 17 | notes_files=(CHANGELOG.md docs/CHANGELOG_ARCHIVE.md) |
| 18 | fi |
| 19 | |
| 20 | for ref in "${base_ref}" "${head_ref}"; do |
| 21 | if ! git rev-parse --verify --quiet "${ref}^{commit}" >/dev/null; then |
| 22 | echo "error: release-note check cannot resolve ${ref}" >&2 |
| 23 | exit 2 |
| 24 | fi |
| 25 | done |
| 26 | for notes_file in "${notes_files[@]}"; do |
| 27 | if [[ ! -f "${notes_file}" ]]; then |
| 28 | echo "error: release-note check cannot read ${notes_file}" >&2 |
| 29 | exit 2 |
| 30 | fi |
| 31 | done |
| 32 | |
| 33 | fail=0 |
| 34 | checked=0 |
| 35 | feature_subject_pattern='^feat(\([^)]*\))?!?:[[:space:]]' |
| 36 | while IFS= read -r -d '' sha && |
| 37 | IFS= read -r -d '' subject && |
| 38 | IFS= read -r -d '' body; do |
| 39 | [[ "${subject}" =~ ${feature_subject_pattern} ]] || continue |
| 40 | |
| 41 | feature_text="${subject}"$'\n'"${body}" |
| 42 | while IFS= read -r issue; do |
| 43 | [[ -n "${issue}" ]] || continue |
| 44 | case "${issue}" in |
| 45 | 000 | 1 | 24 | 26 | 1834 | 142352) continue ;; |
| 46 | esac |
| 47 | checked=$((checked + 1)) |
| 48 | found=0 |
| 49 | for notes_file in "${notes_files[@]}"; do |
| 50 | if grep -Eq "#${issue}([^[:alnum:]_]|$)" "${notes_file}"; then |
| 51 | found=1 |
| 52 | break |
| 53 | fi |
| 54 | done |
| 55 | if [[ "${found}" -eq 0 ]]; then |
| 56 | echo "::error::Feature commit ${sha:0:12} references #${issue}, but no release-note receipt exists in ${notes_files[*]}." >&2 |
| 57 | echo " ${subject}" >&2 |
| 58 | fail=1 |
| 59 | fi |
| 60 | done < <( |
| 61 | printf '%s\n' "${feature_text}" \ |
| 62 | | grep -oE '#[0-9]+([^[:alnum:]_]|$)' \ |
| 63 | | sed -E 's/^#([0-9]+).*/\1/' \ |
| 64 | | sort -u \ |
| 65 | || true |
| 66 | ) |
| 67 | done < <(git log -z --no-merges --format='%H%x00%s%x00%b' "${base_ref}..${head_ref}") |
| 68 | |
| 69 | if [[ "${fail}" -ne 0 ]]; then |
| 70 | echo "Add the missing user-visible feature to the appropriate changelog section before release." >&2 |
| 71 | exit 1 |
| 72 | fi |
| 73 | |
| 74 | echo "Feature release-note receipts OK: ${checked} linked issue reference(s) checked in ${base_ref}..${head_ref}." |
| 75 |