Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 2 additions & 42 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<NOTES

## Binary

Use the prebuilt \`Compute.xcframework\` from a Swift package:

\`\`\`swift
.binaryTarget(
name: "Compute",
url: "$url",
checksum: "$checksum"
)
\`\`\`

Built by the [Release workflow]($RUN_URL) from tag \`$TAG\` at commit \`$GITHUB_SHA\`.
NOTES

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 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\`."
64 changes: 64 additions & 0 deletions Scripts/create-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash
#
# Create (or update) the GitHub release for a tag and attach the XCFramework.
# Usage: ./Scripts/create-release.sh <tag> [<additional release notes>]
#
# 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 <tag> [<additional release notes>]" >&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

## Binary

Use the prebuilt \`Compute.xcframework\` from a Swift package:

\`\`\`swift
.binaryTarget(
name: "Compute",
url: "$url",
checksum: "$checksum"
)
\`\`\`
NOTES

if [[ -n "$additional_notes" ]]; then
printf '\n%s\n' "$additional_notes" >> "$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
Loading