diff --git a/.github/workflows/release-upload.yaml b/.github/workflows/release-upload.yaml index 6ac81ad7c3..f4a2a4a7a7 100644 --- a/.github/workflows/release-upload.yaml +++ b/.github/workflows/release-upload.yaml @@ -160,6 +160,7 @@ jobs: name: "Create Release" runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 # We need the repo to execute extract-changelog.sh below - uses: actions/download-artifact@v4 with: name: cardano-cli-linux # Should match (2) @@ -179,15 +180,28 @@ jobs: # TODO generalize # tar -czf ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-macos.tar.gz cardano-cli-macos # zip ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-win64.zip cardano-cli-win64 + - name: Create short tag + run: | + # Transform the long tag (e.g. "cardano-cli-8.22.0.0") + # into the short version (e.g. "8.22.0.0") + long_tag=${{ needs.wait_for_hydra.outputs.TARGET_TAG }} + short_tag="${long_tag#cardano-cli-}" + echo "SHORT_TAG=$short_tag" >> "$GITHUB_ENV" + - name: Create changelog + run: | + echo -e "# Changelog\n" > RELEASE_CHANGELOG.md + ./scripts/ci/extract-changelog.sh ${{ env.SHORT_TAG }} >> RELEASE_CHANGELOG.md - name: Create Release uses: input-output-hk/action-gh-release@v1 if: ${{ needs.wait_for_hydra.outputs.DRY_RUN == 'false' }} with: draft: true - tag_name: ${{ needs.wait_for_hydra.outputs.TARGET_TAG }} + tag_name: ${{ needs.wait_for_hydra.outputs.TARGET_TAG }} # Git tag the release is attached to + name: ${{ env.SHORT_TAG }} # Release name in GitHub UI # TODO generalize # cardano-cli-${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-macos.tar.gz # cardano-cli-${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-win64.zip # All entries in 'files' below should match (3) files: | ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-linux.tar.gz + body_path: RELEASE_CHANGELOG.md diff --git a/scripts/ci/extract-changelog.sh b/scripts/ci/extract-changelog.sh new file mode 100755 index 0000000000..288af0401c --- /dev/null +++ b/scripts/ci/extract-changelog.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# Extracts the changelog of a specific version, by reading cardano-cli/CHANGELOG.md +# +# This script expects the version as first argument, for example "8.22.0.0" + +set -o pipefail # We want commands with pipes to fail if any command in the stream fails + +[[ -n "$1" ]] || { echo "This script expects a release version number as first and unique parameter. Please provide one (for example \"8.22.0\")"; exit 1; } + +declare -r CHANGELOG="cardano-cli/CHANGELOG.md" + +HEADER_LINE=$(grep -n "^## $1" "$CHANGELOG" | awk -F : '{print $1}') + +# shellcheck disable=SC2181 +[[ "$?" == "0" ]] || { echo "Release header not found (grep for \"^## $1\" failed)"; exit 1; } + +CHANGELOG_START_LINE=$((HEADER_LINE + 2)) + +# Uncomment to debug +# echo "Found changelog starting line: $CHANGELOG_START_LINE" + +AFTER_CHANGELOG_LINE=$((CHANGELOG_START_LINE + 1)) +NUMBER_OF_LINES=$(tail -n "+$AFTER_CHANGELOG_LINE" $CHANGELOG | grep -n '^##' | head -n 1 | awk -F : '{print $1}') + +# shellcheck disable=SC2181 +[[ "$?" == "0" ]] || { echo "Next release header not found (grep for \"^## $1\" failed), starting at line $AFTER_CHANGELOG_LINE"; exit 1; } + +NUMBER_OF_LINES=$((NUMBER_OF_LINES - 1)) + +# Uncomment to debug +# echo "Found number of lines: $NUMBER_OF_LINES" + +# Piping tail doesn't play nice with "set -o pipefail" so turning it off +# See https://superuser.com/questions/554855/how-can-i-fix-a-broken-pipe-error +set +o pipefail + +tail -n "+$CHANGELOG_START_LINE" "$CHANGELOG" | head -n "$NUMBER_OF_LINES"