From ca03e802b7d53892e3418c08236abaf9d6b3090a Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 17 Oct 2025 12:49:31 -0500 Subject: [PATCH 01/13] Create Run.swift --- scripts/repo/Sources/Tests/Run.swift | 247 +++++++++++++++++++++++++++ 1 file changed, 247 insertions(+) create mode 100644 scripts/repo/Sources/Tests/Run.swift diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift new file mode 100644 index 00000000000..031fe6a4485 --- /dev/null +++ b/scripts/repo/Sources/Tests/Run.swift @@ -0,0 +1,247 @@ +/* + * 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. + */ + +import ArgumentParser +import Foundation +import Logging +import Util + +extension Tests { + struct Run: ParsableCommand { + nonisolated(unsafe) static var configuration = CommandConfiguration( + abstract: "Run the integration tests for a given platform.", + usage: """ + tests run [--overwrite] [--secrets ] [--xcode ] [--platforms ...] [--sdk ] + + tests run --xcode Xcode_16.4.0 --platforms iOS macOS --sdk AI + tests run --xcode "/Applications/Xcode_15.0.0.app" --platforms tvOS --sdk Storage + tests run --overwrite --secrets ./scripts/secrets/AI.json --sdk AI + """, + discussion: """ + If multiple Xcode versions are installed, you must specify an Xcode version manually via the + 'xcode' option. If you run the script without doing so, the script will log an error message + that contains all the Xcode versions installed, telling you to manually specify the 'xcode' option. + + Note that Xcode versions can be specified as either the application name, or a full path. For + example, the following are both valid: + "Xcode_16.4.0" and "/Applications/Xcode_16.4.0.app". + + If your tests have encrypted secret files, you can pass a json file to the script via the + 'secrets' option. The script will automatically decrypt them before running the tests, and + delete them after running the tests. You'll also need to provide the password that the secret + files were encrypted with via the 'secrets_passphrase' environment variable. The json file + should be an array of json elements in the format of: + { encrypted: , destination: } + + If you pass a secret file, but decrypted files already exist at the destination, the script + will NOT overwrite them. The script will also not delete these files either. If you want + the script to overwrite and delete secret files, regardless if they existed before the script + ran, you can pass the 'overwrite' flag. + """, + ) + + @Option( + help: + """ + Xcode version to run tests against. \ + Can be either the application name, or a full path (eg; "Xcode_16.4.0" or "/Applications/Xcode_16.4.0.app"). + By default, the script will look for your local Xcode installation. + """ + ) + var xcode: String = "" + + @Option(parsing: .upToNextOption, help: "Platforms to run rests on.") + var platforms: [Platform] = [.iOS] + + @Option(help: "Path to a json file containing an array of secret files to use, if any.") + var secrets: String? = nil + + @Flag(help: "Overwrite existing decrypted secret files.") + var overwrite: Bool = false + + @Option( + help: """ + The SDK to run integration tests for. + There should be a build target for the SDK that follows the format "Firebase{SDK}Integration" + """) + var sdk: String = "AI" + + static let log: Logger = Logger(label: "Tests::Run") + private var log: Logger { Decrypt.log } + + /// A path to the Xcode to use. + /// + /// Only populated after `validate()` runs. + private var xcodePath: String = "" + + mutating func validate() throws { + if xcode.isEmpty { + try findAndValidateXcodeOnDisk() + } else { + try validateProvidedXcode() + } + } + + /// When the `xcode` option isn't provided, try to find an installation on disk. + mutating func findAndValidateXcodeOnDisk() throws { + let xcodes = try findXcodeVersions() + guard xcodes.count == 1 else { + let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } + log.error( + "Multiple Xcode versions found.", + metadata: ["versions": "\(formattedXcodes)"]) + + throw ValidationError( + "Multiple Xcode installations found. Explicitly pass the 'xcode' option to specify which to use." + ) + } + xcodePath = xcodes[0].path() + log.debug("Found Xcode installation", metadata: ["path": "\(xcodePath)"]) + } + + /// When the `xcode` option is provided, ensure it exists. + /// + /// The `xcode` argument can be either a full path to the application, or just the application name. + mutating func validateProvidedXcode() throws { + if xcode.hasSuffix(".app") { + // it's a full path to the Xcode, just ensure it exists + guard FileManager.default.fileExists(atPath: xcode) else { + throw ValidationError("Xcode application not found at path: \(xcode)") + } + xcodePath = URL(filePath: xcode).path() + } else { + // it's the application name, find an Xcode installation that matches + let xcodes = try findXcodeVersions() + guard + let match = xcodes.first(where: { + $0.path(percentEncoded: false).hasSuffix("\(xcode).app") + }) + else { + let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } + log.error("Invalid Xcode specified.", + metadata: ["versions": "\(formattedXcodes)"]) + throw ValidationError( + "Failed to find an Xcode installation that matches: \(xcode)") + } + xcodePath = match.path() + log.debug("Found matching Xcode", metadata: ["path": "\(xcodePath)"]) + } + } + + mutating func run() throws { + var secretFiles: [SecretFile] = [] + + defer { + for file in secretFiles { + do { + log.debug("Deleting secret file", metadata: ["file": "\(file.destination)"]) + try FileManager.default.removeItem(atPath: file.destination) + } catch { + log.error( + "Failed to delete secret file.", + metadata: [ + "file": "\(file.destination)", + "error": "\(error.localizedDescription)", + ]) + } + } + } + + // decrypt secrets if we need to + if let secrets { + var args = ["--json"] + if overwrite { + args.append("--overwrite") + } + args.append(secrets) + var decrypt = try Decrypt.parse(args) + try decrypt.validate() + + // save the secret files to delete later + secretFiles = decrypt.files + + try decrypt.run() + } + + let buildScript = URL(filePath: "scripts/build.sh", relativeTo: URL.currentDirectory()) + for platform in platforms { + log.info( + "Running integration tests", + metadata: ["sdk": "\(sdk)", "platform": "\(platform)"]) + + let build = Process( + buildScript.path(percentEncoded: false), + env: ["DEVELOPER_DIR": "\(xcodePath)/Contents/Developer"], + inheritEnvironment: true + ) + + let exitCode = try build.runWithSignals([ + "Firebase\(sdk)Integration", "\(platform)" + ]) + guard exitCode == 0 else { + log.error( + "Failed to run integration tests.", + metadata: ["sdk": "\(sdk)", "platform": "\(platform)"]) + throw ExitCode(exitCode) + } + } + } + + private func findXcodeVersions() throws -> [URL] { + let applicationDirs = FileManager.default.urls( + for: .applicationDirectory, in: .allDomainsMask + ).filter { url in + // file manager lists application dirs that CAN exist, so we should check if they actually do exist before trying to get their contents + let exists = FileManager.default.fileExists(atPath: url.path()) + if !exists { + log.debug("Application directory doesn't exists, so we're skipping it.", metadata: ["directory": "\(url.path())"]) + } + return exists + } + + log.debug("Searching application directories for Xcode installations.", metadata: ["directories": "\(applicationDirs)"]) + + let allApplications = try applicationDirs.flatMap { URL in + return try FileManager.default.contentsOfDirectory( + at: URL, includingPropertiesForKeys: nil) + } + + let xcodes = allApplications.filter { file in + let isXcode = file.lastPathComponent.contains(/Xcode.*\.app/) + if !isXcode { + log.debug("Application isn't an Xcode installation, so we're skipping it.", metadata: ["application": "\(file.lastPathComponent)"]) + } + return isXcode + } + guard !xcodes.isEmpty else { + throw ValidationError( + "Failed to find any Xcode versions installed. Please install Xcode.") + } + + log.debug("Found Xcode installations.", metadata: ["installations": "\(xcodes)"]) + return xcodes + } + } +} + +enum Platform: String, Codable, ExpressibleByArgument, CaseIterable { + case iOS + case iPad + case macOS + case tvOS + case watchOS + case visionOS +} From f4b1ef09279f879aa2012fb622cf778c58655ca7 Mon Sep 17 00:00:00 2001 From: Daymon Date: Fri, 17 Oct 2025 12:49:34 -0500 Subject: [PATCH 02/13] Update main.swift --- scripts/repo/Sources/Tests/main.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/repo/Sources/Tests/main.swift b/scripts/repo/Sources/Tests/main.swift index 0abb218e46a..38246ea586b 100755 --- a/scripts/repo/Sources/Tests/main.swift +++ b/scripts/repo/Sources/Tests/main.swift @@ -26,8 +26,8 @@ struct Tests: ParsableCommand { debugging, you can set the "LOG_LEVEL" environment variable to a different minimum level \ (eg; "debug"). """, - subcommands: [Decrypt.self] - // defaultSubcommand: Run.self + subcommands: [Decrypt.self, Run.self], + defaultSubcommand: Run.self ) } From 00e28455d8ef0b6fc6d746ff8ea8c1c52b8f0772 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:23:57 -0500 Subject: [PATCH 03/13] Formatting --- scripts/repo/Sources/Tests/Run.swift | 189 +++++++++++++++------------ 1 file changed, 104 insertions(+), 85 deletions(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 031fe6a4485..8b77b67f57d 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -24,46 +24,46 @@ extension Tests { nonisolated(unsafe) static var configuration = CommandConfiguration( abstract: "Run the integration tests for a given platform.", usage: """ - tests run [--overwrite] [--secrets ] [--xcode ] [--platforms ...] [--sdk ] + tests run [--overwrite] [--secrets ] [--xcode ] [--platforms ...] [] - tests run --xcode Xcode_16.4.0 --platforms iOS macOS --sdk AI - tests run --xcode "/Applications/Xcode_15.0.0.app" --platforms tvOS --sdk Storage - tests run --overwrite --secrets ./scripts/secrets/AI.json --sdk AI - """, + tests run --xcode Xcode_16.4.0 --platforms iOS --platforms macOS AI + tests run --xcode "/Applications/Xcode_15.0.0.app" --platforms tvOS Storage + tests run --overwrite --secrets ./scripts/secrets/AI.json AI + """, discussion: """ - If multiple Xcode versions are installed, you must specify an Xcode version manually via the - 'xcode' option. If you run the script without doing so, the script will log an error message - that contains all the Xcode versions installed, telling you to manually specify the 'xcode' option. - - Note that Xcode versions can be specified as either the application name, or a full path. For - example, the following are both valid: - "Xcode_16.4.0" and "/Applications/Xcode_16.4.0.app". - - If your tests have encrypted secret files, you can pass a json file to the script via the - 'secrets' option. The script will automatically decrypt them before running the tests, and - delete them after running the tests. You'll also need to provide the password that the secret - files were encrypted with via the 'secrets_passphrase' environment variable. The json file - should be an array of json elements in the format of: - { encrypted: , destination: } - - If you pass a secret file, but decrypted files already exist at the destination, the script - will NOT overwrite them. The script will also not delete these files either. If you want - the script to overwrite and delete secret files, regardless if they existed before the script - ran, you can pass the 'overwrite' flag. - """, + If multiple Xcode versions are installed, you must specify an Xcode version manually via the + 'xcode' option. If you run the script without doing so, the script will log an error message + that contains all the Xcode versions installed, telling you to manually specify the 'xcode' option. + + Note that Xcode versions can be specified as either the application name, or a full path. For + example, the following are both valid: + "Xcode_16.4.0" and "/Applications/Xcode_16.4.0.app". + + If your tests have encrypted secret files, you can pass a json file to the script via the + 'secrets' option. The script will automatically decrypt them before running the tests, and + delete them after running the tests. You'll also need to provide the password that the secret + files were encrypted with via the 'secrets_passphrase' environment variable. The json file + should be an array of json elements in the format of: + { encrypted: , destination: } + + If you pass a secret file, but decrypted files already exist at the destination, the script + will NOT overwrite them. The script will also not delete these files either. If you want + the script to overwrite and delete secret files, regardless if they existed before the script + ran, you can pass the 'overwrite' flag. + """, ) @Option( help: - """ - Xcode version to run tests against. \ - Can be either the application name, or a full path (eg; "Xcode_16.4.0" or "/Applications/Xcode_16.4.0.app"). - By default, the script will look for your local Xcode installation. - """ + """ + Xcode version to run tests against. \ + Can be either the application name, or a full path (eg; "Xcode_16.4.0" or "/Applications/Xcode_16.4.0.app"). + By default, the script will look for your local Xcode installation. + """ ) var xcode: String = "" - @Option(parsing: .upToNextOption, help: "Platforms to run rests on.") + @Option(help: "Platforms to run rests on.") var platforms: [Platform] = [.iOS] @Option(help: "Path to a json file containing an array of secret files to use, if any.") @@ -72,18 +72,19 @@ extension Tests { @Flag(help: "Overwrite existing decrypted secret files.") var overwrite: Bool = false - @Option( + @Argument( help: """ - The SDK to run integration tests for. - There should be a build target for the SDK that follows the format "Firebase{SDK}Integration" - """) - var sdk: String = "AI" + The SDK to run integration tests for. + There should be a build target for the SDK that follows the format "Firebase{SDK}Integration" + """ + ) + var sdk: String - static let log: Logger = Logger(label: "Tests::Run") + static let log: Logger = .init(label: "Tests::Run") private var log: Logger { Decrypt.log } /// A path to the Xcode to use. - /// + /// /// Only populated after `validate()` runs. private var xcodePath: String = "" @@ -97,48 +98,51 @@ extension Tests { /// When the `xcode` option isn't provided, try to find an installation on disk. mutating func findAndValidateXcodeOnDisk() throws { - let xcodes = try findXcodeVersions() - guard xcodes.count == 1 else { - let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } - log.error( - "Multiple Xcode versions found.", - metadata: ["versions": "\(formattedXcodes)"]) + let xcodes = try findXcodeVersions() + guard xcodes.count == 1 else { + let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } + log.error( + "Multiple Xcode versions found.", + metadata: ["versions": "\(formattedXcodes)"] + ) - throw ValidationError( - "Multiple Xcode installations found. Explicitly pass the 'xcode' option to specify which to use." - ) - } - xcodePath = xcodes[0].path() - log.debug("Found Xcode installation", metadata: ["path": "\(xcodePath)"]) + throw ValidationError( + "Multiple Xcode installations found. Explicitly pass the 'xcode' option to specify which to use." + ) + } + xcodePath = xcodes[0].path() + log.debug("Found Xcode installation", metadata: ["path": "\(xcodePath)"]) } /// When the `xcode` option is provided, ensure it exists. - /// - /// The `xcode` argument can be either a full path to the application, or just the application name. + /// + /// The `xcode` argument can be either a full path to the application, or just the application + /// name. mutating func validateProvidedXcode() throws { - if xcode.hasSuffix(".app") { - // it's a full path to the Xcode, just ensure it exists - guard FileManager.default.fileExists(atPath: xcode) else { - throw ValidationError("Xcode application not found at path: \(xcode)") - } - xcodePath = URL(filePath: xcode).path() - } else { - // it's the application name, find an Xcode installation that matches - let xcodes = try findXcodeVersions() - guard - let match = xcodes.first(where: { - $0.path(percentEncoded: false).hasSuffix("\(xcode).app") - }) - else { - let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } - log.error("Invalid Xcode specified.", - metadata: ["versions": "\(formattedXcodes)"]) - throw ValidationError( - "Failed to find an Xcode installation that matches: \(xcode)") - } - xcodePath = match.path() - log.debug("Found matching Xcode", metadata: ["path": "\(xcodePath)"]) + if xcode.hasSuffix(".app") { + // it's a full path to the Xcode, just ensure it exists + guard FileManager.default.fileExists(atPath: xcode) else { + throw ValidationError("Xcode application not found at path: \(xcode)") + } + xcodePath = URL(filePath: xcode).path() + } else { + // it's the application name, find an Xcode installation that matches + let xcodes = try findXcodeVersions() + guard + let match = xcodes.first(where: { + $0.path(percentEncoded: false).hasSuffix("\(xcode).app") + }) + else { + let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } + log.error("Invalid Xcode specified.", + metadata: ["versions": "\(formattedXcodes)"]) + throw ValidationError( + "Failed to find an Xcode installation that matches: \(xcode)" + ) } + xcodePath = match.path() + log.debug("Found matching Xcode", metadata: ["path": "\(xcodePath)"]) + } } mutating func run() throws { @@ -155,7 +159,8 @@ extension Tests { metadata: [ "file": "\(file.destination)", "error": "\(error.localizedDescription)", - ]) + ] + ) } } } @@ -180,7 +185,8 @@ extension Tests { for platform in platforms { log.info( "Running integration tests", - metadata: ["sdk": "\(sdk)", "platform": "\(platform)"]) + metadata: ["sdk": "\(sdk)", "platform": "\(platform)"] + ) let build = Process( buildScript.path(percentEncoded: false), @@ -189,12 +195,13 @@ extension Tests { ) let exitCode = try build.runWithSignals([ - "Firebase\(sdk)Integration", "\(platform)" + "Firebase\(sdk)Integration", "\(platform)", ]) guard exitCode == 0 else { log.error( "Failed to run integration tests.", - metadata: ["sdk": "\(sdk)", "platform": "\(platform)"]) + metadata: ["sdk": "\(sdk)", "platform": "\(platform)"] + ) throw ExitCode(exitCode) } } @@ -204,31 +211,43 @@ extension Tests { let applicationDirs = FileManager.default.urls( for: .applicationDirectory, in: .allDomainsMask ).filter { url in - // file manager lists application dirs that CAN exist, so we should check if they actually do exist before trying to get their contents + // file manager lists application dirs that CAN exist, so we should check if they actually + // do exist before trying to get their contents let exists = FileManager.default.fileExists(atPath: url.path()) if !exists { - log.debug("Application directory doesn't exists, so we're skipping it.", metadata: ["directory": "\(url.path())"]) + log.debug( + "Application directory doesn't exists, so we're skipping it.", + metadata: ["directory": "\(url.path())"] + ) } return exists } - log.debug("Searching application directories for Xcode installations.", metadata: ["directories": "\(applicationDirs)"]) + log.debug( + "Searching application directories for Xcode installations.", + metadata: ["directories": "\(applicationDirs)"] + ) let allApplications = try applicationDirs.flatMap { URL in - return try FileManager.default.contentsOfDirectory( - at: URL, includingPropertiesForKeys: nil) + try FileManager.default.contentsOfDirectory( + at: URL, includingPropertiesForKeys: nil + ) } let xcodes = allApplications.filter { file in let isXcode = file.lastPathComponent.contains(/Xcode.*\.app/) if !isXcode { - log.debug("Application isn't an Xcode installation, so we're skipping it.", metadata: ["application": "\(file.lastPathComponent)"]) + log.debug( + "Application isn't an Xcode installation, so we're skipping it.", + metadata: ["application": "\(file.lastPathComponent)"] + ) } return isXcode } guard !xcodes.isEmpty else { throw ValidationError( - "Failed to find any Xcode versions installed. Please install Xcode.") + "Failed to find any Xcode versions installed. Please install Xcode." + ) } log.debug("Found Xcode installations.", metadata: ["installations": "\(xcodes)"]) From fe9541f9c00c60b448a14ce1a1a0d4cb36d23fe8 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:27:24 -0500 Subject: [PATCH 04/13] Add some explanatory comments --- scripts/repo/Sources/Tests/Run.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 8b77b67f57d..e9a38fadd7a 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -149,6 +149,7 @@ extension Tests { var secretFiles: [SecretFile] = [] defer { + // ensure secret files are deleted, regardless of test result for file in secretFiles { do { log.debug("Deleting secret file", metadata: ["file": "\(file.destination)"]) @@ -188,6 +189,7 @@ extension Tests { metadata: ["sdk": "\(sdk)", "platform": "\(platform)"] ) + // instead of using xcode-select (which requires sudo), we can use the env variable `DEVELOPER_DIR` to point to our target xcode let build = Process( buildScript.path(percentEncoded: false), env: ["DEVELOPER_DIR": "\(xcodePath)/Contents/Developer"], From 1b013095e9379372b9f31dfd0c71beefd45b3dba Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:28:27 -0500 Subject: [PATCH 05/13] Move private func up --- scripts/repo/Sources/Tests/Run.swift | 94 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index e9a38fadd7a..676c9fe6a6b 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -145,6 +145,53 @@ extension Tests { } } + private func findXcodeVersions() throws -> [URL] { + let applicationDirs = FileManager.default.urls( + for: .applicationDirectory, in: .allDomainsMask + ).filter { url in + // file manager lists application dirs that CAN exist, so we should check if they actually + // do exist before trying to get their contents + let exists = FileManager.default.fileExists(atPath: url.path()) + if !exists { + log.debug( + "Application directory doesn't exists, so we're skipping it.", + metadata: ["directory": "\(url.path())"] + ) + } + return exists + } + + log.debug( + "Searching application directories for Xcode installations.", + metadata: ["directories": "\(applicationDirs)"] + ) + + let allApplications = try applicationDirs.flatMap { URL in + try FileManager.default.contentsOfDirectory( + at: URL, includingPropertiesForKeys: nil + ) + } + + let xcodes = allApplications.filter { file in + let isXcode = file.lastPathComponent.contains(/Xcode.*\.app/) + if !isXcode { + log.debug( + "Application isn't an Xcode installation, so we're skipping it.", + metadata: ["application": "\(file.lastPathComponent)"] + ) + } + return isXcode + } + guard !xcodes.isEmpty else { + throw ValidationError( + "Failed to find any Xcode versions installed. Please install Xcode." + ) + } + + log.debug("Found Xcode installations.", metadata: ["installations": "\(xcodes)"]) + return xcodes + } + mutating func run() throws { var secretFiles: [SecretFile] = [] @@ -208,53 +255,6 @@ extension Tests { } } } - - private func findXcodeVersions() throws -> [URL] { - let applicationDirs = FileManager.default.urls( - for: .applicationDirectory, in: .allDomainsMask - ).filter { url in - // file manager lists application dirs that CAN exist, so we should check if they actually - // do exist before trying to get their contents - let exists = FileManager.default.fileExists(atPath: url.path()) - if !exists { - log.debug( - "Application directory doesn't exists, so we're skipping it.", - metadata: ["directory": "\(url.path())"] - ) - } - return exists - } - - log.debug( - "Searching application directories for Xcode installations.", - metadata: ["directories": "\(applicationDirs)"] - ) - - let allApplications = try applicationDirs.flatMap { URL in - try FileManager.default.contentsOfDirectory( - at: URL, includingPropertiesForKeys: nil - ) - } - - let xcodes = allApplications.filter { file in - let isXcode = file.lastPathComponent.contains(/Xcode.*\.app/) - if !isXcode { - log.debug( - "Application isn't an Xcode installation, so we're skipping it.", - metadata: ["application": "\(file.lastPathComponent)"] - ) - } - return isXcode - } - guard !xcodes.isEmpty else { - throw ValidationError( - "Failed to find any Xcode versions installed. Please install Xcode." - ) - } - - log.debug("Found Xcode installations.", metadata: ["installations": "\(xcodes)"]) - return xcodes - } } } From 9e10da7ae0759ee4b166b58c22f0a473dfd11af3 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:28:50 -0500 Subject: [PATCH 06/13] Make validators private --- scripts/repo/Sources/Tests/Run.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 676c9fe6a6b..1bfce9986ba 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -97,7 +97,7 @@ extension Tests { } /// When the `xcode` option isn't provided, try to find an installation on disk. - mutating func findAndValidateXcodeOnDisk() throws { + private mutating func findAndValidateXcodeOnDisk() throws { let xcodes = try findXcodeVersions() guard xcodes.count == 1 else { let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } @@ -118,7 +118,7 @@ extension Tests { /// /// The `xcode` argument can be either a full path to the application, or just the application /// name. - mutating func validateProvidedXcode() throws { + private mutating func validateProvidedXcode() throws { if xcode.hasSuffix(".app") { // it's a full path to the Xcode, just ensure it exists guard FileManager.default.fileExists(atPath: xcode) else { From 063b9dc5ef6eac188ea26f95af613a0b5c2a8ec5 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:31:51 -0500 Subject: [PATCH 07/13] formatting --- scripts/repo/Sources/Tests/Run.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 1bfce9986ba..9cabe119ddc 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -236,7 +236,8 @@ extension Tests { metadata: ["sdk": "\(sdk)", "platform": "\(platform)"] ) - // instead of using xcode-select (which requires sudo), we can use the env variable `DEVELOPER_DIR` to point to our target xcode + // instead of using xcode-select (which requires sudo), we can use the env variable + // `DEVELOPER_DIR` to point to our target xcode let build = Process( buildScript.path(percentEncoded: false), env: ["DEVELOPER_DIR": "\(xcodePath)/Contents/Developer"], From 2c4eba375667f1c01463325006f7815413f82146 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:35:31 -0500 Subject: [PATCH 08/13] Update some docs --- scripts/repo/Sources/Tests/Run.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 9cabe119ddc..960554cc916 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -20,9 +20,10 @@ import Logging import Util extension Tests { + /// Command for running the integration tests of a given SDK. struct Run: ParsableCommand { nonisolated(unsafe) static var configuration = CommandConfiguration( - abstract: "Run the integration tests for a given platform.", + abstract: "Run the integration tests for a given SDK.", usage: """ tests run [--overwrite] [--secrets ] [--xcode ] [--platforms ...] [] @@ -259,6 +260,7 @@ extension Tests { } } +/// Apple platforms that tests can be ran under. enum Platform: String, Codable, ExpressibleByArgument, CaseIterable { case iOS case iPad From b5f25bab138d3e82399e6efa773f6d8c8b6b137b Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:39:13 -0500 Subject: [PATCH 09/13] Use script in workflow --- .github/workflows/firebaseai.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/firebaseai.yml b/.github/workflows/firebaseai.yml index d4f2ba1cce1..b3c60471701 100644 --- a/.github/workflows/firebaseai.yml +++ b/.github/workflows/firebaseai.yml @@ -58,19 +58,8 @@ jobs: with: path: .build key: ${{ needs.spm.outputs.cache_key }} - - name: Install Secret GoogleService-Info.plist - run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/FirebaseAI/TestApp-GoogleService-Info.plist.gpg \ - FirebaseAI/Tests/TestApp/Resources/GoogleService-Info.plist "$secrets_passphrase" - - name: Install Secret GoogleService-Info-Spark.plist - run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/FirebaseAI/TestApp-GoogleService-Info-Spark.plist.gpg \ - FirebaseAI/Tests/TestApp/Resources/GoogleService-Info-Spark.plist "$secrets_passphrase" - - name: Install Secret Credentials.swift - run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/FirebaseAI/TestApp-Credentials.swift.gpg \ - FirebaseAI/Tests/TestApp/Tests/Integration/Credentials.swift "$secrets_passphrase" - - name: Xcode - run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer - - name: Run IntegrationTests - run: scripts/build.sh FirebaseAIIntegration ${{ matrix.target }} + - name: Run integration tests + run: scripts/repo.sh tests run --secrets ./scripts/secrets/AI.json --platform ${{ matrix.target }} --xcode ${{ matrix.xcode }} AI - name: Upload xcodebuild logs if: failure() uses: actions/upload-artifact@v4 From e1a5e23df8435fa402c851cb0ffd048b8a970016 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 14:51:52 -0500 Subject: [PATCH 10/13] Fix logger reference --- scripts/repo/Sources/Tests/Run.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 960554cc916..60c477271f4 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -82,7 +82,7 @@ extension Tests { var sdk: String static let log: Logger = .init(label: "Tests::Run") - private var log: Logger { Decrypt.log } + private var log: Logger { Self.log } /// A path to the Xcode to use. /// From 505069d21ce19a1c4ea27a23cc4683335e8022b4 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 15:06:07 -0500 Subject: [PATCH 11/13] Use contains instead of hasSuffix --- scripts/repo/Sources/Tests/Run.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/repo/Sources/Tests/Run.swift b/scripts/repo/Sources/Tests/Run.swift index 60c477271f4..06101b43a2c 100644 --- a/scripts/repo/Sources/Tests/Run.swift +++ b/scripts/repo/Sources/Tests/Run.swift @@ -131,7 +131,7 @@ extension Tests { let xcodes = try findXcodeVersions() guard let match = xcodes.first(where: { - $0.path(percentEncoded: false).hasSuffix("\(xcode).app") + $0.path(percentEncoded: false).contains("\(xcode).app") }) else { let formattedXcodes = xcodes.map { $0.path(percentEncoded: false) } From f502bc66f508c4fef5d9939107a2e086219a9603 Mon Sep 17 00:00:00 2001 From: Daymon Date: Mon, 20 Oct 2025 15:19:30 -0500 Subject: [PATCH 12/13] Fix typo --- .github/workflows/firebaseai.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/firebaseai.yml b/.github/workflows/firebaseai.yml index b3c60471701..3c2ff885ade 100644 --- a/.github/workflows/firebaseai.yml +++ b/.github/workflows/firebaseai.yml @@ -59,7 +59,7 @@ jobs: path: .build key: ${{ needs.spm.outputs.cache_key }} - name: Run integration tests - run: scripts/repo.sh tests run --secrets ./scripts/secrets/AI.json --platform ${{ matrix.target }} --xcode ${{ matrix.xcode }} AI + run: scripts/repo.sh tests run --secrets ./scripts/secrets/AI.json --platforms ${{ matrix.target }} --xcode ${{ matrix.xcode }} AI - name: Upload xcodebuild logs if: failure() uses: actions/upload-artifact@v4 From d2a40319b90b0d05e95661c2765414a0c33fee21 Mon Sep 17 00:00:00 2001 From: Daymon Date: Tue, 21 Oct 2025 12:44:40 -0500 Subject: [PATCH 13/13] Remove unnecessary target/os keys --- .github/workflows/firebaseai.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/firebaseai.yml b/.github/workflows/firebaseai.yml index 3c2ff885ade..0dc5a872678 100644 --- a/.github/workflows/firebaseai.yml +++ b/.github/workflows/firebaseai.yml @@ -38,12 +38,12 @@ jobs: testapp-integration: strategy: matrix: - target: [iOS] - os: [macos-15] include: - os: macos-15 + target: iOS xcode: Xcode_16.4 - os: macos-26 + target: iOS xcode: Xcode_26.0 runs-on: ${{ matrix.os }} needs: spm