|
| 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 |
0 commit comments