Skip to content

Commit 1cc93d8

Browse files
committed
ci(swift): add Swift release workflow
1 parent 910d492 commit 1cc93d8

2 files changed

Lines changed: 138 additions & 0 deletions

File tree

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Release Swift Package
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: Release tag (vX.Y.Z or X.Y.Z)
8+
required: true
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
release-swift:
15+
runs-on: macos-latest
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Normalize tag
24+
id: tag
25+
run: |
26+
TAG="${{ inputs.tag }}"
27+
if [[ "${TAG}" != v* ]]; then
28+
TAG="v${TAG}"
29+
fi
30+
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
31+
32+
- name: Check for existing tag or release
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
run: |
36+
TAG="${{ steps.tag.outputs.tag }}"
37+
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}$"; then
38+
echo "Tag already exists on origin: ${TAG}"
39+
exit 1
40+
fi
41+
if gh release view "${TAG}" >/dev/null 2>&1; then
42+
echo "Release already exists: ${TAG}"
43+
exit 1
44+
fi
45+
46+
- name: Configure git
47+
run: |
48+
git config user.name "github-actions[bot]"
49+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
50+
51+
- name: Build xcframework
52+
run: bash cktap-swift/build-xcframework.sh
53+
54+
- name: Create archive and update checksum
55+
run: bash scripts/swift_create_xcframework_archive.sh
56+
57+
- name: Update Package.swift tag
58+
run: python3 scripts/swift_update_package_checksum.py --tag "${{ steps.tag.outputs.tag }}"
59+
60+
- name: Commit updated Swift files
61+
run: |
62+
git add Package.swift cktap-swift/Sources
63+
if git diff --cached --quiet; then
64+
echo "No Swift package changes to commit."
65+
exit 0
66+
fi
67+
git commit -m "chore(swift): release ${{ steps.tag.outputs.tag }}"
68+
69+
- name: Create tag and push atomically
70+
run: |
71+
if git rev-parse "${{ steps.tag.outputs.tag }}" >/dev/null 2>&1; then
72+
echo "Tag already exists: ${{ steps.tag.outputs.tag }}"
73+
exit 1
74+
fi
75+
git tag "${{ steps.tag.outputs.tag }}"
76+
git push --atomic origin HEAD "${{ steps.tag.outputs.tag }}"
77+
78+
- name: Create GitHub release and upload asset
79+
env:
80+
GH_TOKEN: ${{ github.token }}
81+
run: |
82+
gh release create "${{ steps.tag.outputs.tag }}" \
83+
cktap-swift/cktapFFI.xcframework.zip \
84+
--title "${{ steps.tag.outputs.tag }}" \
85+
--notes "Swift bindings release ${{ steps.tag.outputs.tag }}"
86+
87+
- name: Cleanup failed release
88+
if: failure()
89+
env:
90+
GH_TOKEN: ${{ github.token }}
91+
run: |
92+
TAG="${{ steps.tag.outputs.tag }}"
93+
if gh release view "${TAG}" >/dev/null 2>&1; then
94+
gh release delete "${TAG}" --yes || true
95+
fi
96+
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "${TAG}$"; then
97+
git push --delete origin "${TAG}" || true
98+
fi

cktap-swift/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# CKTAP Swift bindings
2+
3+
This directory contains Swift bindings generated by UniFFI and a local SwiftPM
4+
manifest used during development.
5+
6+
## Local development
7+
8+
- Run `just build` (or `./build-xcframework.sh`) to regenerate
9+
`Sources/CKTap/cktap_ffi.swift` and `cktapFFI.xcframework`.
10+
- Run `just test` to execute Swift tests.
11+
12+
## Publishing the Swift package
13+
14+
The repo root `Package.swift` is the public SwiftPM entry point. It expects a
15+
GitHub release asset named `cktapFFI.xcframework.zip`.
16+
17+
### Manual
18+
19+
1. Build the xcframework:
20+
```
21+
just build
22+
```
23+
2. Create the zip from `cktap-swift`:
24+
```
25+
cd cktap-swift
26+
zip -r cktapFFI.xcframework.zip cktapFFI.xcframework
27+
```
28+
3. Upload the zip to the GitHub release tag.
29+
4. Compute the checksum:
30+
```
31+
swift package compute-checksum cktapFFI.xcframework.zip
32+
```
33+
5. Update the root `Package.swift` `tag` and `checksum`, then tag and release.
34+
35+
### Automated
36+
37+
Run the `Release Swift Package` workflow with a tag (e.g. `v0.1.1`). It builds
38+
the xcframework, creates the zip, updates the root `Package.swift`, commits the
39+
Swift sources, tags the release, and uploads the asset. If the workflow fails
40+
after committing, it will not auto-revert the commit.

0 commit comments

Comments
 (0)