@@ -9,6 +9,21 @@ latest_release_number () {
9
9
head -1 || echo ' 0.0.0'
10
10
}
11
11
12
+ branch_exists () {
13
+ # Check if the branch exists on the remote
14
+ git ls-remote --heads origin " $1 " 2> /dev/null | grep -q " $1 " || echo 0
15
+ }
16
+
17
+ pr_exists_and_open () {
18
+ # Check if the PR exists and is open on the remote
19
+ gh pr view $1 --json state | jq -r ' .state' | grep -q " OPEN" || echo 0
20
+ }
21
+
22
+ is_pr_approved () {
23
+ # Check if the PR needs review
24
+ gh pr view $1 --json reviewDecision | jq -r ' .reviewDecision' | grep -q " APPROVED" || echo 0
25
+ }
26
+
12
27
xcframework_name () {
13
28
# Filter out path and extension to get the framework name
14
29
# Ex. xcframework_name "FirebaseFirestore/leveldb-library.xcframework" = "leveldb-library"
@@ -269,16 +284,41 @@ login_reviewer() {
269
284
}
270
285
271
286
commit_changes () {
272
- branch=$1
273
- git checkout -b $branch
287
+ local latest=$1
288
+ local branch=$2
289
+ local scratch=$3
290
+ local repo=$4
291
+
274
292
git add .
275
- git commit -m" Updated Package.swift and sources for latest firebase sdks"
293
+ git commit -m " Updated Package.swift and sources for latest firebase sdks"
276
294
git push -u origin $branch
277
- gh pr create --fill
278
- login_reviewer
279
- gh pr review --approve
295
+
296
+ local pr_exists_and_open=$( pr_exists_and_open $branch )
297
+ local release_notes=$( gh release view --repo $repo --json body | jq -r ' .body' )
298
+
299
+ if [[ $pr_exists_and_open -eq 1 ]]; then
300
+ echo " Pull request $branch already exists."
301
+ else
302
+ echo " Creating pull request for $branch ..."
303
+ gh pr create --title " Update to Firebase $latest " --body " $release_notes " --base main --head $branch
304
+ fi
305
+
306
+ local is_pr_approved=$( is_pr_approved $branch )
307
+
308
+ if [[ $is_pr_approved -eq 1 ]]; then
309
+ echo " Pull request $branch is already approved."
310
+ else
311
+ echo " Approving pull request $branch ..."
312
+ login_reviewer
313
+ gh pr review --approve
314
+ fi
315
+
316
+ echo " Merging pull request $branch ..."
280
317
login_default
281
318
gh pr merge --squash
319
+
320
+ echo " Creating release..."
321
+ gh release create --title " $latest " --notes " $release_notes " --target " $branch " $latest $scratch /dist/* .xcframework.zip
282
322
}
283
323
284
324
# Exit when any command fails
@@ -304,52 +344,68 @@ if [[ $latest != $current || $debug ]]; then
304
344
distribution=" dist"
305
345
sources=" Sources"
306
346
package=" Package.swift"
347
+ branch=" release/$latest "
348
+
349
+ git fetch origin
307
350
308
- # Generate files in a temporary directory
309
- # Use subshell to return to original directory when finished with scratchwork
310
- create_scratch
311
- (
312
- cd $scratch
313
- home=$OLDPWD
314
- echo " Downloading latest release..."
315
- gh release download --pattern ' Firebase.zip' --repo $firebase_repo
316
- echo " Unzipping.."
317
- unzip -q Firebase.zip
318
- echo " Preparing xcframeworks for distribution..."
319
- cd Firebase
320
- rename_frameworks " _"
321
- zip_frameworks
322
- echo " Creating distribution files..."
323
- prepare_files_for_distribution " ../$distribution "
324
- echo " Creating source files..."
325
- generate_sources " ../$sources "
326
- # Create test package using local binaries and make sure it builds
327
- generate_swift_package " ../$package " " $home /package_template.swift" " ../$distribution " $xcframeworks_repo $distribution
328
- echo " Validating..."
329
- (cd ..; swift package dump-package | read pac)
330
- (cd ..; swift build) # TODO: create tests and replace this line with `(cd ..; swift test)`
331
- # Create release package using remote binaries and make sure the Package.swift file is parseable
332
- generate_swift_package " ../$package " " $home /package_template.swift" " ../$distribution " $xcframeworks_repo ' '
333
- echo " Validating..."
334
- (cd ..; swift package dump-package | read pac)
335
- )
336
-
337
- echo " Moving files to repo..." ; cd ..
338
- # Remove any existing files
339
- if [ -d $sources ]; then rm -rf " $sources " ; fi
340
- if [ -f $package ]; then rm -f " $package " ; fi
341
- # Move generated files into the repo directory
342
- mv " $scratch /$sources " " $sources "
343
- mv " $scratch /$package " " $package "
351
+ release_branch_exists=$( branch_exists $branch )
352
+ pr_exists_and_open=$( pr_exists_and_open $branch )
353
+
354
+ if [[ $release_branch_exists -eq 1 ]]; then
355
+ echo " Branch $branch already exists."
356
+ git checkout $branch
357
+ else
358
+ echo " Creating branch $branch ..."
359
+ git checkout -b $branch
360
+ fi
361
+
362
+ if [[ $pr_exists_and_open -eq 0 || $FORCE ]]; then
363
+ # Generate files in a temporary directory
364
+ # Use subshell to return to original directory when finished with scratchwork
365
+ create_scratch
366
+ (
367
+ cd $scratch
368
+ home=$OLDPWD
369
+ echo " Downloading latest release..."
370
+ gh release download --pattern ' Firebase.zip' --repo $firebase_repo
371
+ echo " Unzipping.."
372
+ unzip -q Firebase.zip
373
+ echo " Preparing xcframeworks for distribution..."
374
+ cd Firebase
375
+ rename_frameworks " _"
376
+ zip_frameworks
377
+ echo " Creating distribution files..."
378
+ prepare_files_for_distribution " ../$distribution "
379
+ echo " Creating source files..."
380
+ generate_sources " ../$sources "
381
+ # Create test package using local binaries and make sure it builds
382
+ generate_swift_package " ../$package " " $home /package_template.swift" " ../$distribution " $xcframeworks_repo $distribution
383
+ echo " Validating..."
384
+ (cd ..; swift package dump-package | read pac)
385
+ (cd ..; swift build) # TODO: create tests and replace this line with `(cd ..; swift test)`
386
+ # Create release package using remote binaries and make sure the Package.swift file is parseable
387
+ generate_swift_package " ../$package " " $home /package_template.swift" " ../$distribution " $xcframeworks_repo ' '
388
+ echo " Validating..."
389
+ (cd ..; swift package dump-package | read pac)
390
+ )
391
+
392
+ echo " Moving files to repo..." ; cd ..
393
+ # Remove any existing files
394
+ if [ -d $sources ]; then rm -rf " $sources " ; fi
395
+ if [ -f $package ]; then rm -f " $package " ; fi
396
+ # Move generated files into the repo directory
397
+ mv " $scratch /$sources " " $sources "
398
+ mv " $scratch /$package " " $package "
399
+ else
400
+ echo " Pull request $branch already exists and is open."
401
+ fi
344
402
345
403
# Skips deploy
346
404
if [[ $skip_release ]]; then echo " Done." ; exit 0; fi
347
405
348
406
# Deploy to repository
349
407
echo " Merging changes to Github..."
350
- commit_changes " release/$latest "
351
- echo " Creating release draft"
352
- echo " Release $latest " | gh release create --title " $latest " --target " release/$latest " $latest $scratch /dist/* .xcframework.zip
408
+ commit_changes " $latest " " $branch " " $scratch " " $firebase_repo "
353
409
else
354
410
echo " $current is up to date."
355
411
fi
0 commit comments