|
| 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 |
0 commit comments