diff --git a/.github/scripts/assemble-release-notes.sh b/.github/scripts/assemble-release-notes.sh new file mode 100755 index 0000000..9d67f43 --- /dev/null +++ b/.github/scripts/assemble-release-notes.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -euo pipefail + +image_tag_list="${1}" + +# TODO: Include tag annotation? +# TODO: include some form of changelog? + +echo -e "### Published images\n" +for tag in $(grep -ve ':latest$' "${image_tag_list}"); do + echo " - [${tag}](https://hub.docker.com/r/${tag%%:*})" +done diff --git a/.github/scripts/update-github-release.sh b/.github/scripts/update-github-release.sh deleted file mode 100755 index 7e74aa5..0000000 --- a/.github/scripts/update-github-release.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -source "$(dirname "${0}")/_shared_functions.sh" - -set -eu - -release_id="${1}" -# shellcheck disable=SC2153 # false positive -image_tag_list="${IMAGE_TAG_LIST}" - -# Get current values -curl -siX GET "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}" \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -o "${CURL_OUT}" -process_curl_response || exit 1 - -release_name="$(print_curl_response_json | jq '."name"' )" -release_body="$(print_curl_response_json | jq '."body" // ""' )" - -# Remove version prefix from title -new_name="${release_name//@(pre-|release-)/}" - -# Add list with new images to body -function list_entry { - image_tag=${1} - - echo " - [${image_tag}](https://hub.docker.com/r/${image_tag%%:*})\r\n" -} -export -f list_entry - -# TODO: Include tag annotation? -# TODO: include some form of changelog? - -# shellcheck disable=SC2016 # false positive -new_body="$(tr -d '\n' << BODY -${release_body%\"} \\r\\n \\r\\n - -### Published images \\r\\n \\r\\n -$(grep -ve ':latest$' "${image_tag_list}" | xargs -n 1 -I {} bash -c 'list_entry "${@}"' _ {})" - -BODY -)" - -# Update release -curl -siX PATCH "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/${release_id}" \ - -H "Authorization: token ${GITHUB_TOKEN}" \ - -o "${CURL_OUT}" \ - -d @- \ -<< PAYLOAD -{ - "name": ${new_name}, - "body": ${new_body}, - "draft": false -} - -PAYLOAD -process_curl_response || exit 1 diff --git a/.github/workflows/test-and-publish.yml b/.github/workflows/test-and-publish.yml index 67008dc..31f0f1c 100644 --- a/.github/workflows/test-and-publish.yml +++ b/.github/workflows/test-and-publish.yml @@ -82,20 +82,32 @@ jobs: docker push "${tag}" done <"${IMAGE_TAG_LIST}" docker logout + - name: Determine version + id: release-version + run: | + tag="${{ github.ref }}" + version="${tag##*/*-}" + is_prerelease=false + title="Release ${version}" + if [[ "${tag}" == *"/pre-"* ]]; then + is_prerelease=true + title="Pre-${title}" + fi + + echo "version=${version}" >> $GITHUB_OUTPUT + echo "is_prerelease=${is_prerelease}" >> $GITHUB_OUTPUT + echo "title=${title}" >> $GITHUB_OUTPUT + - name: Assemble release notes + id: release-notes + run: | + .github/scripts/assemble-release-notes.sh \ + "${IMAGE_TAG_LIST}" \ + > release-notes.md - name: Create Github release id: create-gh-release - uses: actions/create-release@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: softprops/action-gh-release@v2 with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - draft: true - prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-') }} - # TODO: Compute release info before creating the release; communicate by step output - - name: Update Github release info - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - .github/scripts/update-github-release.sh \ - "${{ steps.create-gh-release.outputs.id }}" + name: ${{ steps.release-version.outputs.title }} + body_path: release-notes.md + # TODO: mark as draft if created manually + prerelease: ${{ steps.release-version.outputs.is_prerelease }}