Skip to content

Commit fd1be74

Browse files
authored
Add changelog test in CI (#7)
1 parent ee7c91a commit fd1be74

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

.github/workflows/cli.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
rustup component add clippy rustfmt
3434
- name: Checkout repo
3535
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
36+
with:
37+
# This is needed to test that CHANGELOG.md is up-to-date.
38+
fetch-depth: 0
3639
# TODO(https://github.com/actions/cache/issues/1539): Just use actions/cache instead of the
3740
# work-around. The only relevant steps in-between are the cargo install commands.
3841
# BEGIN work-around

cli/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
## 0.0.0
1616

1717
No content.
18+
19+
<!-- Increment to skip CHANGELOG.md test: 0 -->

cli/ci.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
set -e
1717
. ./color.sh
1818

19-
info "Checking CHANGELOG.md version"
19+
info "Checking if CHANGELOG.md is up-to-date"
2020
x="$(sed -n '3s/^## //p' CHANGELOG.md)"
2121
y="$(sed -n '3s/^version = "\(.*\)"/\1/p' Cargo.toml)"
2222
[ -n "$x" ] || error "Missing version in CHANGELOG.md"
2323
[ -n "$y" ] || error "Missing version in Cargo.toml"
24-
[ "$x" = "$y" ] || error "Version mismatch between Cargo.toml and CHANGELOG.md"
24+
[ "$x" = "$y" ] || error "CHANGELOG.md version differs from Cargo.toml"
25+
ref=$(git log -n1 --pretty=format:%H origin/main.. -- CHANGELOG.md)
26+
git diff --quiet ${ref:-origin/main} -- Cargo.* src || error "CHANGELOG.md is not up-to-date"
2527

2628
info "Running unit tests"
2729
./test.sh

cli/release.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ info "Removing all -git suffixes"
2525
sed -i 's/-git//' Cargo.* CHANGELOG.md
2626
VERSION="${VERSION%-git}"
2727

28+
info "Reset CHANGELOG.md counter"
29+
sed -i 's/\(^<!-- .* test\): [0-9]* -->$/\1: 0 -->/' CHANGELOG.md
30+
2831
info "Updating README.md"
2932
sed -i 's#\(releases/tag/cli/v\).*$#\1'"$VERSION"'#' README.md
3033

0 commit comments

Comments
 (0)