-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(infra): Add script to set up SPM-based quickstarts #15295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ncooke3
wants to merge
43
commits into
main
Choose a base branch
from
nc/qsss
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+257
−1
Open
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
c659fcf
feat(infra): Add script to set up SPM-based quickstarts
ncooke3 b4a3998
doc fixes
ncooke3 e289fb8
Update scripts/setup_quickstart_spm.sh
ncooke3 4f3d31b
Update scripts/setup_quickstart_spm.sh
ncooke3 cb0236e
Update scripts/setup_quickstart_spm.sh
ncooke3 43c34e2
Update scripts/setup_quickstart_spm.sh
ncooke3 b507d89
remove unused
ncooke3 2e1431a
refactor constants
ncooke3 dd08b7f
switch to case
ncooke3 e21368c
review
ncooke3 72e8bf2
fix
ncooke3 8d77513
more
ncooke3 44d276e
Update scripts/setup_quickstart_spm.sh
ncooke3 e09127f
Update scripts/setup_quickstart_spm.sh
ncooke3 c2b6a50
work
ncooke3 ecf5c27
fix env
ncooke3 682605b
careful with xcpretty
ncooke3 19c149f
quoting
ncooke3 83d6451
more fixes
ncooke3 dcfc811
review
ncooke3 529558d
more review
ncooke3 0e5c1b1
Update scripts/setup_quickstart_spm.sh
ncooke3 aafe681
Update scripts/setup_quickstart_spm.sh
ncooke3 1fc4bc4
Review
ncooke3 95b032d
Remove xcpretty check
ncooke3 cac3c32
refactor(scripts): Improve robustness of setup_quickstart_spm.sh
ncooke3 2194f28
Update scripts/setup_quickstart_spm.sh
ncooke3 624b41b
Update scripts/setup_quickstart_spm.sh
ncooke3 ab9042b
Update scripts/setup_quickstart_spm.sh
ncooke3 614d19f
Update scripts/setup_quickstart_spm.sh
ncooke3 a8aa103
Update scripts/setup_quickstart_spm.sh
ncooke3 123ea0b
review:
ncooke3 271d1f9
review 1
ncooke3 4eb43b3
more
ncooke3 3467cfc
review
ncooke3 f4b789f
work
ncooke3 7018c23
almost done
ncooke3 cb72289
Update scripts/setup_quickstart_spm.sh
ncooke3 081b78f
Update scripts/setup_quickstart_spm.sh
ncooke3 70c04f1
Update scripts/setup_quickstart_spm.sh
ncooke3 5dc35f6
wrap to 80
ncooke3 bb32269
fix
ncooke3 fae5d77
work
ncooke3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2025 Google LLC | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# | ||
# 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 <<EOF | ||
Usage: $(basename "$0") <sample_name> [testing_mode] | ||
|
||
This script sets up a quickstart sample for SPM integration testing. | ||
|
||
ARGUMENTS: | ||
<sample_name> 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}" | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 directory. | ||
git sparse-checkout set "${sample_name}" | ||
) | ||
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 | ||
git checkout "${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 | \ | ||
grep -E '^CocoaPods-[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | ||
if [[ -z "$latest_tag" ]]; then | ||
echo "Error: Could not find a 'CocoaPods-X.Y.Z' tag." >&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-}" | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 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 | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "Skipping quickstart setup: CI secrets are not available." | ||
exit 0 | ||
fi | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# --- 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 "$@" | ||
ncooke3 marked this conversation as resolved.
Show resolved
Hide resolved
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.