Repository navigation
276 lines (242 loc) · 11.7 KB
/
Copy pathcreate-release-pr.yml
File metadata and controls
276 lines (242 loc) · 11.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Create Release PR
on:
# For making a release pr from android / ios sdk actions
workflow_call:
secrets:
GH_PUSH_TOKEN:
required: false
description: 'GitHub token for pushing changes'
inputs:
rn_version:
description: 'New React Native Version (e.g., 5.2.15 or 5.2.15-beta.1)'
required: true
type: string
android_version:
description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.'
required: false
type: string
ios_version:
description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.'
required: false
type: string
target_branch:
description: 'Target branch to create the release PR on. Defaults to main.'
required: false
type: string
default: main
# For making a release pr from the github actions
workflow_dispatch:
inputs:
rn_version:
description: 'Override the auto-detected version (e.g., 5.2.15 or 5.2.15-beta.1). Leave blank to auto-detect.'
required: false
type: string
android_version:
description: 'New Android SDK Version (e.g., 2.3.0). Leave blank to skip.'
required: false
type: string
ios_version:
description: 'New iOS SDK Version (e.g., 1.5.0). Leave blank to skip.'
required: false
type: string
target_branch:
description: 'Target branch to create the release PR on. Defaults to main.'
required: false
type: string
default: main
jobs:
determine_version:
runs-on: ubuntu-latest
outputs:
rn_version: ${{ inputs.rn_version || steps.next_version.outputs.version }}
release_needed: ${{ inputs.rn_version != '' || steps.next_version.outputs.release-needed == 'true' }}
steps:
- name: Determine React Native SDK version
if: github.event_name == 'workflow_dispatch' && inputs.rn_version == ''
id: next_version
uses: OneSignal/sdk-shared/.github/actions/determine-next-version@main
with:
github-token: ${{ secrets.GH_PUSH_TOKEN || github.token }}
target-repo: OneSignal/react-native-onesignal
target-branch: ${{ inputs.target_branch }}
prep:
needs: determine_version
if: needs.determine_version.outputs.release_needed == 'true'
uses: OneSignal/sdk-shared/.github/workflows/prep-release.yml@main
secrets:
# Need this cross-repo token (sdk-shared & this repo) to perform changes
GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
with:
target_repo: OneSignal/react-native-onesignal
version: ${{ needs.determine_version.outputs.rn_version }}
target_branch: ${{ inputs.target_branch }}
# React Native specific steps
update_version:
needs: [determine_version, prep]
runs-on: macos-latest
outputs:
rn_from: ${{ steps.current_versions.outputs.rn_from }}
ios_from: ${{ steps.current_versions.outputs.ios_from }}
android_from: ${{ steps.current_versions.outputs.android_from }}
steps:
- name: Checkout
uses: actions/checkout@v5
with:
# Need repository otherwise caller would set github.repository to the caller itself (e.g. sdk-shared)
repository: OneSignal/react-native-onesignal
ref: ${{ needs.prep.outputs.release_branch }}
token: ${{ secrets.GH_PUSH_TOKEN || github.token }}
- name: Setup Git User
uses: OneSignal/sdk-shared/.github/actions/setup-git-user@main
- name: Set up Vite+
uses: voidzero-dev/setup-vp@v1
with:
cache: true
run-install: true
- name: Get current native SDK versions from target branch
id: current_versions
run: |
git fetch origin ${{ inputs.target_branch }}
# Get versions from target branch (not the release branch)
CURRENT_VERSION=$(git show origin/${{ inputs.target_branch }}:package.json | jq -r .version)
ANDROID_VERSION=$(git show origin/${{ inputs.target_branch }}:android/build.gradle | sed -nE "s/.*def oneSignalVersion = ['\"]([^'\"]+)['\"].*/\1/p" | head -n 1)
IOS_VERSION=$(git show origin/${{ inputs.target_branch }}:react-native-onesignal.podspec | sed -nE "s/.*onesignal_xcframework_version = ['\"]([^'\"]+)['\"].*/\1/p" | head -n 1)
if [ -z "$ANDROID_VERSION" ]; then
echo "::error::Failed to read Android SDK version from android/build.gradle"
exit 1
fi
if [ -z "$IOS_VERSION" ]; then
echo "::error::Failed to read iOS SDK version from react-native-onesignal.podspec"
exit 1
fi
echo "rn_from=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "android_from=$ANDROID_VERSION" >> $GITHUB_OUTPUT
echo "ios_from=$IOS_VERSION" >> $GITHUB_OUTPUT
- name: Update Android SDK version
if: inputs.android_version != ''
run: |
VERSION="${{ inputs.android_version }}"
# Validate version exists on GitHub
if ! curl --fail --silent --show-error --retry 4 --retry-delay 30 \
-H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/OneSignal/OneSignal-Android-SDK/releases/tags/${VERSION}" \
>/dev/null; then
echo "✗ Android SDK version ${VERSION} not found"
exit 1
fi
sed -i '' -E "s/(def oneSignalVersion = ['\"])[^'\"]+(['\"])/\1$VERSION\2/" android/build.gradle
if ! grep -q "def oneSignalVersion = '${VERSION}'" android/build.gradle; then
echo "::error::Failed to update Android SDK version in android/build.gradle to ${VERSION}"
exit 1
fi
echo "✓ Updated android/build.gradle with Android SDK ${VERSION}"
# Only commit if there are changes
git add -A
git diff --staged --quiet && exit 0
git commit -m "Update Android SDK to ${VERSION}" && git push
- name: Update iOS SDK version
if: inputs.ios_version != ''
run: |
VERSION="${{ inputs.ios_version }}"
# Validate version exists on GitHub
if ! curl --fail --silent --show-error --retry 4 --retry-delay 30 \
-H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/OneSignal/OneSignal-iOS-SDK/releases/tags/${VERSION}" \
>/dev/null; then
echo "✗ iOS SDK version ${VERSION} not found"
exit 1
fi
sed -i '' -E "s/(onesignal_xcframework_version = ['\"])[^'\"]+(['\"])/\1$VERSION\2/" react-native-onesignal.podspec
if ! grep -q "onesignal_xcframework_version = '${VERSION}'" react-native-onesignal.podspec; then
echo "::error::Failed to update iOS SDK version in react-native-onesignal.podspec to ${VERSION}"
exit 1
fi
echo "✓ Updated react-native-onesignal.podspec with iOS SDK ${VERSION}"
sed -i '' -E "s/(let oneSignalXCFrameworkVersion: Version = \")[^\"]+(\")/\1$VERSION\2/" Package.swift
if ! grep -q "let oneSignalXCFrameworkVersion: Version = \"${VERSION}\"" Package.swift; then
echo "::error::Failed to update iOS SDK version in Package.swift to ${VERSION}"
exit 1
fi
echo "✓ Updated Package.swift with iOS SDK ${VERSION}"
PODFILE=examples/demo-pods/ios/Podfile
sed -i '' -E "s/^([[:space:]]*pod 'OneSignalXCFramework', )'[^']+'.*$/\1'${VERSION}'/" "$PODFILE"
if [ "$(grep -c "pod 'OneSignalXCFramework', '${VERSION}'$" "$PODFILE")" -ne 2 ]; then
echo "::error::Failed to update OneSignalXCFramework pins in ${PODFILE} to ${VERSION}"
exit 1
fi
echo "✓ Updated ${PODFILE} extension pods to iOS SDK ${VERSION}"
# Only commit if there are changes
git add -A
git diff --staged --quiet && exit 0
git commit -m "Update iOS SDK to ${VERSION}" && git push
- name: Update sdk version
env:
NEW_VERSION: ${{ needs.determine_version.outputs.rn_version }}
run: |
# Update package.json version
npm pkg set version="$NEW_VERSION"
# Update the wrapper version literal reported to OneSignal's backend.
# Format is MMmmpp (zero-padded major/minor/patch); strip any pre-release suffix.
CORE_VERSION=${NEW_VERSION%%-*}
CORE_VERSION=${CORE_VERSION%%+*}
IFS='.' read -r MAJOR MINOR PATCH <<< "$CORE_VERSION"
PADDED_VERSION=$(printf "%02d%02d%02d" "$MAJOR" "$MINOR" "$PATCH")
ANDROID_FILE=android/src/main/java/com/onesignal/rnonesignalandroid/RNOneSignal.java
sed -i '' -E "s/(OneSignalWrapper\.setSdkVersion\(\")[0-9]+(\"\))/\1${PADDED_VERSION}\2/" "$ANDROID_FILE"
if ! grep -q "OneSignalWrapper.setSdkVersion(\"${PADDED_VERSION}\")" "$ANDROID_FILE"; then
echo "::error::Failed to update wrapper version in ${ANDROID_FILE} to ${PADDED_VERSION}"
exit 1
fi
echo "✓ Updated RNOneSignal.java wrapper version to ${PADDED_VERSION}"
IOS_FILE=ios/RCTOneSignal/RCTOneSignal.mm
sed -i '' -E "s/(OneSignalWrapper\.sdkVersion = @\")[0-9]+(\";)/\1${PADDED_VERSION}\2/" "$IOS_FILE"
if ! grep -q "OneSignalWrapper.sdkVersion = @\"${PADDED_VERSION}\";" "$IOS_FILE"; then
echo "::error::Failed to update wrapper version in ${IOS_FILE} to ${PADDED_VERSION}"
exit 1
fi
echo "✓ Updated RCTOneSignal.mm wrapper version to ${PADDED_VERSION}"
# Only commit if there are changes
git add -A
git diff --staged --quiet && exit 0
git commit -m "Release $NEW_VERSION" && git push
- name: Refresh demo lockfiles
env:
IOS_VERSION: ${{ inputs.ios_version }}
run: |
# Runs after all version edits (package.json + podspec) so the
# repacked SDK tarball and OneSignalXCFramework pin both reflect
# the new release. setup always runs because every version bump
# changes the tarball integrity recorded in the demo bun.lock.
for DEMO in examples/demo examples/demo-pods; do
(cd "$DEMO" && vp run setup)
echo "✓ Refreshed ${DEMO}/bun.lock"
done
# demo resolves OneSignal-XCFramework through Package.swift, so only
# demo-pods has a Podfile.lock to refresh.
if [ -n "$IOS_VERSION" ]; then
(cd examples/demo-pods/ios && pod update OneSignalXCFramework)
else
# Still refresh the local react-native-onesignal pod's version and
# checksum; pod install keeps OneSignalXCFramework at its locked version.
(cd examples/demo-pods/ios && pod install)
fi
echo "✓ Refreshed examples/demo-pods/ios/Podfile.lock"
# Only commit if there are changes
git add -A
git diff --staged --quiet && exit 0
git commit -m "Update demo lockfiles" && git push
create-pr:
needs: [prep, update_version]
uses: OneSignal/sdk-shared/.github/workflows/create-release.yml@main
secrets:
# Need this cross-repo token (sdk-shared & this repo) to perform changes
GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }}
with:
# Need target_repo otherwise caller would set github.repository to the caller itself (e.g. sdk-shared)
target_repo: OneSignal/react-native-onesignal
release_branch: ${{ needs.prep.outputs.release_branch }}
target_branch: ${{ inputs.target_branch }}
android_from: ${{ needs.update_version.outputs.android_from }}
android_to: ${{ inputs.android_version }}
ios_from: ${{ needs.update_version.outputs.ios_from }}
ios_to: ${{ inputs.ios_version }}