quickstart_spm_xcodeproj.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env bash
  2. # Copyright 2025 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # Modify a .xcodeproj to use a specific branch.
  16. set -xeuo pipefail
  17. SAMPLE=$1
  18. SAMPLE_DIR=$(echo "$SAMPLE" | perl -ne 'print lc')
  19. XCODEPROJ=${SAMPLE_DIR}/${SAMPLE}Example.xcodeproj/project.pbxproj
  20. # Regex matches SemVer `firebase-ios-sdk` dependency in project.pbxproj:
  21. # {
  22. # isa = XCRemoteSwiftPackageReference;
  23. # repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
  24. # requirement = {
  25. # kind = upToNextMajorVersion;
  26. # minimumVersion = xx.yy.zz;
  27. # };
  28. # };
  29. REQUIREMENT_REGEX='({'\
  30. '\s*isa = XCRemoteSwiftPackageReference;'\
  31. '\s*repositoryURL = "https://github\.com/firebase/firebase-ios-sdk\.git";'\
  32. '\s*requirement = {\s*)kind = upToNextMajorVersion;'\
  33. '\s*minimumVersion = \d+\.\d+\.\d+;'\
  34. '(\s*};'\
  35. '\s*};)'
  36. # Replaces the minimumVersion requirement with a branch requirement.
  37. REPLACEMENT_REGEX="\1branch = $BRANCH_NAME;\n\t\t\t\tkind = branch;\2"
  38. # Performs the replacement using Perl.
  39. #
  40. # -0777 Enables reading all input in one go (slurp), rather than line-by-line.
  41. # -p Causes Perl to loop through the input line by line.
  42. # -i Edits the file in place.
  43. # -e Provides the expression to execute.
  44. perl -0777 -i -pe "s#$REQUIREMENT_REGEX#$REPLACEMENT_REGEX#g" "$XCODEPROJ" || {
  45. echo "Failed to update quickstart's Xcode project to the branch: $BRANCH_NAME"
  46. exit 1
  47. }
  48. # Point SPM CI to the tip of `main` of
  49. # https://github.com/google/GoogleAppMeasurement so that the release process
  50. # can defer publishing the `GoogleAppMeasurement` tag until after testing.
  51. export FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT=1