diff --git a/.github/workflows/abtesting.yml b/.github/workflows/abtesting.yml index ab2b77aa8d6..f5a2d6f81c0 100644 --- a/.github/workflows/abtesting.yml +++ b/.github/workflows/abtesting.yml @@ -45,7 +45,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: ABTesting - setup_command: scripts/setup_quickstart_spm.sh abtesting + setup_command: scripts/setup_quickstart.sh abtesting plist_src_path: scripts/gha-encrypted/qs-abtesting.plist.gpg plist_dst_path: quickstart-ios/abtesting/GoogleService-Info.plist secrets: @@ -69,7 +69,7 @@ jobs: with: python-version: '3.11' - name: Setup quickstart - run: scripts/setup_quickstart_spm.sh abtesting + run: scripts/setup_quickstart.sh abtesting - name: Install Secret GoogleService-Info.plist run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/qs-abtesting.plist.gpg \ quickstart-ios/abtesting/GoogleService-Info.plist "$plist_secret" diff --git a/.github/workflows/auth.yml b/.github/workflows/auth.yml index fd9cce9f5be..4a0f8a36547 100644 --- a/.github/workflows/auth.yml +++ b/.github/workflows/auth.yml @@ -97,7 +97,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Authentication - setup_command: scripts/setup_quickstart_spm.sh authentication + setup_command: scripts/setup_quickstart.sh authentication plist_src_path: scripts/gha-encrypted/qs-authentication.plist.gpg plist_dst_path: quickstart-ios/authentication/GoogleService-Info.plist run_tests: false diff --git a/.github/workflows/crashlytics.yml b/.github/workflows/crashlytics.yml index 341da63a063..79288931bc6 100644 --- a/.github/workflows/crashlytics.yml +++ b/.github/workflows/crashlytics.yml @@ -48,7 +48,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Crashlytics - setup_command: scripts/setup_quickstart_spm.sh crashlytics + setup_command: scripts/setup_quickstart.sh crashlytics plist_src_path: scripts/gha-encrypted/qs-crashlytics.plist.gpg plist_dst_path: quickstart-ios/crashlytics/GoogleService-Info.plist secrets: @@ -74,7 +74,7 @@ jobs: - name: Xcode run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer - name: Setup quickstart - run: scripts/setup_quickstart_spm.sh crashlytics + run: scripts/setup_quickstart.sh crashlytics - name: Install Secret GoogleService-Info.plist run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/qs-crashlytics.plist.gpg \ quickstart-ios/crashlytics/GoogleService-Info.plist "$plist_secret" diff --git a/.github/workflows/database.yml b/.github/workflows/database.yml index b75ecb9f8a3..7c99accf44b 100644 --- a/.github/workflows/database.yml +++ b/.github/workflows/database.yml @@ -74,7 +74,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Database - setup_command: scripts/setup_quickstart_spm.sh database + setup_command: scripts/setup_quickstart.sh database plist_src_path: scripts/gha-encrypted/qs-database.plist.gpg plist_dst_path: quickstart-ios/database/GoogleService-Info.plist run_tests: false diff --git a/.github/workflows/firestore.yml b/.github/workflows/firestore.yml index 4c3e9726425..1c93b975311 100644 --- a/.github/workflows/firestore.yml +++ b/.github/workflows/firestore.yml @@ -605,7 +605,7 @@ jobs: # uses: ./.github/workflows/common_quickstart.yml # with: # product: Firestore - # setup_command: scripts/setup_quickstart_spm.sh firestore + # setup_command: scripts/setup_quickstart.sh firestore # plist_src_path: scripts/gha-encrypted/qs-firestore.plist.gpg # plist_dst_path: quickstart-ios/firestore/GoogleService-Info.plist # run_tests: false diff --git a/.github/workflows/inappmessaging.yml b/.github/workflows/inappmessaging.yml index b7ace6a847a..c4ef6f675b9 100644 --- a/.github/workflows/inappmessaging.yml +++ b/.github/workflows/inappmessaging.yml @@ -76,7 +76,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: InAppMessaging - setup_command: scripts/setup_quickstart_spm.sh inappmessaging + setup_command: scripts/setup_quickstart.sh inappmessaging plist_src_path: scripts/gha-encrypted/qs-inappmessaging.plist.gpg plist_dst_path: quickstart-ios/inappmessaging/GoogleService-Info.plist run_tests: false diff --git a/.github/workflows/installations.yml b/.github/workflows/installations.yml index 6037a762d2c..140274967e2 100644 --- a/.github/workflows/installations.yml +++ b/.github/workflows/installations.yml @@ -53,7 +53,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Installations - setup_command: scripts/setup_quickstart_spm.sh installations + setup_command: scripts/setup_quickstart.sh installations plist_src_path: scripts/gha-encrypted/Installations/GoogleService-Info.plist.gpg plist_dst_path: quickstart-ios/installations/GoogleService-Info.plist secrets: @@ -76,7 +76,7 @@ jobs: - name: Xcode run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer - name: Setup quickstart - run: scripts/setup_quickstart_spm.sh installations + run: scripts/setup_quickstart.sh installations - name: Copy mock plist run: cp quickstart-ios/mock-GoogleService-Info.plist quickstart-ios/installations/GoogleService-Info.plist - name: Build quickstart diff --git a/.github/workflows/messaging.yml b/.github/workflows/messaging.yml index 2939d779594..86af0505687 100644 --- a/.github/workflows/messaging.yml +++ b/.github/workflows/messaging.yml @@ -85,7 +85,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Messaging - setup_command: scripts/setup_quickstart_spm.sh messaging + setup_command: scripts/setup_quickstart.sh messaging plist_src_path: scripts/gha-encrypted/qs-messaging.plist.gpg plist_dst_path: quickstart-ios/messaging/GoogleService-Info.plist run_tests: false @@ -105,7 +105,7 @@ jobs: - name: Xcode run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer - name: Setup quickstart - run: scripts/setup_quickstart_spm.sh messaging + run: scripts/setup_quickstart.sh messaging - name: Install Secret GoogleService-Info.plist run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/qs-messaging.plist.gpg \ quickstart-ios/messaging/GoogleService-Info.plist "$plist_secret" diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index d5b39b13b39..2eaef8ca98e 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -82,7 +82,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Performance - setup_command: scripts/setup_quickstart_spm.sh performance + setup_command: scripts/setup_quickstart.sh performance plist_src_path: scripts/gha-encrypted/qs-performance.plist.gpg plist_dst_path: quickstart-ios/performance/GoogleService-Info.plist secrets: @@ -104,7 +104,7 @@ jobs: - name: Install xcpretty run: gem install xcpretty - name: Setup quickstart - run: scripts/setup_quickstart_spm.sh performance + run: scripts/setup_quickstart.sh performance - name: Install Secret GoogleService-Info.plist run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/qs-performance.plist.gpg \ quickstart-ios/performance/GoogleService-Info.plist "$plist_secret" diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index e6575f9a614..7a9537ecac6 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -101,7 +101,7 @@ jobs: - name: Xcode run: sudo xcode-select -s /Applications/Xcode_16.4.app/Contents/Developer - name: Setup testing repo and quickstart - run: scripts/setup_quickstart_spm.sh ${{ matrix.product }} prerelease_testing + run: scripts/setup_quickstart.sh ${{ matrix.product }} prerelease_testing - name: Install Secret GoogleService-Info.plist run: | scripts/decrypt_gha_secret.sh \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0a3d4842b53..3a191c3d473 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,7 +99,7 @@ jobs: - name: Prereqs run: gem install xcpretty - name: Setup testing repo and quickstart - run: scripts/setup_quickstart_spm.sh ${{ matrix.product }} nightly_release_testing + run: scripts/setup_quickstart.sh ${{ matrix.product }} nightly_release_testing - name: Install Secret GoogleService-Info.plist run: | scripts/decrypt_gha_secret.sh scripts/gha-encrypted/qs-${{ matrix.product }}.plist.gpg \ diff --git a/.github/workflows/remoteconfig.yml b/.github/workflows/remoteconfig.yml index 36ba73ed473..2293aaa9283 100644 --- a/.github/workflows/remoteconfig.yml +++ b/.github/workflows/remoteconfig.yml @@ -94,7 +94,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Config - setup_command: scripts/setup_quickstart_spm.sh config + setup_command: scripts/setup_quickstart.sh config plist_src_path: scripts/gha-encrypted/qs-config.plist.gpg plist_dst_path: quickstart-ios/config/GoogleService-Info.plist secrets: diff --git a/.github/workflows/storage.yml b/.github/workflows/storage.yml index 9aae03de131..8155d718928 100644 --- a/.github/workflows/storage.yml +++ b/.github/workflows/storage.yml @@ -83,7 +83,7 @@ jobs: uses: ./.github/workflows/common_quickstart.yml with: product: Storage - setup_command: scripts/setup_quickstart_spm.sh storage + setup_command: scripts/setup_quickstart.sh storage plist_src_path: scripts/gha-encrypted/qs-storage.plist.gpg plist_dst_path: quickstart-ios/storage/GoogleService-Info.plist run_tests: false diff --git a/scripts/setup_quickstart.sh b/scripts/setup_quickstart.sh index 840b1eaebdc..faf0224fec8 100755 --- a/scripts/setup_quickstart.sh +++ b/scripts/setup_quickstart.sh @@ -1,4 +1,6 @@ -# Copyright 2019 Google +#!/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. @@ -12,63 +14,247 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Script to run in a CI `before_install` phase to setup a SPM-based +# quickstart repo so that it can be used for integration testing. + +set -euo pipefail -# Script to run in a CI `before_install` phase to setup the quickstart repo -# so that it can be used for integration testing. +# Define testing mode constants. +readonly NIGHTLY_RELEASE_TESTING="nightly_release_testing" +readonly PRERELEASE_TESTING="prerelease_testing" -set -xeuo pipefail +# All script logic is contained in functions. The main function is called at +# the end. +# Global variables: +# - readonly constants are defined at the top. +# - scripts_dir and root_dir are set after constants. scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root_dir="$(dirname "$scripts_dir")" -$scripts_dir/setup_bundler.sh +print_usage() { + cat < [testing_mode] -# Source function to check if CI secrets are available. -source $scripts_dir/check_secrets.sh +This script sets up a quickstart sample for SPM integration testing. -SAMPLE=$1 +ARGUMENTS: + The name of the quickstart sample directory + (e.g., "authentication"). + [testing_mode] Optional. Specifies the testing mode. Can be one of: + - "${NIGHTLY_RELEASE_TESTING}": Points SPM to the latest + CocoaPods tag. + - "${PRERELEASE_TESTING}": Points SPM to the tip of the main + branch. + - (default): Points SPM to the current commit for PR testing. -RELEASE_TESTING=${2-} +ENVIRONMENT VARIABLES: + QUICKSTART_REPO: Optional. Path to a local clone of the quickstart-ios repo. + If not set, the script will clone it from GitHub. + Example: + QUICKSTART_REPO=/path/to/quickstart-ios $(basename "$0") authentication -WORKSPACE_DIR="quickstart-ios/${SAMPLE}" -PODFILE="quickstart-ios/"$SAMPLE"/Podfile" + QUICKSTART_BRANCH: Optional. The branch to checkout in the quickstart repo. + Defaults to the repo's default branch. + Example: + QUICKSTART_BRANCH=my-feature-branch $(basename "$0") authentication -if [[ ! -z "${LEGACY:-}" ]]; then - WORKSPACE_DIR="quickstart-ios/${SAMPLE}/Legacy${SAMPLE}Quickstart" - PODFILE="quickstart-ios/"$SAMPLE"/Legacy${SAMPLE}Quickstart/Podfile" -fi + BYPASS_SECRET_CHECK: Optional. Set to "true" to bypass the CI secret check + for local runs. + Example: + BYPASS_SECRET_CHECK=true $(basename "$0") authentication -gem install xcpretty + DEBUG: Optional. Set to "true" to enable shell trace mode (`set -x`). + Example: DEBUG=true $(basename "$0") authentication +EOF +} -# Installations is the only quickstart that doesn't need a real -# GoogleService-Info.plist for its tests. -if check_secrets || [[ ${SAMPLE} == "installations" ]]; then +# Clones or locates the quickstart repo. +# +# Globals: +# - QUICKSTART_REPO (read-only) +# Arguments: +# - $1: The name of the sample. +# Outputs: +# - Echoes the absolute path to the quickstart directory. +setup_quickstart_repo() { + local sample_name="$1" + local quickstart_dir - # Specify repo so the Firebase module and header can be found in a - # development pod install. This is needed for the `pod install` command. - export FIREBASE_POD_REPO_FOR_DEV_POD=`pwd` + # If QUICKSTART_REPO is set, use it. Otherwise, clone the repo. + if [[ -n "${QUICKSTART_REPO:-}" ]]; then + # If the user provided a path, it must be a valid directory. + if [[ ! -d "${QUICKSTART_REPO}" ]]; then + echo "Error: QUICKSTART_REPO is set to '${QUICKSTART_REPO}'," \ + "but this is not a valid directory." >&2 + exit 1 + fi + echo "Using local quickstart repository at ${QUICKSTART_REPO}" >&2 + quickstart_dir="${QUICKSTART_REPO}" + if ! (cd "${quickstart_dir}" && \ + git rev-parse --is-inside-work-tree >/dev/null 2>&1); then + echo "Error: QUICKSTART_REPO ('${quickstart_dir}') is not a git" \ + "repository." >&2 + exit 1 + fi + else + # QUICKSTART_REPO is not set, so clone it. + quickstart_dir="quickstart-ios" + if [[ -d "${quickstart_dir}" ]]; then + echo "Quickstart repository already exists at ${quickstart_dir}" >&2 + else + echo "Cloning quickstart repository into '${quickstart_dir}' directory..." >&2 + # Do a partial, sparse clone to speed up CI. See + # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ + git clone --filter=blob:none --sparse \ + https://github.com/firebase/quickstart-ios.git "${quickstart_dir}" + fi + ( + cd "${quickstart_dir}" + echo "Ensuring sparse checkout is set for ${sample_name}..." >&2 + # Checkout the sample and scripts directories. + git sparse-checkout set "${sample_name}" scripts shared + ) + fi - git clone https://github.com/firebase/quickstart-ios.git + # If a branch is specified, check it out. + if [[ -n "${QUICKSTART_BRANCH:-}" ]]; then + echo "Checking out quickstart branch: ${QUICKSTART_BRANCH}" >&2 + ( + cd "${quickstart_dir}" + git fetch --quiet + git checkout --quiet "${QUICKSTART_BRANCH}" + ) + fi - $scripts_dir/localize_podfile.swift "$WORKSPACE_DIR"/Podfile "$RELEASE_TESTING" - if [ "$RELEASE_TESTING" == "nightly_release_testing" ]; then - set +x - sed -i "" '1i\'$'\n'"source 'https://github.com/Firebase/SpecsReleasing.git'"$'\n' "$PODFILE" - set -x - echo "Source of Podfile for nightly release testing is updated." + # Return the absolute path to the quickstart directory. + (cd "$quickstart_dir" && pwd) +} + +# Updates the SPM dependency in the Xcode project based on the testing mode. +# +# Globals: +# - NIGHTLY_RELEASE_TESTING (read-only) +# - PRERELEASE_TESTING (read-only) +# - scripts_dir (read-only) +# - root_dir (read-only) +# Arguments: +# - $1: The testing mode. +# - $2: The absolute path to the .xcodeproj file. +update_spm_dependency() { + local release_testing_mode="$1" + local absolute_project_file="$2" + + case "$release_testing_mode" in + "${NIGHTLY_RELEASE_TESTING}") + # For release testing, find the latest CocoaPods tag. + local latest_tag + latest_tag=$(git -C "$root_dir" tag -l "CocoaPods-*" --sort=-v:refname | + awk '/^CocoaPods-[0-9]+\.[0-9]+\.[0-9]+$/{print; exit}') + if [[ -z "$latest_tag" ]]; then + echo "Error: Could not find the latest CocoaPods tag." >&2 + echo "This is often caused by a shallow git clone in a CI environment." >&2 + echo "If you are running in GitHub Actions, please ensure your checkout" >&2 + echo "step includes 'fetch-depth: 0' to fetch the full git history." >&2 + exit 1 + fi + local tag_revision + tag_revision=$(git -C "$root_dir" rev-list -n 1 "$latest_tag") + echo "Setting SPM dependency to revision for tag ${latest_tag}:" \ + "${tag_revision}" + "$scripts_dir/update_firebase_spm_dependency.sh" \ + "$absolute_project_file" --revision "$tag_revision" + ;; + + "${PRERELEASE_TESTING}") + # For prerelease testing, point to the tip of the main branch. + echo "Setting SPM dependency to the tip of the main branch." + "$scripts_dir/update_firebase_spm_dependency.sh" \ + "$absolute_project_file" --prerelease + ;; + + *) + # For PR testing, point to the current commit. + local current_revision + current_revision=$(git -C "$root_dir" rev-parse HEAD) + echo "Setting SPM dependency to current revision: ${current_revision}" + "$scripts_dir/update_firebase_spm_dependency.sh" \ + "$absolute_project_file" --revision "$current_revision" + ;; + esac +} + +main() { + # --- Argument Parsing --- + if [[ -z "${1:-}" ]]; then + print_usage + exit 1 fi - if [ "$RELEASE_TESTING" == "prerelease_testing" ]; then - set +x - sed -i "" '1i\'$'\n'"source 'https://github.com/Firebase/SpecsTesting.git'"$'\n' "$PODFILE" + + local sample="$1" + local release_testing="${2-}" + + # Validate release_testing argument. + case "$release_testing" in + "" | "${NIGHTLY_RELEASE_TESTING}" | "${PRERELEASE_TESTING}") + # This is a valid value (or empty), so do nothing. + ;; + *) + # This is an invalid value. + echo "Error: Invalid testing_mode: '${release_testing}'" >&2 + print_usage + exit 1 + ;; + esac + + # --- Environment Setup and Validation --- + # Enable trace mode if DEBUG is set to 'true' + if [[ "${DEBUG:-false}" == "true" ]]; then set -x - echo "Source of Podfile for prerelease testing is updated." fi - cd "${WORKSPACE_DIR}" - # To test a branch, uncomment the following line - # git checkout {BRANCH_NAME} + # Source function to check if CI secrets are available. + source "$scripts_dir/check_secrets.sh" + + # Some quickstarts may not need a real GoogleService-Info.plist for their + # tests. When QUICKSTART_REPO is set (for local runs) or BYPASS_SECRET_CHECK + # is true, the secrets check is skipped. + if [[ -z "${QUICKSTART_REPO:-}" ]] && \ + [[ "${BYPASS_SECRET_CHECK:-}" != "true" ]] && \ + ! check_secrets && \ + [[ "${sample}" != "installations" ]]; then + echo "Skipping quickstart setup: CI secrets are not available." + exit 0 + fi + + # --- Main Logic --- + local quickstart_dir + quickstart_dir=$(setup_quickstart_repo "$sample") + + local quickstart_project_dir="${quickstart_dir}/${sample}" + + if [[ ! -d "${quickstart_project_dir}" ]]; then + echo "Error: Sample directory not found at '${quickstart_project_dir}'" >&2 + exit 1 + fi + + # Find the .xcodeproj file within the sample directory. + # Fail if there isn't exactly one. + # Enable nullglob to ensure the glob expands to an empty list if no files + # are found. + shopt -s nullglob + local project_files=("${quickstart_project_dir}"/*.xcodeproj) + # Restore default globbing behavior. + shopt -u nullglob + if [[ "${#project_files[@]}" -ne 1 ]]; then + echo "Error: Expected 1 .xcodeproj file in" \ + "'${quickstart_project_dir}', but found ${#project_files[@]}." >&2 + exit 1 + fi + local project_file="${project_files[0]}" + + update_spm_dependency "$release_testing" "$project_file" +} - bundle update --bundler - bundle install - pod update -fi +# Run the main function with all provided arguments. +main "$@" diff --git a/scripts/setup_quickstart_spm.sh b/scripts/setup_quickstart_spm.sh deleted file mode 100755 index faf0224fec8..00000000000 --- a/scripts/setup_quickstart_spm.sh +++ /dev/null @@ -1,260 +0,0 @@ -#!/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. - -# Script to run in a CI `before_install` phase to setup a SPM-based -# quickstart repo so that it can be used for integration testing. - -set -euo pipefail - -# Define testing mode constants. -readonly NIGHTLY_RELEASE_TESTING="nightly_release_testing" -readonly PRERELEASE_TESTING="prerelease_testing" - -# All script logic is contained in functions. The main function is called at -# the end. -# Global variables: -# - readonly constants are defined at the top. -# - scripts_dir and root_dir are set after constants. - -scripts_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -root_dir="$(dirname "$scripts_dir")" - -print_usage() { - cat < [testing_mode] - -This script sets up a quickstart sample for SPM integration testing. - -ARGUMENTS: - The name of the quickstart sample directory - (e.g., "authentication"). - [testing_mode] Optional. Specifies the testing mode. Can be one of: - - "${NIGHTLY_RELEASE_TESTING}": Points SPM to the latest - CocoaPods tag. - - "${PRERELEASE_TESTING}": Points SPM to the tip of the main - branch. - - (default): Points SPM to the current commit for PR testing. - -ENVIRONMENT VARIABLES: - QUICKSTART_REPO: Optional. Path to a local clone of the quickstart-ios repo. - If not set, the script will clone it from GitHub. - Example: - QUICKSTART_REPO=/path/to/quickstart-ios $(basename "$0") authentication - - QUICKSTART_BRANCH: Optional. The branch to checkout in the quickstart repo. - Defaults to the repo's default branch. - Example: - QUICKSTART_BRANCH=my-feature-branch $(basename "$0") authentication - - BYPASS_SECRET_CHECK: Optional. Set to "true" to bypass the CI secret check - for local runs. - Example: - BYPASS_SECRET_CHECK=true $(basename "$0") authentication - - DEBUG: Optional. Set to "true" to enable shell trace mode (`set -x`). - Example: DEBUG=true $(basename "$0") authentication -EOF -} - -# Clones or locates the quickstart repo. -# -# Globals: -# - QUICKSTART_REPO (read-only) -# Arguments: -# - $1: The name of the sample. -# Outputs: -# - Echoes the absolute path to the quickstart directory. -setup_quickstart_repo() { - local sample_name="$1" - local quickstart_dir - - # If QUICKSTART_REPO is set, use it. Otherwise, clone the repo. - if [[ -n "${QUICKSTART_REPO:-}" ]]; then - # If the user provided a path, it must be a valid directory. - if [[ ! -d "${QUICKSTART_REPO}" ]]; then - echo "Error: QUICKSTART_REPO is set to '${QUICKSTART_REPO}'," \ - "but this is not a valid directory." >&2 - exit 1 - fi - echo "Using local quickstart repository at ${QUICKSTART_REPO}" >&2 - quickstart_dir="${QUICKSTART_REPO}" - if ! (cd "${quickstart_dir}" && \ - git rev-parse --is-inside-work-tree >/dev/null 2>&1); then - echo "Error: QUICKSTART_REPO ('${quickstart_dir}') is not a git" \ - "repository." >&2 - exit 1 - fi - else - # QUICKSTART_REPO is not set, so clone it. - quickstart_dir="quickstart-ios" - if [[ -d "${quickstart_dir}" ]]; then - echo "Quickstart repository already exists at ${quickstart_dir}" >&2 - else - echo "Cloning quickstart repository into '${quickstart_dir}' directory..." >&2 - # Do a partial, sparse clone to speed up CI. See - # https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/ - git clone --filter=blob:none --sparse \ - https://github.com/firebase/quickstart-ios.git "${quickstart_dir}" - fi - ( - cd "${quickstart_dir}" - echo "Ensuring sparse checkout is set for ${sample_name}..." >&2 - # Checkout the sample and scripts directories. - git sparse-checkout set "${sample_name}" scripts shared - ) - fi - - # If a branch is specified, check it out. - if [[ -n "${QUICKSTART_BRANCH:-}" ]]; then - echo "Checking out quickstart branch: ${QUICKSTART_BRANCH}" >&2 - ( - cd "${quickstart_dir}" - git fetch --quiet - git checkout --quiet "${QUICKSTART_BRANCH}" - ) - fi - - # Return the absolute path to the quickstart directory. - (cd "$quickstart_dir" && pwd) -} - -# Updates the SPM dependency in the Xcode project based on the testing mode. -# -# Globals: -# - NIGHTLY_RELEASE_TESTING (read-only) -# - PRERELEASE_TESTING (read-only) -# - scripts_dir (read-only) -# - root_dir (read-only) -# Arguments: -# - $1: The testing mode. -# - $2: The absolute path to the .xcodeproj file. -update_spm_dependency() { - local release_testing_mode="$1" - local absolute_project_file="$2" - - case "$release_testing_mode" in - "${NIGHTLY_RELEASE_TESTING}") - # For release testing, find the latest CocoaPods tag. - local latest_tag - latest_tag=$(git -C "$root_dir" tag -l "CocoaPods-*" --sort=-v:refname | - awk '/^CocoaPods-[0-9]+\.[0-9]+\.[0-9]+$/{print; exit}') - if [[ -z "$latest_tag" ]]; then - echo "Error: Could not find the latest CocoaPods tag." >&2 - echo "This is often caused by a shallow git clone in a CI environment." >&2 - echo "If you are running in GitHub Actions, please ensure your checkout" >&2 - echo "step includes 'fetch-depth: 0' to fetch the full git history." >&2 - exit 1 - fi - local tag_revision - tag_revision=$(git -C "$root_dir" rev-list -n 1 "$latest_tag") - echo "Setting SPM dependency to revision for tag ${latest_tag}:" \ - "${tag_revision}" - "$scripts_dir/update_firebase_spm_dependency.sh" \ - "$absolute_project_file" --revision "$tag_revision" - ;; - - "${PRERELEASE_TESTING}") - # For prerelease testing, point to the tip of the main branch. - echo "Setting SPM dependency to the tip of the main branch." - "$scripts_dir/update_firebase_spm_dependency.sh" \ - "$absolute_project_file" --prerelease - ;; - - *) - # For PR testing, point to the current commit. - local current_revision - current_revision=$(git -C "$root_dir" rev-parse HEAD) - echo "Setting SPM dependency to current revision: ${current_revision}" - "$scripts_dir/update_firebase_spm_dependency.sh" \ - "$absolute_project_file" --revision "$current_revision" - ;; - esac -} - -main() { - # --- Argument Parsing --- - if [[ -z "${1:-}" ]]; then - print_usage - exit 1 - fi - - local sample="$1" - local release_testing="${2-}" - - # Validate release_testing argument. - case "$release_testing" in - "" | "${NIGHTLY_RELEASE_TESTING}" | "${PRERELEASE_TESTING}") - # This is a valid value (or empty), so do nothing. - ;; - *) - # This is an invalid value. - echo "Error: Invalid testing_mode: '${release_testing}'" >&2 - print_usage - exit 1 - ;; - esac - - # --- Environment Setup and Validation --- - # Enable trace mode if DEBUG is set to 'true' - if [[ "${DEBUG:-false}" == "true" ]]; then - set -x - fi - - # Source function to check if CI secrets are available. - source "$scripts_dir/check_secrets.sh" - - # Some quickstarts may not need a real GoogleService-Info.plist for their - # tests. When QUICKSTART_REPO is set (for local runs) or BYPASS_SECRET_CHECK - # is true, the secrets check is skipped. - if [[ -z "${QUICKSTART_REPO:-}" ]] && \ - [[ "${BYPASS_SECRET_CHECK:-}" != "true" ]] && \ - ! check_secrets && \ - [[ "${sample}" != "installations" ]]; then - echo "Skipping quickstart setup: CI secrets are not available." - exit 0 - fi - - # --- Main Logic --- - local quickstart_dir - quickstart_dir=$(setup_quickstart_repo "$sample") - - local quickstart_project_dir="${quickstart_dir}/${sample}" - - if [[ ! -d "${quickstart_project_dir}" ]]; then - echo "Error: Sample directory not found at '${quickstart_project_dir}'" >&2 - exit 1 - fi - - # Find the .xcodeproj file within the sample directory. - # Fail if there isn't exactly one. - # Enable nullglob to ensure the glob expands to an empty list if no files - # are found. - shopt -s nullglob - local project_files=("${quickstart_project_dir}"/*.xcodeproj) - # Restore default globbing behavior. - shopt -u nullglob - if [[ "${#project_files[@]}" -ne 1 ]]; then - echo "Error: Expected 1 .xcodeproj file in" \ - "'${quickstart_project_dir}', but found ${#project_files[@]}." >&2 - exit 1 - fi - local project_file="${project_files[0]}" - - update_spm_dependency "$release_testing" "$project_file" -} - -# Run the main function with all provided arguments. -main "$@"