Skip to content

Commit 2594a9a

Browse files
committed
extend existing script
1 parent 254930f commit 2594a9a

File tree

5 files changed

+109
-185
lines changed

5 files changed

+109
-185
lines changed

scripts/.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"configurations": [
3+
{
4+
"type": "swift",
5+
"request": "launch",
6+
"args": [],
7+
"cwd": "${workspaceFolder:scripts}",
8+
"name": "Debug SPMLocalize",
9+
"program": "${workspaceFolder:scripts}/.build/debug/SPMLocalize",
10+
"preLaunchTask": "swift: Build Debug SPMLocalize"
11+
},
12+
{
13+
"type": "swift",
14+
"request": "launch",
15+
"args": [],
16+
"cwd": "${workspaceFolder:scripts}",
17+
"name": "Release SPMLocalize",
18+
"program": "${workspaceFolder:scripts}/.build/release/SPMLocalize",
19+
"preLaunchTask": "swift: Build Release SPMLocalize"
20+
}
21+
]
22+
}

scripts/quickstart_spm_xcodeproj.sh

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,94 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

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

18-
# Modify a .xcodeproj to use a specific branch.
19-
20-
set -xeuo pipefail
21-
22-
SAMPLE=$1
23-
SAMPLE_DIR=$(echo "$SAMPLE" | perl -ne 'print lc')
24-
XCODEPROJ=${SAMPLE_DIR}/${SAMPLE}Example.xcodeproj/project.pbxproj
25-
26-
# Regex matches SemVer `firebase-ios-sdk` dependency in project.pbxproj:
27-
# {
28-
# isa = XCRemoteSwiftPackageReference;
29-
# repositoryURL = "https://github.com/firebase/firebase-ios-sdk.git";
30-
# requirement = {
31-
# kind = upToNextMajorVersion;
32-
# minimumVersion = xx.yy.zz;
33-
# };
34-
# };
35-
REQUIREMENT_REGEX='({'\
36-
'\s*isa = XCRemoteSwiftPackageReference;'\
37-
'\s*repositoryURL = "https://github\.com/firebase/firebase-ios-sdk\.git";'\
38-
'\s*requirement = {\s*)kind = upToNextMajorVersion;'\
39-
'\s*minimumVersion = \d+\.\d+\.\d+;'\
40-
'(\s*};'\
41-
'\s*};)'
42-
43-
# Replaces the minimumVersion requirement with a branch requirement.
44-
REPLACEMENT_REGEX="\1branch = $BRANCH_NAME;\n\t\t\t\tkind = branch;\2"
45-
46-
# Performs the replacement using Perl.
47-
#
48-
# -0777 Enables reading all input in one go (slurp), rather than line-by-line.
49-
# -p Causes Perl to loop through the input line by line.
50-
# -i Edits the file in place.
51-
# -e Provides the expression to execute.
52-
perl -0777 -i -pe "s#$REQUIREMENT_REGEX#$REPLACEMENT_REGEX#g" "$XCODEPROJ" || {
53-
echo "Failed to update quickstart's Xcode project to the branch: $BRANCH_NAME"
20+
set -euo pipefail
21+
22+
# --- Helper functions ---
23+
usage() {
24+
echo "Usage: $0 <path_to.xcodeproj> [--version <version> | --revision <revision> | --prerelease]"
25+
echo "Example: $0 path/to/MyProject.xcodeproj --version 10.24.0"
26+
exit 1
27+
}
28+
29+
# --- Argument parsing ---
30+
if [[ $# -lt 2 ]]; then
31+
usage
32+
fi
33+
34+
XCODEPROJ_PATH="$1"
35+
shift
36+
MODE="$1"
37+
shift
38+
39+
# Validate Xcode project path
40+
if [[ ! -d "$XCODEPROJ_PATH" || ! "$XCODEPROJ_PATH" == *.xcodeproj ]]; then
41+
echo "Error: Invalid Xcode project path provided: $XCODEPROJ_PATH"
42+
exit 1
43+
fi
44+
PBXPROJ_PATH="${XCODEPROJ_PATH}/project.pbxproj"
45+
if [[ ! -f "$PBXPROJ_PATH" ]]; then
46+
echo "Error: project.pbxproj not found at ${PBXPROJ_PATH}"
47+
exit 1
48+
fi
49+
50+
case "$MODE" in
51+
--version)
52+
if [[ $# -lt 1 ]]; then usage; fi
53+
VERSION="$1"
54+
# Release testing: Point to CocoaPods-{VERSION} tag (as a branch)
55+
export REPLACEMENT_VALUE
56+
REPLACEMENT_VALUE=$(printf '{\n\t\t\t\tkind = branch;\n\t\t\t\tbranch = "%s";\n\t\t\t}' "$VERSION")
57+
;;
58+
--prerelease)
59+
# Prerelease testing: Point to the tip of the main branch
60+
COMMIT_HASH=$(git ls-remote https://github.com/firebase/firebase-ios-sdk.git main | cut -f1)
61+
if [[ -z "$COMMIT_HASH" ]]; then
62+
echo "Error: Failed to get remote revision for main branch."
63+
exit 1
64+
fi
65+
export REPLACEMENT_VALUE
66+
REPLACEMENT_VALUE=$(printf '{\n\t\t\t\tkind = revision;\n\t\t\t\trevision = "%s";\n\t\t\t}' "$COMMIT_HASH")
67+
;;
68+
--revision)
69+
if [[ $# -lt 1 ]]; then usage; fi
70+
REVISION="$1"
71+
# PR testing: Point to the specific commit hash of the current branch
72+
export REPLACEMENT_VALUE
73+
REPLACEMENT_VALUE=$(printf '{\n\t\t\t\tkind = revision;\n\t\t\t\trevision = "%s";\n\t\t\t}' "$REVISION")
74+
;;
75+
*)
76+
usage
77+
;;
78+
esac
79+
80+
# Read the original content to check for changes later.
81+
ORIGINAL_CONTENT=$(<"$PBXPROJ_PATH")
82+
83+
# Use perl to perform the replacement.
84+
# -0777: Slurp the whole file into one string.
85+
# -i: Edit in-place.
86+
# -p: Loop over the input.
87+
# -e: Execute the script.
88+
# The `e` flag in `s/.../.../ge` evaluates the replacement as a Perl expression.
89+
# This allows us to use an environment variable for the replacement string,
90+
# avoiding quoting issues with shell variables.
91+
perl -0777 -i -pe 's#(repositoryURL = "https://github.com/firebase/firebase-ios-sdk\.git";\s*requirement = )\{[^\}]+\};#$1 . $ENV{"REPLACEMENT_VALUE"} . ";"#ge' "$PBXPROJ_PATH" || {
92+
echo "Failed to update the Xcode project's SPM dependency."
5493
exit 1
5594
}
5695

96+
# Verify that the file was changed.
97+
UPDATED_CONTENT=$(<"$PBXPROJ_PATH")
98+
if [[ "$ORIGINAL_CONTENT" == "$UPDATED_CONTENT" ]]; then
99+
echo "Failed to find and replace the firebase-ios-sdk dependency. Check the regex pattern and project file structure."
100+
exit 1
101+
}
102+
103+
echo "Successfully updated SPM dependency in $PBXPROJ_PATH"
104+
57105
# Point SPM CI to the tip of `main` of
58106
# https://github.com/google/GoogleAppMeasurement so that the release process
59107
# can defer publishing the `GoogleAppMeasurement` tag until after testing.

scripts/setup_quickstart_spm.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ if [[ -n "${QUICKSTART_REPO:-}" ]] || check_secrets || [[ ${SAMPLE} == "installa
8686
fi
8787
VERSION=$(echo "$LATEST_TAG" | sed 's/CocoaPods-//')
8888
echo "Setting SPM dependency to latest version: ${VERSION}"
89-
swift run --package-path "$scripts_dir/spm-localizer" SPMLocalize "$ABSOLUTE_PROJECT_FILE" --version "$VERSION"
89+
"$scripts_dir/quickstart_spm_xcodeproj.sh" "$ABSOLUTE_PROJECT_FILE" --version "$VERSION"
9090

9191
elif [ "$RELEASE_TESTING" == "prerelease_testing" ]; then
9292
# For prerelease testing, point to the tip of the main branch.
9393
echo "Setting SPM dependency to the tip of the main branch."
94-
swift run --package-path "$scripts_dir/spm-localizer" SPMLocalize "$ABSOLUTE_PROJECT_FILE" --prerelease
94+
"$scripts_dir/quickstart_spm_xcodeproj.sh" "$ABSOLUTE_PROJECT_FILE" --prerelease
9595

9696
else
9797
# For PR testing, point to the current commit.
9898
CURRENT_REVISION=$(git rev-parse HEAD)
9999
echo "Setting SPM dependency to current revision: ${CURRENT_REVISION}"
100-
swift run --package-path "$scripts_dir/spm-localizer" SPMLocalize "$ABSOLUTE_PROJECT_FILE" --revision "$CURRENT_REVISION"
100+
"$scripts_dir/quickstart_spm_xcodeproj.sh" "$ABSOLUTE_PROJECT_FILE" --revision "$CURRENT_REVISION"
101101
fi
102102

103103
else

scripts/spm-localizer/Package.swift

Lines changed: 0 additions & 34 deletions
This file was deleted.

scripts/spm-localizer/spm_localize_xcode_project.swift

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)