Replace the readMarketingVersion method with a cleaner Yams based one and extract it into the shared tools
This commit is contained in:
committed by
Stefan Ceriu
parent
44b9b8bb71
commit
3dfb33d6e9
@@ -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.
|
||||
|
||||
@@ -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))"
|
||||
|
||||
Reference in New Issue
Block a user