|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -euo pipefail |
| 4 | + |
| 5 | +repository_root="$(git rev-parse --show-toplevel)" |
| 6 | +validator="${repository_root}/.github/scripts/validate-release-changelogs.sh" |
| 7 | +temporary_root="$(mktemp -d)" |
| 8 | +fixture="${temporary_root}/repository" |
| 9 | +output="${temporary_root}/output" |
| 10 | + |
| 11 | +trap 'rm -rf "$temporary_root"' EXIT |
| 12 | + |
| 13 | +mkdir -p "$fixture" "$output" |
| 14 | +git -C "$fixture" init --quiet |
| 15 | +git -C "$fixture" config user.email release-validator@example.com |
| 16 | +git -C "$fixture" config user.name "Release Validator" |
| 17 | + |
| 18 | +write_file() { |
| 19 | + local path="$1" |
| 20 | + local content="$2" |
| 21 | + |
| 22 | + mkdir -p "$(dirname "${fixture}/${path}")" |
| 23 | + printf '%s\n' "$content" > "${fixture}/${path}" |
| 24 | +} |
| 25 | + |
| 26 | +commit_fixture() { |
| 27 | + local message="$1" |
| 28 | + |
| 29 | + git -C "$fixture" add --all |
| 30 | + git -C "$fixture" commit --quiet --message "$message" |
| 31 | +} |
| 32 | + |
| 33 | +expect_failure() { |
| 34 | + if (cd "$fixture" && "$validator" HEAD^ HEAD >/dev/null 2>&1); then |
| 35 | + echo "expected validation to fail: $1" >&2 |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +write_file zebrad/Cargo.toml '[package] |
| 41 | +name = "zebrad" |
| 42 | +version = "1.0.0"' |
| 43 | +write_file zebra-example/Cargo.toml '[package] |
| 44 | +name = "zebra-example" |
| 45 | +version = "2.0.0"' |
| 46 | +write_file CHANGELOG.md '# Changelog |
| 47 | +
|
| 48 | +## [Zebra 1.0.0] |
| 49 | +
|
| 50 | +- Initial release.' |
| 51 | +write_file zebra-example/CHANGELOG.md '# Changelog |
| 52 | +
|
| 53 | +## [2.0.0] |
| 54 | +
|
| 55 | +- Initial release.' |
| 56 | +commit_fixture base |
| 57 | + |
| 58 | +write_file zebrad/Cargo.toml '[package] |
| 59 | +name = "zebrad" |
| 60 | +version = "1.1.0"' |
| 61 | +write_file zebra-example/Cargo.toml '[package] |
| 62 | +name = "zebra-example" |
| 63 | +version = "2.0.1"' |
| 64 | +write_file CHANGELOG.md '# Changelog |
| 65 | +
|
| 66 | +## [Zebra 1.1.0](https://example.com/v1.1.0) - 2026-07-22 |
| 67 | +
|
| 68 | +### Fixed |
| 69 | +
|
| 70 | +- Fixed release behavior. |
| 71 | +
|
| 72 | +## [Zebra 1.0.0] |
| 73 | +
|
| 74 | +- Initial release.' |
| 75 | +write_file zebra-example/CHANGELOG.md '# Changelog |
| 76 | +
|
| 77 | +## [2.0.1] - 2026-07-22 |
| 78 | +
|
| 79 | +- Updated the dependency. |
| 80 | +
|
| 81 | +## [2.0.0] |
| 82 | +
|
| 83 | +- Initial release.' |
| 84 | +commit_fixture valid-release |
| 85 | + |
| 86 | +( |
| 87 | + cd "$fixture" |
| 88 | + "$validator" HEAD^ HEAD "${output}/notes.md" "${output}/expected.tsv" |
| 89 | +) |
| 90 | +grep -q '^## \[Zebra 1\.1\.0\]' "${output}/notes.md" |
| 91 | +diff -u <(printf 'zebra-example\t2.0.1\nzebrad\t1.1.0\n') "${output}/expected.tsv" |
| 92 | + |
| 93 | +write_file zebrad/Cargo.toml '[package] |
| 94 | +name = "zebrad" |
| 95 | +version = "1.1.1"' |
| 96 | +write_file CHANGELOG.md '# Changelog |
| 97 | +
|
| 98 | +## [Zebra 1.1.1] |
| 99 | +
|
| 100 | +## [Zebra 1.1.0] |
| 101 | +
|
| 102 | +- Previous release.' |
| 103 | +commit_fixture heading-only |
| 104 | +expect_failure "heading-only section" |
| 105 | + |
| 106 | +write_file zebrad/Cargo.toml '[package] |
| 107 | +name = "zebrad" |
| 108 | +version = "1.1.2"' |
| 109 | +write_file CHANGELOG.md '# Changelog |
| 110 | +
|
| 111 | +## [Zebra 1.1.20] |
| 112 | +
|
| 113 | +- Near-match heading. |
| 114 | +
|
| 115 | +## [Zebra 1.1.0] |
| 116 | +
|
| 117 | +- Previous release.' |
| 118 | +commit_fixture near-match |
| 119 | +expect_failure "near-match heading" |
| 120 | + |
| 121 | +write_file zebra-example/Cargo.toml '[package] |
| 122 | +name = "zebra-example" |
| 123 | +version = "2.0.2"' |
| 124 | +write_file zebra-example/CHANGELOG.md '# Changelog |
| 125 | +
|
| 126 | +## [2.0.2] |
| 127 | +
|
| 128 | +- Updated another dependency. |
| 129 | +
|
| 130 | +## [2.0.1] |
| 131 | +
|
| 132 | +- Previous release.' |
| 133 | +commit_fixture library-only |
| 134 | + |
| 135 | +( |
| 136 | + cd "$fixture" |
| 137 | + "$validator" HEAD^ HEAD "${output}/notes.md" "${output}/expected.tsv" |
| 138 | +) |
| 139 | +test ! -e "${output}/notes.md" |
| 140 | +diff -u <(printf 'zebra-example\t2.0.2\n') "${output}/expected.tsv" |
| 141 | + |
| 142 | +write_file zebra-example/Cargo.toml '[package] |
| 143 | +name = "zebra-example" |
| 144 | +version = "2.0.3"' |
| 145 | +commit_fixture missing-library-heading |
| 146 | +expect_failure "missing library heading" |
| 147 | + |
| 148 | +write_file zebrad/Cargo.toml '[package] |
| 149 | +name = "zebrad" |
| 150 | +version = "1.1.2" |
| 151 | +description = "Metadata-only change"' |
| 152 | +commit_fixture metadata-only |
| 153 | +expect_failure "Release PR without a version change" |
| 154 | + |
| 155 | +write_file zebra-example/Cargo.toml '[package] |
| 156 | +name = "zebra-example" |
| 157 | +version = "2.0.4"' |
| 158 | +git -C "$fixture" rm --quiet zebra-example/CHANGELOG.md |
| 159 | +commit_fixture missing-changelog |
| 160 | +expect_failure "missing changelog" |
| 161 | + |
| 162 | +echo "release changelog validator tests passed" |
0 commit comments