From afae1e4fc062374060e79c6896ac55516a244bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Tue, 23 Apr 2024 10:59:13 +0200 Subject: [PATCH 1/3] CI: use short tag as release identifier --- .github/workflows/release-upload.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-upload.yaml b/.github/workflows/release-upload.yaml index 6ac81ad7c3..18a57ff80e 100644 --- a/.github/workflows/release-upload.yaml +++ b/.github/workflows/release-upload.yaml @@ -179,12 +179,20 @@ 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 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 From f44c63166c0c3e7088a4ff8f28497b16dceb9348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Mon, 22 Apr 2024 14:40:13 +0200 Subject: [PATCH 2/3] Add script to extract changelog --- scripts/ci/extract-changelog.sh | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 scripts/ci/extract-changelog.sh diff --git a/scripts/ci/extract-changelog.sh b/scripts/ci/extract-changelog.sh new file mode 100755 index 0000000000..6912e123ed --- /dev/null +++ b/scripts/ci/extract-changelog.sh @@ -0,0 +1,34 @@ +#!/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" + +tail -n "+$CHANGELOG_START_LINE" "$CHANGELOG" | head -n "$NUMBER_OF_LINES" From c2a72b0588b3d077e25cb70f635a044a7c0e0c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Hurlin?= Date: Mon, 22 Apr 2024 18:09:28 +0200 Subject: [PATCH 3/3] CI: create release changelog automatically --- .github/workflows/release-upload.yaml | 6 ++++++ scripts/ci/extract-changelog.sh | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/.github/workflows/release-upload.yaml b/.github/workflows/release-upload.yaml index 18a57ff80e..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) @@ -186,6 +187,10 @@ jobs: 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' }} @@ -199,3 +204,4 @@ jobs: # 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 index 6912e123ed..288af0401c 100755 --- a/scripts/ci/extract-changelog.sh +++ b/scripts/ci/extract-changelog.sh @@ -31,4 +31,8 @@ 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"