| 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail |
| 3 | |
| 4 | repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 5 | tmp_dir="$(mktemp -d)" |
| 6 | trap 'rm -rf "${tmp_dir}"' EXIT |
| 7 | |
| 8 | cat >"${tmp_dir}/CHANGELOG.md" <<'EOF' |
| 9 | ## [Unreleased] |
| 10 | |
| 11 | ## [1.2.3] - 2026-07-14 |
| 12 | |
| 13 | Release summary and highlights. |
| 14 | |
| 15 | ### Upgrade notes |
| 16 | |
| 17 | - Run the required migration once. |
| 18 | |
| 19 | ### Fixed |
| 20 | |
| 21 | - A release fix. |
| 22 | |
| 23 | ### Contributors |
| 24 | |
| 25 | - [@example](https://github.com/example) — report and implementation. |
| 26 | |
| 27 | ## [1.2.2] - 2026-07-01 |
| 28 | EOF |
| 29 | |
| 30 | body="$("${repo_root}/scripts/release/generate-release-body.sh" v1.2.3 "${tmp_dir}/CHANGELOG.md")" |
| 31 | |
| 32 | [[ "${body%%$'\n'*}" == "## What's in v1.2.3" ]] |
| 33 | [[ "${body%%## Install*}" == *"Release summary and highlights."* ]] |
| 34 | [[ "${body%%Release summary and highlights.*}" == *$'### Upgrade notes\n\n- Run the required migration once.'* ]] |
| 35 | [[ "$(grep -c -- '- Run the required migration once.' <<<"${body}")" == 1 ]] |
| 36 | grep -Fq -- '<summary>Full release notes</summary>' <<<"${body}" |
| 37 | grep -Fq -- "- A release fix." <<<"${body}" |
| 38 | grep -Fq -- "## Contributors" <<<"${body}" |
| 39 | grep -Fq -- "[@example](https://github.com/example)" <<<"${body}" |
| 40 | grep -Fq -- 'codewhale-home:/home/codewhale/.codewhale' <<<"${body}" |
| 41 | grep -Fq -- 'codewhale-android-arm64.tar.gz' <<<"${body}" |
| 42 | grep -Fq -- 'codewhale-windows-arm64.zip' <<<"${body}" |
| 43 | grep -Fq -- 'codewhale.bat' <<<"${body}" |
| 44 | grep -Fq -- 'The image exposes the same runtime as both `codewhale` and `codew`.' <<<"${body}" |
| 45 | grep -Fq -- '### Recommended — official GitHub release' <<<"${body}" |
| 46 | grep -Fq -- 'curl -fsSL https://codewhale.net/install.sh | CODEWHALE_VERSION="v1.2.3" sh' <<<"${body}" |
| 47 | grep -Fq -- '### Secondary packaging — npm and Cargo' <<<"${body}" |
| 48 | grep -Fq -- 'byte-identical compatibility copies' <<<"${body}" |
| 49 | grep -Fq -- 'sha256sum -c codewhale-bundles-sha256.txt --ignore-missing' <<<"${body}" |
| 50 | grep -Fq -- 'sha256sum -c codewhale-artifacts-sha256.txt --ignore-missing' <<<"${body}" |
| 51 | grep -Fq -- 'shasum -a 256 -c codewhale-bundles-sha256.txt --ignore-missing' <<<"${body}" |
| 52 | grep -Fq -- 'shasum -a 256 -c codewhale-artifacts-sha256.txt --ignore-missing' <<<"${body}" |
| 53 | |
| 54 | checksum_dir="${tmp_dir}/checksums" |
| 55 | mkdir -p "${checksum_dir}" |
| 56 | printf 'downloaded platform\n' >"${checksum_dir}/codewhale-linux-x64.tar.gz" |
| 57 | present_hash="$(sha256sum "${checksum_dir}/codewhale-linux-x64.tar.gz" | awk '{print $1}')" |
| 58 | { |
| 59 | printf '%s %s\n' "${present_hash}" "codewhale-linux-x64.tar.gz" |
| 60 | printf '%064d %s\n' 0 "codewhale-windows-x64.zip" |
| 61 | } >"${checksum_dir}/codewhale-bundles-sha256.txt" |
| 62 | ( |
| 63 | cd "${checksum_dir}" |
| 64 | sha256sum -c codewhale-bundles-sha256.txt --ignore-missing >/dev/null |
| 65 | ) |
| 66 | if grep -Fq -- "### Contributors" <<<"${body}"; then |
| 67 | echo "nested contributor heading leaked into generated release body" >&2 |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | awk 'BEGIN { |
| 72 | print "## [Unreleased]\n" |
| 73 | print "## [2.0.0] - 2026-11-18\n" |
| 74 | for (i = 0; i < 2200; i++) printf "Summary paragraph with spaces and CJK text. " |
| 75 | print "\n\n### Fixed\n" |
| 76 | for (i = 0; i < 1200; i++) printf "- Detailed release fix bullet with context. " |
| 77 | print "\n\n### Contributors\n\n- [@large](https://github.com/large) — stress fixture.\n" |
| 78 | print "## [1.9.9] - 2026-11-01" |
| 79 | }' >"${tmp_dir}/LARGE_CHANGELOG.md" |
| 80 | |
| 81 | awk 'BEGIN { |
| 82 | print "## [2.0.1] - 2026-11-18\n" |
| 83 | for (i = 0; i < 3600; i++) printf "- Unclassified release line with spaces. " |
| 84 | print "\n\n### Contributors\n\n- [@flat](https://github.com/flat) — fixture." |
| 85 | }' >"${tmp_dir}/FLAT_LARGE_CHANGELOG.md" |
| 86 | |
| 87 | shells=("${BASH}") |
| 88 | if [[ -x /bin/bash && "${BASH}" != "/bin/bash" ]]; then |
| 89 | shells+=("/bin/bash") |
| 90 | fi |
| 91 | |
| 92 | for shell_bin in "${shells[@]}"; do |
| 93 | SECONDS=0 |
| 94 | large_body="$("${shell_bin}" "${repo_root}/scripts/release/generate-release-body.sh" v2.0.0 "${tmp_dir}/LARGE_CHANGELOG.md")" |
| 95 | (( SECONDS < 5 )) |
| 96 | grep -Fq -- "Summary paragraph with spaces" <<<"${large_body}" |
| 97 | grep -Fq -- "The full notes exceed GitHub's release-description limit." <<<"${large_body}" |
| 98 | grep -Fq -- "[@large](https://github.com/large)" <<<"${large_body}" |
| 99 | (( ${#large_body} < 125000 )) |
| 100 | |
| 101 | SECONDS=0 |
| 102 | flat_body="$("${shell_bin}" "${repo_root}/scripts/release/generate-release-body.sh" v2.0.1 "${tmp_dir}/FLAT_LARGE_CHANGELOG.md")" |
| 103 | (( SECONDS < 5 )) |
| 104 | grep -Fq -- "The full notes exceed GitHub's release-description limit." <<<"${flat_body}" |
| 105 | grep -Fq -- "[@flat](https://github.com/flat)" <<<"${flat_body}" |
| 106 | (( ${#flat_body} < 125000 )) |
| 107 | done |
| 108 | |
| 109 | echo "generate-release-body tests passed" |
| 110 |