Repository navigation
130 lines (110 loc) · 4.47 KB
/
Copy pathrelease.yml
File metadata and controls
130 lines (110 loc) · 4.47 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Release Wrapper
on:
workflow_dispatch:
inputs:
kmp_version:
description: "Version of the KMP Shared.xcframework release (no leading v; e.g. 0.0.1)"
required: true
default: "0.0.1"
package_version:
description: "Swift package version to tag (e.g. 0.1.0)"
required: true
default: "0.1.0"
jobs:
release:
runs-on: macos-26
permissions:
contents: write
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Configure Git author
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# The release commit is pushed to main before the tag, so a taken version must stop the release here.
- name: Check versions
env:
KMP_VERSION: ${{ inputs.kmp_version }}
PACKAGE_VERSION: ${{ inputs.package_version }}
run: |
semver='^[0-9]+\.[0-9]+\.[0-9]+$'
if [[ ! "$KMP_VERSION" =~ $semver ]]; then
echo "::error::kmp_version '${KMP_VERSION}' must look like 1.2.3, with no leading v."
exit 1
fi
if [[ ! "$PACKAGE_VERSION" =~ $semver ]]; then
echo "::error::package_version '${PACKAGE_VERSION}' must look like 1.2.3, with no leading v."
exit 1
fi
status=0
git ls-remote --exit-code --tags origin "refs/tags/v${PACKAGE_VERSION}" > /dev/null || status=$?
case "$status" in
0)
echo "::error::Tag v${PACKAGE_VERSION} already exists; pick the next package_version."
exit 1
;;
2) ;;
*)
echo "::error::Couldn't list the remote tags (git ls-remote exited with ${status})."
exit 1
;;
esac
- name: Download Shared.xcframework.zip
env:
KMP_VERSION: ${{ inputs.kmp_version }}
run: |
curl -L --fail -o Shared.xcframework.zip \
"https://github.com/quran/mobile-sync/releases/download/v${KMP_VERSION}/Shared-${KMP_VERSION}.xcframework.zip"
- name: Compute checksum
id: checksum
run: |
CHECKSUM=$(swift package compute-checksum Shared.xcframework.zip)
echo "checksum=$CHECKSUM" >> "$GITHUB_OUTPUT"
- name: Update Package.swift
env:
REMOTE_VERSION: ${{ inputs.kmp_version }}
REMOTE_CHECKSUM: ${{ steps.checksum.outputs.checksum }}
run: |
python3 - <<'PY'
from pathlib import Path
import os
import re
package = Path("Package.swift")
data = package.read_text()
version = os.environ["REMOTE_VERSION"]
checksum = os.environ["REMOTE_CHECKSUM"]
data, count_v = re.subn(r'let remoteVersion = ".*"', f'let remoteVersion = "{version}"', data, count=1)
if count_v != 1:
raise SystemExit("Failed to update remoteVersion in Package.swift")
data, count_c = re.subn(r'let remoteChecksum = ".*"', f'let remoteChecksum = "{checksum}"', data, count=1)
if count_c != 1:
raise SystemExit("Failed to update remoteChecksum in Package.swift")
package.write_text(data)
PY
# The Swift package must match the Kotlin plugin that built this Shared, so take its version from mobile-sync.
- name: Set KMP-NativeCoroutines from mobile-sync
run: scripts/check-native-coroutines.sh --update
# Pushes from this workflow use GITHUB_TOKEN and don't trigger CI, so this is the only check a release gets.
- name: Check KMP-NativeCoroutines matches mobile-sync
run: scripts/check-native-coroutines.sh
- name: Setting up Xcode
run: sudo xcode-select -s "/Applications/Xcode_26.2.app"
# Same as CI: a failing test stops the release before anything is committed, pushed or tagged.
- name: Build and test package
run: scripts/test.sh
- name: Commit release
env:
PACKAGE_VERSION: ${{ inputs.package_version }}
run: |
git add Package.swift
git commit --allow-empty -m "Release ${PACKAGE_VERSION}"
- name: Push release commit and tag
env:
PACKAGE_VERSION: ${{ inputs.package_version }}
run: |
git push origin HEAD:main
git tag "v${PACKAGE_VERSION}"
git push origin "v${PACKAGE_VERSION}"