-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix: stop doubling the changelog header newlines #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+125
−5
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f5656e7
fix: stop doubling the changelog header newlines
michen00 f624b03
fix(test-cliff-header.sh): guard mktemp failure
michen00 ee335df
fix(test-cliff-header.sh): match MD012 blank rule
michen00 998e5f8
docs(cliff.toml): scope the header newline rule
michen00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #!/usr/bin/env bash | ||
| # Test script for the [changelog] header template in cliff.toml | ||
|
|
||
| set -uo pipefail | ||
| TEST_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
|
|
||
| # Load shared configurations | ||
| # shellcheck disable=SC1091 # Dynamic path via $TEST_SCRIPT_DIR | ||
| . "$TEST_SCRIPT_DIR/colors.sh" | ||
|
|
||
| CLIFF_TOML="$TEST_SCRIPT_DIR/../cliff.toml" | ||
|
|
||
| PASSED=0 | ||
| FAILED=0 | ||
|
michen00 marked this conversation as resolved.
|
||
|
|
||
| pass() { | ||
| echo -e "${GREEN}✓${NC} $1" | ||
| ((PASSED++)) | ||
| } | ||
|
|
||
| fail() { | ||
| echo -e "${RED}✗${NC} $1" | ||
| shift | ||
| for msg in "$@"; do | ||
| echo -e " ${YELLOW}$msg${NC}" | ||
| done | ||
| ((FAILED++)) | ||
| } | ||
|
|
||
| # Render the header template the way TOML does, so the assertions below run | ||
| # against the text git-cliff actually writes. git-cliff is not installed on | ||
| # every machine that runs this suite (and not in CI at all), and the header is | ||
| # static text with no Tera expressions, so decoding it here is both sufficient | ||
| # and portable. | ||
| # | ||
| # TOML multi-line basic strings drop the newline right after the opening | ||
| # delimiter; every other source line contributes its text plus one newline, and | ||
| # a trailing \n escape contributes another newline on top of that. That second | ||
| # newline is easy to add by accident and invisible in the source, which is what | ||
| # MD012 below is guarding against. | ||
| render_header() { | ||
| awk ' | ||
| /^header = """$/ { in_block = 1; next } | ||
| in_block && /^"""$/ { exit } | ||
| in_block { | ||
|
michen00 marked this conversation as resolved.
|
||
| line = $0 | ||
| extra = 0 | ||
| while (sub(/\\n$/, "", line)) extra++ | ||
| if (line ~ /\\/) { | ||
| print "unsupported escape in header template: " $0 > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| print line | ||
| for (i = 0; i < extra; i++) print "" | ||
| } | ||
| ' "$1" | ||
| } | ||
|
|
||
| if ! work="$(mktemp -d)"; then | ||
| echo "Error: could not create a temporary directory" >&2 | ||
| exit 1 | ||
| fi | ||
| trap 'rm -rf "$work"' EXIT INT TERM HUP | ||
| rendered="$work/header.md" | ||
|
|
||
| if ! render_header "$CLIFF_TOML" >"$rendered"; then | ||
| fail "header template renders" "render_header could not decode the template" | ||
| elif [ ! -s "$rendered" ]; then | ||
| fail "header template renders" "Rendered header is empty; is the 'header = \"\"\"' block still there?" | ||
| else | ||
| pass "header template renders" | ||
|
|
||
| # MD012/no-multiple-blanks. markdownlint runs over the generated changelog | ||
| # in the changelog-autoupdate workflow, and a header that trips this rule | ||
| # fails that job every week without ever touching a commit. | ||
| # | ||
| # markdownlint counts a whitespace-only line as blank, so this check and | ||
| # the trailing-blank count below have to as well; testing for an empty | ||
| # line alone would pass a header that markdownlint still rejects. | ||
| offenders="$(awk 'BEGIN { run = 0 } { if ($0 ~ /^[[:space:]]*$/) { run++; if (run > 1) print NR } else run = 0 }' "$rendered")" | ||
| if [ -n "$offenders" ]; then | ||
| # shellcheck disable=SC2086 # Word splitting turns the line list into args | ||
| fail "header has no consecutive blank lines (MD012)" \ | ||
| "Extra blank lines at rendered line(s): $(echo $offenders | tr ' ' ',')" \ | ||
| "Rendered header:" \ | ||
| "$(cat -v "$rendered")" | ||
| else | ||
| pass "header has no consecutive blank lines (MD012)" | ||
| fi | ||
|
|
||
| # The header has to end with exactly one blank line so the first '## [' | ||
| # section that follows it is separated by one blank line, not glued on. | ||
| trailing_blanks="$(awk '{ if ($0 ~ /^[[:space:]]*$/) blanks++; else blanks = 0 } END { print blanks + 0 }' "$rendered")" | ||
| if [ "$trailing_blanks" -ne 1 ]; then | ||
| fail "header ends with a single blank line" \ | ||
| "Header ends with $trailing_blanks trailing blank line(s), expected 1" | ||
| else | ||
| pass "header ends with a single blank line" | ||
| fi | ||
| fi | ||
|
|
||
| echo "" | ||
| echo -e "Results: ${GREEN}$PASSED passed${NC}, ${RED}$FAILED failed${NC}" | ||
| [ "$FAILED" -eq 0 ] | ||
|
michen00 marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.