Skip to content

Commit 8467e35

Browse files
authored
Merge pull request #4957 from IntersectMBO/ldan/changelog-bumper
Add script for bumping CHANGELOGS post-release
2 parents 3a986b4 + ab4d442 commit 8467e35

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

RELEASING.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,19 @@ More on that command in the section below.
238238
```
239239

240240
4. Create a PR to `master` that updates `CHANGELOG.md` files for all of the packages that
241-
have just been released. The only addition to the file should be a markdown header
242-
section with the next patch version bumped, which must bring the `CHANGELOG.md` to the
243-
state of the top level section containing a version higher than the highest one ever
244-
released. Due to concurrent nature of editing the repository it is possible that
241+
have just been released. When done manually, the only addition to the file should be a markdown header
242+
section with the next patch version bumped but prefer to use the provided convenience script `./scripts/bump-changelogs.sh`
243+
to do this automatically. This will fetch a shallow copy of [CHaP](https://github.com/intersectmbo/cardano-haskell-packages)
244+
and check if any of our most recent package versions had a release. If so, the script
245+
will bump the corresponding `CHANGELOG`s with the next patch version, which brings
246+
the state of the top level section containing a version higher than the highest one ever released.
247+
Due to concurrent nature of editing the repository it is possible that
245248
`CHANGELOG.md` have already received a version bump with a section that fits the
246-
higher version criteria, in which case nothing needs to be added. The body of the
247-
section, if added, must be empty with just one single asterisk `*`.
249+
higher version criteria, in which case nothing will be nor should be added. The body of the
250+
section, when added, should be empty with just one single asterisk `*`.
248251

249252
For example, if `cardano-ledger-core-1.20.1.1` was just released, then a new empty
250-
`1.20.1.2` section in the `CHANGELOG.md` must be added:
253+
`1.20.1.2` section in the `CHANGELOG.md` will be added by the script:
251254

252255
```markdown
253256
# Version history for `cardano-ledger-core`

scripts/bump-changelogs.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
CHAP=./cardano-haskell-packages
4+
# Download a shallow copy of CHaP
5+
git clone --depth 1 [email protected]:IntersectMBO/cardano-haskell-packages.git $CHAP
6+
7+
cd $CHAP || exit
8+
# Save all the available packages from CHaP
9+
CHAP_PACKAGES=$(./scripts/list-packages.sh)
10+
cd - || exit
11+
echo "The following packages are available in CHaP:"
12+
echo "$CHAP_PACKAGES"
13+
14+
# Save the paths to every `cardano-ledger` cabal file
15+
CABAL_FILES=$(find . -wholename '*/eras/*.cabal' -o -wholename '*/libs/*.cabal')
16+
17+
for i in $CABAL_FILES;
18+
do
19+
# Extract the name of the package (without the path and the extension)
20+
PACKAGE=$(basename "$i" .cabal)
21+
# Construct the path to the package's `CHANGELOG`
22+
CHANGELOG=${i/$PACKAGE.cabal/CHANGELOG.md}
23+
24+
# Check if package has a `CHANGELOG`
25+
if [[ -f "$CHANGELOG" ]]; then
26+
# Get the most recent version number in the `CHANGELOG`
27+
VERSION=$(grep -m 1 -o "[0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+" "$CHANGELOG")
28+
29+
# Check if the package had a release with
30+
# the most recent `CHANGELOG` version number
31+
printf "Looking for %s with version %s in CHaP\n" "$PACKAGE" "$VERSION"
32+
RESULT=$(echo "$CHAP_PACKAGES" | grep -o "$PACKAGE $VERSION")
33+
if [[ -n "$RESULT" ]]; then
34+
# A release was found and thus the `CHANGELOG` has to be bumped
35+
# with the incremented patch version
36+
NEXT_VERSION=$(echo "$VERSION" | awk -F. -v OFS=. '{$NF += 1 ; print}')
37+
printf "Bumping %s to %s\n" "$CHANGELOG" "$NEXT_VERSION"
38+
sed -i "s/## $VERSION/## $NEXT_VERSION\n\n*\n\n## $VERSION/" "$CHANGELOG"
39+
fi
40+
fi
41+
done
42+
43+
rm -rf $CHAP
44+
printf "\n!!!!!!\n%s %s\n!!!!!!\n" \
45+
"WARNING! DO NOT BUMP THE VERSION NUMBER IN THE CABAL FILES" \
46+
"(unless its dependencies were bumped)!"

0 commit comments

Comments
 (0)