Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/firebaseai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- '.github/workflows/common.yml'
- '.github/workflows/common_cocoapods.yml'
- 'scripts/quickstart_build_spm.sh'
- 'scripts/quickstart_spm_xcodeproj.sh'
- 'scripts/update_firebase_spm_dependency.sh'
- 'Gemfile*'
# Do not run for documentation-only PRs.
- '!**.md'
Expand Down
4 changes: 3 additions & 1 deletion scripts/quickstart_build_spm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
set -xeuo pipefail

SAMPLE=$1
SAMPLE_DIR=$(echo "$SAMPLE" | perl -ne 'print lc')
SAMPLE_XCODEPROJ=${SAMPLE_DIR}/${SAMPLE}Example.xcodeproj

scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

Expand All @@ -32,7 +34,7 @@ git clone https://github.com/firebase/quickstart-ios.git

cd quickstart-ios

source "$scripts_dir/quickstart_spm_xcodeproj.sh" "$SAMPLE"
source "$scripts_dir/update_firebase_spm_dependency.sh" "$SAMPLE_XCODEPROJ" --branch "$BRANCH_NAME"

# Placeholder GoogleService-Info.plist good enough for build only testing.
cp ./mock-GoogleService-Info.plist ./firebaseai/GoogleService-Info.plist
Expand Down
60 changes: 0 additions & 60 deletions scripts/quickstart_spm_xcodeproj.sh

This file was deleted.

121 changes: 121 additions & 0 deletions scripts/update_firebase_spm_dependency.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash

# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Modify a .xcodeproj to use a specific branch, version, or commit for the
# firebase-ios-sdk SPM dependency.

set -euo pipefail

# Enable trace mode if DEBUG is set to 'true'
if [[ "${DEBUG:-false}" == "true" ]]; then
set -x
fi

# --- Argument parsing ---
if [[ $# -lt 2 ]]; then
echo "Modify a .xcodeproj to use a specific branch, version, or commit for the"
echo "firebase-ios-sdk SPM dependency."
echo ""
echo "Usage: $0 <path_to.xcodeproj> [--version <version> | --revision <revision> | --prerelease | --branch <branch>]"
exit 1
fi

XCODEPROJ_PATH="$1"
shift
MODE="$1"
shift

PBXPROJ_PATH="${XCODEPROJ_PATH}/project.pbxproj"

# Regex matches SemVer `firebase-ios-sdk` dependency in project.pbxproj:
# {
# isa = XCRemoteSwiftPackageReference;
# repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
# requirement = {
# kind = upToNextMajorVersion;
# minimumVersion = xx.yy.zz;
# };
# };
REQUIREMENT_REGEX='({'\
'\s*isa = XCRemoteSwiftPackageReference;'\
'\s*repositoryURL = "https://github\.com/firebase/firebase-ios-sdk(?:\.git)?";'\
'\s*requirement = {\s*)kind = upToNextMajorVersion;'\
'\s*minimumVersion = \d+\.\d+\.\d+;'\
'(\s*};'\
'\s*};)'

# Define the replacement regex based on the selected mode.
case "$MODE" in
--version)
if [[ $# -lt 1 ]]; then echo "Error: Missing version for --version"; exit 1; fi
VERSION="$1"
REPLACEMENT_REGEX="\1kind = branch;\n\t\t\t\tbranch = \"$VERSION\";\2"
;;
--prerelease)
COMMIT_HASH=$(git ls-remote https://github.com/firebase/firebase-ios-sdk.git main | cut -f1)
if [[ -z "$COMMIT_HASH" ]]; then
echo "Error: Failed to get remote revision for main branch."
exit 1
fi
REPLACEMENT_REGEX="\1kind = revision;\n\t\t\t\trevision = \"$COMMIT_HASH\";\2"
;;
--revision)
if [[ $# -lt 1 ]]; then echo "Error: Missing revision for --revision"; exit 1; fi
REVISION="$1"
REPLACEMENT_REGEX="\1kind = revision;\n\t\t\t\trevision = \"$REVISION\";\2"
;;
--branch)
if [[ $# -lt 1 ]]; then echo "Error: Missing branch name for --branch"; exit 1; fi
BRANCH_NAME="$1"
REPLACEMENT_REGEX="\1kind = branch;\n\t\t\t\tbranch = \"$BRANCH_NAME\";\2"
;;
*)
echo "Invalid mode: $MODE"
exit 1
;;
esac

# Make a temporary backup of the original file.
# This will be used to check if any changes were made.
TEMP_FILE=$(mktemp)
cp "$PBXPROJ_PATH" "$TEMP_FILE"

# Performs the replacement using Perl.
#
# -0777 Enables reading all input in one go (slurp), rather than line-by-line.
# -p Causes Perl to loop through the input line by line.
# -i Edits the file in place.
# -e Provides the expression to execute.
perl -0777 -i -pe "s#$REQUIREMENT_REGEX#$REPLACEMENT_REGEX#g" "$PBXPROJ_PATH" || {
echo "Failed to update the Xcode project's SPM dependency."
exit 1
}

# Silently compare the modified file with the temporary backup.
# If they are the same, cmp will return 0 (success), and the 'if' block will run.
if cmp -s "$PBXPROJ_PATH" "$TEMP_FILE"; then
echo "Failed to find and replace the firebase-ios-sdk dependency. Check the regex pattern and project file structure."
# Restore the original file from the backup
mv "$TEMP_FILE" "$PBXPROJ_PATH"
exit 1
fi

echo "Successfully updated SPM dependency in $PBXPROJ_PATH"

# Point SPM CI to the tip of `main` of
# https://github.com/google/GoogleAppMeasurement so that the release process
# can defer publishing the `GoogleAppMeasurement` tag until after testing.
export FIREBASECI_USE_LATEST_GOOGLEAPPMEASUREMENT=1
Loading