From f2a2374c4ff29a046bfbbde143003e3cbc23427d Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Tue, 24 Dec 2024 09:02:38 -0500 Subject: [PATCH] feat: Updates configuration, uses json for configuration files and drops toml support. --- ...version.toml => .bump-version.example.toml | 0 .bump-version.json | 18 +- Package.resolved | 11 +- Package.swift | 4 +- .../Internal/ConfigurationExtensions.swift | 4 +- .../Internal/FileClient+semVar.swift | 1 - Sources/ConfigurationClient/Coders.swift | 7 +- .../ConfigurationClient/Configuration.swift | 251 ++++-------------- .../ConfigurationClient.swift | 59 ++-- .../ConfigurationFile.swift | 76 ------ .../cli-version/ConfigurationExtensions.swift | 4 +- Sources/cli-version/GlobalOptions.swift | 42 +-- Tests/CliVersionTests/CliClientTests.swift | 6 +- .../ConfigurationClientTests.swift | 39 +-- 14 files changed, 127 insertions(+), 395 deletions(-) rename .bump-version.toml => .bump-version.example.toml (100%) delete mode 100644 Sources/ConfigurationClient/ConfigurationFile.swift diff --git a/.bump-version.toml b/.bump-version.example.toml similarity index 100% rename from .bump-version.toml rename to .bump-version.example.toml diff --git a/.bump-version.json b/.bump-version.json index 5da2325..3de4041 100644 --- a/.bump-version.json +++ b/.bump-version.json @@ -1,19 +1,7 @@ { "strategy" : { - "semvar" : { - "preRelease" : { - "strategy" : { - "command" : { - "arguments" : [ - "git", - "describe", - "--tags" - ] - } - } - }, - "requireExistingFile" : true, - "requireExistingSemVar" : true + "branch" : { + "includeCommitSha": true } }, "target" : { @@ -22,4 +10,4 @@ "name" : "cli-version" } } -} \ No newline at end of file +} diff --git a/Package.resolved b/Package.resolved index b285ab7..79e9970 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "a6f314a56cd0c1a50e5cace4aacf75ecda58c4cc00e5e13bf7ec110289f943bf", + "originHash" : "077fe473b2dff48184d79b6897170a2c87f00a465e6c079889de37e6470001fb", "pins" : [ { "identity" : "combine-schedulers", @@ -118,15 +118,6 @@ "version" : "600.0.1" } }, - { - "identity" : "tomlkit", - "kind" : "remoteSourceControl", - "location" : "https://github.com/LebJe/TOMLKit.git", - "state" : { - "revision" : "ec6198d37d495efc6acd4dffbd262cdca7ff9b3f", - "version" : "0.6.0" - } - }, { "identity" : "xctest-dynamic-overlay", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 114d62a..8b0166a 100644 --- a/Package.swift +++ b/Package.swift @@ -19,7 +19,6 @@ let package = Package( .package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"), .package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.0.0"), .package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"), - .package(url: "https://github.com/LebJe/TOMLKit.git", from: "0.5.0"), .package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.3.3") ], targets: [ @@ -50,8 +49,7 @@ let package = Package( "FileClient", .product(name: "CustomDump", package: "swift-custom-dump"), .product(name: "Dependencies", package: "swift-dependencies"), - .product(name: "DependenciesMacros", package: "swift-dependencies"), - .product(name: "TOMLKit", package: "TOMLKit") + .product(name: "DependenciesMacros", package: "swift-dependencies") ] ), .testTarget( diff --git a/Sources/CliClient/Internal/ConfigurationExtensions.swift b/Sources/CliClient/Internal/ConfigurationExtensions.swift index a13fb88..c20f842 100644 --- a/Sources/CliClient/Internal/ConfigurationExtensions.swift +++ b/Sources/CliClient/Internal/ConfigurationExtensions.swift @@ -68,14 +68,14 @@ extension GitClient { } } -extension Configuration.PreReleaseStrategy { +extension Configuration.PreRelease { func preReleaseString(gitDirectory: String?) async throws -> String { @Dependency(\.gitClient) var gitClient let preReleaseString: String - if let branch { + if let branch = strategy?.branch { preReleaseString = try await gitClient.version(branch: branch, gitDirectory: gitDirectory) } else { preReleaseString = try await gitClient.version(.init( diff --git a/Sources/CliClient/Internal/FileClient+semVar.swift b/Sources/CliClient/Internal/FileClient+semVar.swift index dd6e384..afc1b5a 100644 --- a/Sources/CliClient/Internal/FileClient+semVar.swift +++ b/Sources/CliClient/Internal/FileClient+semVar.swift @@ -46,7 +46,6 @@ public extension FileClient { let (string, usesOptionalType) = try await getVersionString(fileUrl: file, gitDirectory: gitDirectory) let semvar = SemVar(string: string) logger.debug("Semvar: \(String(describing: semvar))") - return (semvar, usesOptionalType) } diff --git a/Sources/ConfigurationClient/Coders.swift b/Sources/ConfigurationClient/Coders.swift index 52f9ba6..1e68993 100644 --- a/Sources/ConfigurationClient/Coders.swift +++ b/Sources/ConfigurationClient/Coders.swift @@ -1,7 +1,6 @@ import Dependencies import DependenciesMacros import Foundation -import TOMLKit public extension DependencyValues { var coders: Coders { @@ -14,17 +13,13 @@ public extension DependencyValues { public struct Coders: Sendable { public var jsonDecoder: @Sendable () -> JSONDecoder = { .init() } public var jsonEncoder: @Sendable () -> JSONEncoder = { .init() } - public var tomlDecoder: @Sendable () -> TOMLDecoder = { .init() } - public var tomlEncoder: @Sendable () -> TOMLEncoder = { .init() } } extension Coders: DependencyKey { public static var testValue: Coders { .init( jsonDecoder: { .init() }, - jsonEncoder: { defaultJsonEncoder }, - tomlDecoder: { .init() }, - tomlEncoder: { .init() } + jsonEncoder: { defaultJsonEncoder } ) } diff --git a/Sources/ConfigurationClient/Configuration.swift b/Sources/ConfigurationClient/Configuration.swift index b826600..69ec78a 100644 --- a/Sources/ConfigurationClient/Configuration.swift +++ b/Sources/ConfigurationClient/Configuration.swift @@ -1,8 +1,5 @@ import CustomDump import Foundation -import TOMLKit - -// TODO: Just use json for configuration ?? /// Represents configuration that can be set via a file, generally in the root of the /// project directory. @@ -18,7 +15,7 @@ public struct Configuration: Codable, Equatable, Sendable { public init( target: Target? = nil, - strategy: VersionStrategy? = .init(semvar: .init()) + strategy: VersionStrategy? = .semvar(.init()) ) { self.target = target self.strategy = strategy @@ -27,39 +24,26 @@ public struct Configuration: Codable, Equatable, Sendable { public static var mock: Self { .init( target: .init(module: .init("cli-version")), - strategy: .init() + strategy: .semvar(.init()) ) } public static var customPreRelease: Self { .init( target: .init(module: .init("cli-version")), - strategy: .init(semvar: .init( - preRelease: .customBranchPrefix("rc") + strategy: .semvar(.init( + preRelease: .init(prefix: "rc", strategy: .branch()) )) ) } } -public struct Configuration2: Codable, Equatable, Sendable { - public let target: Configuration.Target? - public let strategy: Configuration.VersionStrategy2? - - public static let mock = Self( - target: .init(module: .init("cli-version")), - strategy: .semvar(value: .init(preRelease: .init( - strategy: .branch() - ))) - // strategy: .branch() - ) -} - public extension Configuration { /// Represents a branch version or pre-release strategy. /// - /// This derives the version from the branch name and short version - /// of the commit sha if configured. + /// This derives the version or pre-release suffix from the branch name and + /// optionally the short version of the commit sha. struct Branch: Codable, Equatable, Sendable { /// Include the commit sha in the output for this strategy. @@ -74,14 +58,19 @@ public extension Configuration { } } - struct PreRelease2: Codable, Equatable, Sendable { + /// Represents version strategy for pre-release. + /// + /// This appends a suffix to the version that get's generated from the version strategy. + /// For example: `1.0.0-rc-1` + /// + struct PreRelease: Codable, Equatable, Sendable { public let prefix: String? - public let strategy: Strategy + public let strategy: Strategy? public init( prefix: String? = nil, - strategy: Strategy + strategy: Strategy? = nil ) { self.prefix = prefix self.strategy = strategy @@ -91,99 +80,12 @@ public extension Configuration { case branch(includeCommitSha: Bool = true) case command(arguments: [String]) case gitTag - } - } - /// Represents version strategy for pre-release. - /// - /// This appends a suffix to the version that get's generated from the version strategy. - /// For example: `1.0.0-rc-1` - /// - struct PreReleaseStrategy: Codable, Equatable, Sendable, CustomDumpReflectable { - - /// Use branch and commit sha as pre-release suffix. - public let branch: Branch? - - /// Use a custom prefix string. - public let prefix: String? - - /// An identifier for the type of pre-release. - public let style: StyleId - - /// Whether we use `git describe --tags` for part of the suffix, this is only used - /// if we have a custom style. - public let usesGitTag: Bool? - - init( - style: StyleId, - branch: Branch? = nil, - prefix: String? = nil, - usesGitTag: Bool = false - ) { - self.branch = branch - self.prefix = prefix - self.style = style - self.usesGitTag = usesGitTag - } - - public var customDumpMirror: Mirror { - guard let branch else { - return .init( - self, - children: [ - "style": style, - "prefix": prefix as Any, - "usesGitTag": style == .gitTag ? true : (usesGitTag ?? false) - ], - displayStyle: .struct - ) - // return .init(reflecting: self) + public var branch: Branch? { + guard case let .branch(includeCommitSha) = self + else { return nil } + return .init(includeCommitSha: includeCommitSha) } - return .init( - self, - children: [ - "style": style, - "branch": branch, - "prefix": prefix as Any - ], - displayStyle: .struct - ) - } - - /// Represents a pre-release strategy that is derived from calling - /// `git describe --tags`. - public static let gitTag = Self(style: StyleId.gitTag) - - /// Represents a pre-release strategy that is derived from the branch and commit sha. - public static func branch(_ branch: Branch = .init()) -> Self { - .init(style: .branch, branch: branch) - } - - /// Represents a custom strategy that uses the given value, not deriving any other - /// data. - public static func custom(_ prefix: String) -> Self { - .init(style: .custom, prefix: prefix) - } - - /// Represents a custom strategy that uses a prefix along with the branch and - /// commit sha. - public static func customBranchPrefix( - _ prefix: String, - branch: Branch = .init() - ) -> Self { - .init(style: .custom, branch: branch, prefix: prefix) - } - - /// Represents a custom strategy that uses a prefix along with the output from - /// calling `git describe --tags`. - public static func customGitTagPrefix(_ prefix: String) -> Self { - .init(style: StyleId.custom, prefix: prefix, usesGitTag: true) - } - - public enum StyleId: String, Codable, Sendable { - case branch - case custom - case gitTag } } @@ -194,7 +96,7 @@ public extension Configuration { struct SemVar: Codable, Equatable, Sendable { /// Optional pre-releas suffix strategy. - public let preRelease: PreReleaseStrategy? + public let preRelease: PreRelease? /// Fail if an existing version file does not exist in the target. public let requireExistingFile: Bool @@ -203,30 +105,7 @@ public extension Configuration { public let requireExistingSemVar: Bool public init( - preRelease: PreReleaseStrategy? = nil, - requireExistingFile: Bool = true, - requireExistingSemVar: Bool = true - ) { - self.preRelease = preRelease - self.requireExistingFile = requireExistingFile - self.requireExistingSemVar = requireExistingSemVar - } - - } - - struct SemVar2: Codable, Equatable, Sendable { - - /// Optional pre-releas suffix strategy. - public let preRelease: PreRelease2? - - /// Fail if an existing version file does not exist in the target. - public let requireExistingFile: Bool - - /// Fail if an existing semvar is not parsed from the file or version generation strategy. - public let requireExistingSemVar: Bool - - public init( - preRelease: PreRelease2? = nil, + preRelease: PreRelease? = nil, requireExistingFile: Bool = true, requireExistingSemVar: Bool = true ) { @@ -313,75 +192,57 @@ public extension Configuration { } } - enum VersionStrategy2: Codable, Equatable, Sendable { + /// Strategy used to generate a version. + /// + /// Typically a `SemVar` strategy or `Branch`. + /// + /// + enum VersionStrategy: Codable, Equatable, Sendable, CustomDumpReflectable { case branch(includeCommitSha: Bool = true) + case semvar( - preRelease: PreRelease2? = nil, + preRelease: PreRelease? = nil, requireExistingFile: Bool? = nil, requireExistingSemVar: Bool? = nil ) - static func semvar(value: SemVar2) -> Self { + public var branch: Branch? { + guard case let .branch(includeCommitSha) = self + else { return nil } + + return .init(includeCommitSha: includeCommitSha) + } + + public var semvar: SemVar? { + guard case let .semvar(preRelease, requireExistingFile, requireExistingSemVar) = self + else { return nil } + return .init( + preRelease: preRelease, + requireExistingFile: requireExistingFile ?? false, + requireExistingSemVar: requireExistingSemVar ?? false + ) + } + + public static func branch(_ branch: Branch) -> Self { + .branch(includeCommitSha: branch.includeCommitSha) + } + + public static func semvar(_ value: SemVar) -> Self { .semvar( preRelease: value.preRelease, requireExistingFile: value.requireExistingFile, requireExistingSemVar: value.requireExistingSemVar ) } - } - - /// Strategy used to generate a version. - /// - /// Typically a `SemVar` strategy or `Branch`. - /// - /// - struct VersionStrategy: Codable, Equatable, Sendable, CustomDumpReflectable { - - /// Set if we're using the branch and commit sha to derive the version. - public let branch: Branch? - - /// Set if we're using semvar to derive the version. - public let semvar: SemVar? - - /// Create a new version strategy that uses branch and commit sha to derive the version. - /// - /// - Parameters: - /// - branch: The branch strategy options. - public init(branch: Branch) { - self.branch = branch - self.semvar = nil - } - - /// Create a new version strategy that uses semvar to derive the version. - /// - /// - Parameters: - /// - semvar: The semvar strategy options. - public init(semvar: SemVar = .init()) { - self.branch = nil - self.semvar = semvar - } public var customDumpMirror: Mirror { - if let branch { - return .init( - self, - children: [ - "branch": branch - ], - displayStyle: .struct - ) - } else if let semvar { - return .init( - self, - children: [ - "semvar": semvar - ], - displayStyle: .struct - ) - } else { - return .init(reflecting: self) + switch self { + case .branch: + return .init(self, children: ["branch": branch!], displayStyle: .struct) + case .semvar: + return .init(self, children: ["semvar": semvar!], displayStyle: .struct) } } - } + } diff --git a/Sources/ConfigurationClient/ConfigurationClient.swift b/Sources/ConfigurationClient/ConfigurationClient.swift index 1a783bc..3e44d69 100644 --- a/Sources/ConfigurationClient/ConfigurationClient.swift +++ b/Sources/ConfigurationClient/ConfigurationClient.swift @@ -17,20 +17,20 @@ public extension DependencyValues { public struct ConfigurationClient: Sendable { /// Find a configuration file in the given directory or in current working directory. - public var find: @Sendable (URL?) async throws -> ConfigurationFile? + public var find: @Sendable (URL?) async throws -> URL? /// Load a configuration file. - public var load: @Sendable (ConfigurationFile) async throws -> Configuration + public var load: @Sendable (URL) async throws -> Configuration /// Write a configuration file. - public var write: @Sendable (Configuration, ConfigurationFile) async throws -> Void + public var write: @Sendable (Configuration, URL) async throws -> Void /// Find a configuration file and load it if found. public func findAndLoad(_ url: URL? = nil) async throws -> Configuration { - guard let url = try await find(url) else { + guard let url = try? await find(url) else { throw ConfigurationClientError.configurationNotFound } - return try await load(url) + return (try? await load(url)) ?? .mock } } @@ -40,49 +40,48 @@ extension ConfigurationClient: DependencyKey { public static var liveValue: ConfigurationClient { .init( find: { try await findConfiguration($0) }, - load: { try await $0.load() ?? .mock }, - write: { try await $1.write($0) } + load: { try await loadConfiguration($0) }, + write: { try await writeConfiguration($0, to: $1) } ) } } -private func findConfiguration(_ url: URL?) async throws -> ConfigurationFile? { +private func findConfiguration(_ url: URL?) async throws -> URL? { @Dependency(\.fileClient) var fileClient + let defaultFileName = ConfigurationClient.Constants.defaultFileNameWithoutExtension + var url: URL! = url if url == nil { url = try await URL(filePath: fileClient.currentDirectory()) } - // Check if url is a valid configuration url. - var configurationFile = ConfigurationFile(url: url) - if let configurationFile, fileClient.fileExists(configurationFile.url) { - return configurationFile + if try await fileClient.isDirectory(url.cleanFilePath) { + url = url.appending(path: "\(defaultFileName).json") } - guard try await fileClient.isDirectory(url.cleanFilePath) else { - throw ConfigurationClientError.invalidConfigurationDirectory(path: url.cleanFilePath) + if fileClient.fileExists(url) { + return url } - - // Check for toml file. - let tomlUrl = url.appending(path: "\(ConfigurationClient.Constants.defaultFileNameWithoutExtension).toml") - configurationFile = ConfigurationFile(url: tomlUrl) - if let configurationFile, fileClient.fileExists(configurationFile.url) { - return configurationFile - } - - // Check for json file. - let jsonUrl = url.appending(path: "\(ConfigurationClient.Constants.defaultFileNameWithoutExtension).json") - configurationFile = ConfigurationFile(url: jsonUrl) - if let configurationFile, fileClient.fileExists(configurationFile.url) { - return configurationFile - } - - // Couldn't find valid configuration file. return nil } +private func loadConfiguration(_ url: URL) async throws -> Configuration { + @Dependency(\.coders.jsonDecoder) var jsonDecoder + @Dependency(\.fileClient) var fileClient + + let string = try await fileClient.read(url.cleanFilePath) + return try jsonDecoder().decode(Configuration.self, from: Data(string.utf8)) +} + enum ConfigurationClientError: Error { case configurationNotFound case invalidConfigurationDirectory(path: String) } + +private func writeConfiguration(_ configuration: Configuration, to url: URL) async throws { + @Dependency(\.fileClient) var fileClient + @Dependency(\.coders.jsonEncoder) var jsonEncoder + let data = try jsonEncoder().encode(configuration) + try await fileClient.write(data, url) +} diff --git a/Sources/ConfigurationClient/ConfigurationFile.swift b/Sources/ConfigurationClient/ConfigurationFile.swift deleted file mode 100644 index 5a41820..0000000 --- a/Sources/ConfigurationClient/ConfigurationFile.swift +++ /dev/null @@ -1,76 +0,0 @@ -import Dependencies -import FileClient -import Foundation - -/// Represents a configuration file type and location. -public enum ConfigurationFile: Equatable, Sendable { - - /// A json configuration file. - case json(URL) - - /// A toml configuration file. - case toml(URL) - - /// Default configuration file, which is a toml file - /// with the name of '.bump-version.toml' - public static var `default`: Self { - .toml(URL( - filePath: "\(ConfigurationClient.Constants.defaultFileNameWithoutExtension).toml" - )) - } - - /// Create a new file location from the given url. - /// - /// - Parameters: - /// - url: The url for the file. - public init?(url: URL) { - if url.pathExtension == "toml" { - self = .toml(url) - } else if url.pathExtension == "json" { - self = .json(url) - } else { - return nil - } - } - - /// The url of the file. - public var url: URL { - switch self { - case let .json(url): return url - case let .toml(url): return url - } - } -} - -extension ConfigurationFile { - - func load() async throws -> Configuration? { - @Dependency(\.coders) var coders - @Dependency(\.fileClient) var fileClient - - switch self { - case .json: - let data = try await Data(fileClient.read(url.cleanFilePath).utf8) - return try? coders.jsonDecoder().decode(Configuration.self, from: data) - case .toml: - let string = try await fileClient.read(url.cleanFilePath) - return try? coders.tomlDecoder().decode(Configuration.self, from: string) - } - } - - func write(_ configuration: Configuration) async throws { - @Dependency(\.coders) var coders - @Dependency(\.fileClient) var fileClient - - let data: Data - - switch self { - case .json: - data = try coders.jsonEncoder().encode(configuration) - case .toml: - data = try Data(coders.tomlEncoder().encode(configuration).utf8) - } - - try await fileClient.write(data, url) - } -} diff --git a/Sources/cli-version/ConfigurationExtensions.swift b/Sources/cli-version/ConfigurationExtensions.swift index 0b0f279..e01e6ed 100644 --- a/Sources/cli-version/ConfigurationExtensions.swift +++ b/Sources/cli-version/ConfigurationExtensions.swift @@ -40,9 +40,9 @@ extension Configuration.VersionStrategy { func merging(_ other: Self?) -> Self { guard let branch else { guard let semvar else { return self } - return .init(semvar: semvar.merging(other?.semvar)) + return .semvar(semvar.merging(other?.semvar)) } - return .init(branch: branch.merging(other?.branch)) + return .branch(branch.merging(other?.branch)) } } diff --git a/Sources/cli-version/GlobalOptions.swift b/Sources/cli-version/GlobalOptions.swift index 2c01f5f..f39c942 100644 --- a/Sources/cli-version/GlobalOptions.swift +++ b/Sources/cli-version/GlobalOptions.swift @@ -111,7 +111,7 @@ typealias GlobalBranchOptions = GlobalOptions extension GlobalSemVarOptions { func shared() async throws -> CliClient.SharedOptions { try await withConfiguration(path: configurationFile) { configuration in - try shared(configuration.mergingStrategy(.init(semvar: child.configSemVarOptions()))) + try shared(configuration.mergingStrategy(.semvar(child.configSemVarOptions()))) } } } @@ -119,7 +119,7 @@ extension GlobalSemVarOptions { extension GlobalBranchOptions { func shared() async throws -> CliClient.SharedOptions { try await withConfiguration(path: configurationFile) { configuration in - try shared(configuration.mergingStrategy(.init(branch: .init()))) + try shared(configuration.mergingStrategy(.branch())) } } } @@ -197,24 +197,26 @@ private extension TargetOptions { extension PreReleaseOptions { - func configPreReleaseStrategy() throws -> Configuration.PreReleaseStrategy? { - guard let custom else { - if useBranchAsPreRelease { - return .branch() - } else if useTagAsPreRelease { - return .gitTag - } else { - return nil - } - } - - if useBranchAsPreRelease { - return .customBranchPrefix(custom) - } else if useTagAsPreRelease { - return .customGitTagPrefix(custom) - } else { - return .custom(custom) - } + // FIX: + func configPreReleaseStrategy() throws -> Configuration.PreRelease? { + return nil + // guard let custom else { + // if useBranchAsPreRelease { + // return .branch() + // } else if useTagAsPreRelease { + // return .gitTag + // } else { + // return nil + // } + // } + // + // if useBranchAsPreRelease { + // return .customBranchPrefix(custom) + // } else if useTagAsPreRelease { + // return .customGitTagPrefix(custom) + // } else { + // return .custom(custom) + // } } } diff --git a/Tests/CliVersionTests/CliClientTests.swift b/Tests/CliVersionTests/CliClientTests.swift index 1b34210..d052651 100644 --- a/Tests/CliVersionTests/CliClientTests.swift +++ b/Tests/CliVersionTests/CliClientTests.swift @@ -21,7 +21,7 @@ struct CliClientTests { @Dependency(\.cliClient) var client let output = try await client.build(.testOptions( target: target, - versionStrategy: .init(semvar: .init(requireExistingFile: false)) + versionStrategy: .semvar(requireExistingFile: false) )) #expect(output == "/baz/Sources/bar/Version.swift") } @@ -66,7 +66,7 @@ struct CliClientTests { @Dependency(\.cliClient) var client let output = try await client.build(.testOptions( target: target, - versionStrategy: .init(semvar: .init(requireExistingFile: false)) + versionStrategy: .semvar(requireExistingFile: false) )) #expect(output == "/baz/Sources/bar/Version.swift") } @@ -131,7 +131,7 @@ extension CliClient.SharedOptions { dryRun: Bool = false, target: String = "bar", logLevel: Logger.Level = .trace, - versionStrategy: Configuration.VersionStrategy = .init(semvar: .init()) + versionStrategy: Configuration.VersionStrategy = .semvar(.init()) ) -> Self { .init( dryRun: dryRun, diff --git a/Tests/ConfigurationClientTests/ConfigurationClientTests.swift b/Tests/ConfigurationClientTests/ConfigurationClientTests.swift index 1b39d4b..ed3bb16 100644 --- a/Tests/ConfigurationClientTests/ConfigurationClientTests.swift +++ b/Tests/ConfigurationClientTests/ConfigurationClientTests.swift @@ -3,7 +3,6 @@ import Dependencies import Foundation import Testing import TestSupport -import TOMLKit @Suite("ConfigurationClientTests") struct ConfigurationClientTests { @@ -19,28 +18,6 @@ struct ConfigurationClientTests { let decoded = try coders.jsonDecoder().decode(Configuration.self, from: encoded) #expect(decoded == configuration) - - let tomlEncoded = try coders.tomlEncoder().encode(configuration) - let tomlDecoded = try coders.tomlDecoder().decode( - Configuration.self, - from: tomlEncoded - ) - #expect(tomlDecoded == configuration) - } - } - - @Test(arguments: ["foo", ".foo"]) - func configurationFile(fileName: String) { - for ext in ["toml", "json", "bar"] { - let file = ConfigurationFile(url: URL(filePath: "\(fileName).\(ext)")) - switch ext { - case "toml": - #expect(file == .toml(URL(filePath: "\(fileName).toml"))) - case "json": - #expect(file == .json(URL(filePath: "\(fileName).json"))) - default: - #expect(file == nil) - } } } @@ -50,16 +27,15 @@ struct ConfigurationClientTests { try await run { @Dependency(\.configurationClient) var configurationClient - for ext in ["toml", "json"] { + for ext in ["json"] { let fileUrl = url.appending(path: "test.\(ext)") let configuration = Configuration.mock - let configurationFile = ConfigurationFile(url: fileUrl)! - try await configurationClient.write(configuration, configurationFile) - let loaded = try await configurationClient.load(configurationFile) + try await configurationClient.write(configuration, fileUrl) + let loaded = try await configurationClient.load(fileUrl) #expect(loaded == configuration) - let findAndLoaded = try await configurationClient.findAndLoad(configurationFile.url) + let findAndLoaded = try await configurationClient.findAndLoad(fileUrl) #expect(findAndLoaded == configuration) try FileManager.default.removeItem(at: fileUrl) @@ -84,13 +60,12 @@ struct ConfigurationClientTests { #expect(Bool(true)) } - for ext in ["toml", "json"] { + for ext in ["json"] { let fileUrl = url.appending(path: ".bump-version.\(ext)") let configuration = Configuration.mock - let configurationFile = ConfigurationFile(url: fileUrl)! - try await configurationClient.write(configuration, configurationFile) - let loaded = try await configurationClient.findAndLoad(url) + try await configurationClient.write(configuration, fileUrl) + let loaded = try await configurationClient.findAndLoad(fileUrl) #expect(loaded == configuration) try FileManager.default.removeItem(at: fileUrl)