Skip to content

Commit

Permalink
Merge pull request #733 from IntersectMBO/smelc/release-create-changelog
Browse files Browse the repository at this point in the history
            CI: create release changelog automatically
  • Loading branch information
smelc authored Apr 24, 2024
2 parents 1cd6e14 + c2a72b0 commit 5056246
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
16 changes: 15 additions & 1 deletion .github/workflows/release-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
38 changes: 38 additions & 0 deletions scripts/ci/extract-changelog.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 5056246

Please sign in to comment.