diff --git a/Tools/Sources/Commands/CI/CI.swift b/Tools/Sources/Commands/CI/CI.swift index b96102a9e..3c139c6f7 100644 --- a/Tools/Sources/Commands/CI/CI.swift +++ b/Tools/Sources/Commands/CI/CI.swift @@ -1,6 +1,7 @@ import ArgumentParser import Foundation import Subprocess +import Yams struct CI: ParsableCommand { static let configuration = CommandConfiguration(abstract: "CI workflow commands that can be run both locally and in CI environments.", @@ -13,6 +14,19 @@ struct CI: ParsableCommand { static let testOutputDirectory = "test_output" + /// Reads the `MARKETING_VERSION` from `project.yml`. + static func readMarketingVersion() throws -> String { + let projectURL = URL.projectDirectory.appending(component: "project.yml") + let projectString = try String(contentsOf: projectURL) + + guard let projectConfig = try Yams.compose(yaml: projectString), + let version = projectConfig["settings"]?["MARKETING_VERSION"]?.string else { + throw ValidationError("Could not find MARKETING_VERSION in project.yml.") + } + + return version + } + // MARK: - Linting /// Runs SwiftFormat in lint mode against the current directory. diff --git a/Tools/Sources/Commands/CI/ConfigureNightly.swift b/Tools/Sources/Commands/CI/ConfigureNightly.swift index 176a14b2a..f6ae94446 100644 --- a/Tools/Sources/Commands/CI/ConfigureNightly.swift +++ b/Tools/Sources/Commands/CI/ConfigureNightly.swift @@ -20,7 +20,7 @@ struct ConfigureNightly: AsyncParsableCommand { try Zsh.run(command: "swift run pipeline update-foss-secrets") try Zsh.run(command: "xcodegen") - let releaseVersion = try readMarketingVersion() + let releaseVersion = try CI.readMarketingVersion() try await generateAppIconBanner(version: releaseVersion, buildNumber: buildNumber) } @@ -41,19 +41,6 @@ struct ConfigureNightly: AsyncParsableCommand { try updatedYAMLString.write(to: projectURL, atomically: true, encoding: .utf8) } - /// Reads the MARKETING_VERSION from `project.yml`. - private func readMarketingVersion() throws -> String { - let projectURL = URL.projectDirectory.appending(component: "project.yml") - let projectString = try String(contentsOf: projectURL) - - let marketingVersionRegex = /MARKETING_VERSION:\s*([^\s]+)/ - guard let match = projectString.firstMatch(of: marketingVersionRegex) else { - throw ValidationError("Could not find MARKETING_VERSION in project.yml.") - } - - return String(match.1) - } - /// Generates the app icon banner with version and build number. private func generateAppIconBanner(version: String, buildNumber: String) async throws { let bannerText = "\(version) (\(buildNumber))"