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