FFFF ci: put the SPM semver tag on the swift-releases manifest commit by adityamukho · Pull Request #3 · project-minigraf/minigraf-swift · GitHub
[go: up one dir, main page]

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
67 changes: 40 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ jobs:
with:
ref: ${{ needs.prepare.outputs.sha }}

# The source commit gets a non-semver `source-vX` tag. The semver `vX` tag is
# what Swift Package Manager resolves, so it goes on the swift-releases commit
# that carries the real xcframework URL, checksum and generated Swift sources
# (build-and-publish below). A semver tag on the source commit resolves to a
# manifest with a placeholder checksum and no Swift sources.
tag:
name: Push tag and update main
name: Push source tag and update main
needs: [prepare, test]
runs-on: ubuntu-latest
steps:
Expand All @@ -92,9 +97,9 @@ jobs:
ref: ${{ needs.prepare.outputs.sha }}
token: ${{ secrets.MINIGRAF_RELEASE_TOKEN }}

- name: Push tag, fast-forward main, delete release branch
- name: Push source tag, fast-forward main, delete release branch
env:
TAG: ${{ needs.prepare.outputs.tag }}
TAG: source-${{ needs.prepare.outputs.tag }}
SHA: ${{ needs.prepare.outputs.sha }}
run: |
EXISTING=$(git ls-remote origin "refs/tags/$TAG" | cut -f1)
Expand All @@ -110,8 +115,8 @@ jobs:
# Atomic: main and the tag move together or not at all. Rejected if
# main moved during the release; re-run to re-pin on the new main.
git push --atomic origin "${REFS[@]}"
git push origin --delete "release/$TAG" \
|| echo "::warning::Could not delete branch release/$TAG"
git push origin --delete "release/${{ needs.prepare.outputs.tag }}" \
|| echo "::warning::Could not delete branch release/${{ needs.prepare.outputs.tag }}"

build-and-publish:
name: Build xcframework and publish
Expand All @@ -120,7 +125,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.tag }}
ref: source-${{ needs.prepare.outputs.tag }}
token: ${{ secrets.MINIGRAF_RELEASE_TOKEN }}
fetch-depth: 0

Expand Down Expand Up @@ -169,18 +174,6 @@ jobs:
-output "MinigrafKit.xcframework"
zip -r "MinigrafKit-${TAG}.xcframework.zip" MinigrafKit.xcframework

- name: Create GitHub Release and upload xcframework
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ needs.prepare.outputs.tag }}"
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "MinigrafKit $TAG" \
--notes "Swift/iOS binding for minigraf $TAG."
gh release upload "$TAG" "MinigrafKit-${TAG}.xcframework.zip" \
--repo "$GITHUB_REPOSITORY"

- name: Compute checksum and update Package.swift
run: |
TAG="${{ needs.prepare.outputs.tag }}"
Expand Down Expand Up @@ -221,13 +214,33 @@ jobs:
git push origin swift-releases --force

NEW_SHA=$(git rev-parse HEAD)
SWIFT_TAG="swift-${TAG}"
gh api "repos/${GITHUB_REPOSITORY}/git/refs" \
-X POST \
-f ref="refs/tags/${SWIFT_TAG}" \
-f sha="$NEW_SHA" 2>/dev/null \
|| gh api "repos/${GITHUB_REPOSITORY}/git/refs/tags/${SWIFT_TAG}" \
-X PATCH \
-f sha="$NEW_SHA" \
-F force=true
echo "SWIFT_SHA=$NEW_SHA" >> "$GITHUB_ENV"

# SPM resolves semver tags only, so the semver tag must point at the
# swift-releases commit whose Package.swift has the real URL and checksum.
- name: Tag the swift-releases commit with the semver tag
env:
TAG: ${{ needs.prepare.outputs.tag }}
run: |
EXISTING=$(git ls-remote origin "refs/tags/$TAG" | cut -f1)
if [ -z "$EXISTING" ]; then
git push origin "$SWIFT_SHA:refs/tags/$TAG"
elif [ "$EXISTING" = "$SWIFT_SHA" ]; then
echo "Tag $TAG already points at $SWIFT_SHA"
else
echo "::error::Tag $TAG already exists at $EXISTING, not at the swift-releases commit $SWIFT_SHA. Check which commit SPM users resolve before moving it."
exit 1
fi

- name: Create GitHub Release and upload xcframework
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.prepare.outputs.tag }}
run: |
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--verify-tag \
--title "MinigrafKit $TAG" \
--notes "Swift/iOS binding for minigraf $TAG."
gh release upload "$TAG" "MinigrafKit-${TAG}.xcframework.zip" \
--repo "$GITHUB_REPOSITORY"
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,26 @@ Or add to `Package.swift`:

```swift
dependencies: [
.package(url: "https://github.com/project-minigraf/minigraf-swift", from: "1.2.0")
.package(url: "https://github.com/project-minigraf/minigraf-swift", from: "2.0.1")
]
```

> SPM resolves via the `swift-v<version>` tag which points to the `swift-releases` branch
> containing the updated `Package.swift` and generated Swift sources.
> Each semver tag `v<version>` points to a commit on the `swift-releases` branch. That commit
> holds the `Package.swift` with the release's xcframework URL and checksum, plus the generated
> Swift sources. The matching source commit on `main` is tagged `source-v<version>`.
> Releases up to v2.0.1 were tagged differently; see
> [Older releases](#older-releases) below.

### Older releases

Before the tagging fix, the release workflow put the semver tag on the source commit, whose
`Package.swift` has a placeholder checksum and no generated sources. Those tags do not resolve.
For those versions, the working manifest is on the `swift-v<version>` tag instead, which SPM
cannot resolve by version. Pin the `swift-releases` branch or a specific revision instead:

```swift
.package(url: "https://github.com/project-minigraf/minigraf-swift", branch: "swift-releases")
```

Requires iOS 16+.

Expand Down Expand Up @@ -51,7 +65,8 @@ cargo run --bin uniffi-bindgen -- generate \
This repo receives a `core-release` repository_dispatch from the minigraf monorepo
cascade whenever a new version of the `minigraf` core crate is published. The release
workflow pins the new version, builds the xcframework for iOS device and simulator,
zips it, creates a GitHub Release, and updates `Package.swift` on the `swift-releases` branch.
zips it, updates `Package.swift` on the `swift-releases` branch, tags that commit with the
semver tag SPM resolves, and creates a GitHub Release with the xcframework.

## License

Expand Down
Loading
0