diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e21de987..4f1dcc03 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,47 +31,7 @@ jobs: env: GH_TOKEN: ${{ github.token }} TAG: ${{ github.ref_name }} - REPOSITORY: ${{ github.repository }} RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} run: | - set -euo pipefail - zip_path=".build/Xcode/Frameworks/Compute.xcframework.zip" - checksum="$(swift package compute-checksum "$zip_path")" - url="https://github.com/$REPOSITORY/releases/download/$TAG/Compute.xcframework.zip" - - # Start with the release notes that GitHub generates from the changes since the previous release. - gh api "repos/$REPOSITORY/releases/generate-notes" \ - -f tag_name="$TAG" \ - --jq .body > release-notes.md - cat >> release-notes.md < /dev/null 2>&1; then - gh release upload "$TAG" "$zip_path" --clobber - gh release edit "$TAG" --notes-file release-notes.md - else - gh release create "$TAG" "$zip_path" \ - --verify-tag \ - --title "Version $TAG" \ - --notes-file release-notes.md \ - ${prerelease[@]+"${prerelease[@]}"} - fi + ./Scripts/create-release.sh "$TAG" \ + "Created by the [Release workflow]($RUN_URL) from tag \`$TAG\` at commit \`$GITHUB_SHA\`." diff --git a/Scripts/create-release.sh b/Scripts/create-release.sh new file mode 100755 index 00000000..018e9c43 --- /dev/null +++ b/Scripts/create-release.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# Create (or update) the GitHub release for a tag and attach the XCFramework. +# Usage: ./Scripts/create-release.sh [] +# +# Expects Scripts/create-xcframework.sh to have been run first. The gh CLI must +# be authenticated, and picks the repository from the current checkout (or GH_REPO). + +set -euo pipefail + +if [[ $# -lt 1 || $# -gt 2 ]]; then + echo "Usage: $0 []" >&2 + exit 1 +fi + +TAG="$1" +additional_notes="${2:-}" +REPOSITORY="$(gh repo view --json nameWithOwner --jq .nameWithOwner)" + +zip_path=".build/Xcode/Frameworks/Compute.xcframework.zip" +checksum="$(swift package compute-checksum "$zip_path")" +url="https://github.com/$REPOSITORY/releases/download/$TAG/Compute.xcframework.zip" + +notes_path="$(mktemp)" +trap 'rm -f "$notes_path"' EXIT + +# Start with the release notes that GitHub generates from the changes since the previous release. +gh api "repos/$REPOSITORY/releases/generate-notes" \ + -f tag_name="$TAG" \ + --jq .body > "$notes_path" +cat >> "$notes_path" <> "$notes_path" +fi + +prerelease=() +if [[ "$TAG" == *-* ]]; then + prerelease=(--prerelease) +fi + +if gh release view "$TAG" > /dev/null 2>&1; then + gh release upload "$TAG" "$zip_path" --clobber + gh release edit "$TAG" --notes-file "$notes_path" +else + gh release create "$TAG" "$zip_path" \ + --verify-tag \ + --title "Version $TAG" \ + --notes-file "$notes_path" \ + ${prerelease[@]+"${prerelease[@]}"} +fi