feat: Begin cleaning up cli-client for better separation for current and next versions.
All checks were successful
CI / Ubuntu (push) Successful in 2m33s
All checks were successful
CI / Ubuntu (push) Successful in 2m33s
This commit is contained in:
@@ -44,95 +44,6 @@ public struct Configuration: Codable, Equatable, Sendable {
|
||||
|
||||
public extension Configuration {
|
||||
|
||||
/// Represents a branch version or pre-release strategy.
|
||||
///
|
||||
/// 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.
|
||||
public let includeCommitSha: Bool
|
||||
|
||||
/// Create a new branch strategy.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - includeCommitSha: Whether to include the commit sha.
|
||||
public init(includeCommitSha: Bool = true) {
|
||||
self.includeCommitSha = includeCommitSha
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 init(
|
||||
prefix: String? = nil,
|
||||
strategy: Strategy? = nil
|
||||
) {
|
||||
self.prefix = prefix
|
||||
self.strategy = strategy
|
||||
}
|
||||
|
||||
public enum Strategy: Codable, Equatable, Sendable {
|
||||
case branch(includeCommitSha: Bool = true)
|
||||
case command(arguments: [String], allowPrefix: Bool? = nil)
|
||||
case gitTag
|
||||
|
||||
public var branch: Branch? {
|
||||
guard case let .branch(includeCommitSha) = self
|
||||
else { return nil }
|
||||
return .init(includeCommitSha: includeCommitSha)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a semvar version strategy.
|
||||
///
|
||||
/// ## Example: 1.0.0
|
||||
///
|
||||
struct SemVar: Codable, Equatable, Sendable {
|
||||
|
||||
public let allowPreRelease: Bool?
|
||||
|
||||
/// Optional pre-releas suffix strategy.
|
||||
public let preRelease: PreRelease?
|
||||
|
||||
/// 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 let strategy: Strategy?
|
||||
|
||||
public init(
|
||||
allowPreRelease: Bool? = true,
|
||||
preRelease: PreRelease? = nil,
|
||||
requireExistingFile: Bool? = false,
|
||||
requireExistingSemVar: Bool? = false,
|
||||
strategy: Strategy? = nil
|
||||
) {
|
||||
self.allowPreRelease = allowPreRelease
|
||||
self.preRelease = preRelease
|
||||
self.requireExistingFile = requireExistingFile
|
||||
self.requireExistingSemVar = requireExistingSemVar
|
||||
self.strategy = strategy
|
||||
}
|
||||
|
||||
public enum Strategy: Codable, Equatable, Sendable {
|
||||
case command(arguments: [String])
|
||||
case gitTag(exactMatch: Bool? = false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// Represents the target where we will bump the version in.
|
||||
///
|
||||
/// This can either be a path to a version file or a module used to
|
||||
@@ -283,4 +194,93 @@ public extension Configuration {
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a branch version or pre-release strategy.
|
||||
///
|
||||
/// 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.
|
||||
public let includeCommitSha: Bool
|
||||
|
||||
/// Create a new branch strategy.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - includeCommitSha: Whether to include the commit sha.
|
||||
public init(includeCommitSha: Bool = true) {
|
||||
self.includeCommitSha = includeCommitSha
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 init(
|
||||
prefix: String? = nil,
|
||||
strategy: Strategy? = nil
|
||||
) {
|
||||
self.prefix = prefix
|
||||
self.strategy = strategy
|
||||
}
|
||||
|
||||
public enum Strategy: Codable, Equatable, Sendable {
|
||||
case branch(includeCommitSha: Bool = true)
|
||||
case command(arguments: [String], allowPrefix: Bool? = nil)
|
||||
case gitTag
|
||||
|
||||
public var branch: Branch? {
|
||||
guard case let .branch(includeCommitSha) = self
|
||||
else { return nil }
|
||||
return .init(includeCommitSha: includeCommitSha)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents a semvar version strategy.
|
||||
///
|
||||
/// ## Example: 1.0.0
|
||||
///
|
||||
struct SemVar: Codable, Equatable, Sendable {
|
||||
|
||||
public let allowPreRelease: Bool?
|
||||
|
||||
/// Optional pre-releas suffix strategy.
|
||||
public let preRelease: PreRelease?
|
||||
|
||||
/// 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 let strategy: Strategy?
|
||||
|
||||
public init(
|
||||
allowPreRelease: Bool? = true,
|
||||
preRelease: PreRelease? = nil,
|
||||
requireExistingFile: Bool? = false,
|
||||
requireExistingSemVar: Bool? = false,
|
||||
strategy: Strategy? = nil
|
||||
) {
|
||||
self.allowPreRelease = allowPreRelease
|
||||
self.preRelease = preRelease
|
||||
self.requireExistingFile = requireExistingFile
|
||||
self.requireExistingSemVar = requireExistingSemVar
|
||||
self.strategy = strategy
|
||||
}
|
||||
|
||||
public enum Strategy: Codable, Equatable, Sendable {
|
||||
case command(arguments: [String])
|
||||
case gitTag(exactMatch: Bool? = false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import DependenciesMacros
|
||||
import FileClient
|
||||
import Foundation
|
||||
|
||||
// TODO: Add a method to get a semvar / handle a version strategy's ??
|
||||
|
||||
public extension DependencyValues {
|
||||
|
||||
/// Perform operations with configuration files.
|
||||
@@ -16,6 +18,12 @@ public extension DependencyValues {
|
||||
@DependencyClient
|
||||
public struct ConfigurationClient: Sendable {
|
||||
|
||||
fileprivate enum Constants {
|
||||
static let defaultFileNameWithoutExtension = ".bump-version"
|
||||
static let defaultExtension = "json"
|
||||
static var defaultFileName: String { "\(defaultFileNameWithoutExtension).\(defaultExtension)" }
|
||||
}
|
||||
|
||||
/// The default file name for a configuration file.
|
||||
public var defaultFileName: @Sendable () -> String = { "test.json" }
|
||||
|
||||
@@ -89,15 +97,13 @@ extension ConfigurationClient: DependencyKey {
|
||||
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())
|
||||
}
|
||||
|
||||
if try await fileClient.isDirectory(url.cleanFilePath) {
|
||||
url = url.appending(path: "\(defaultFileName).json")
|
||||
url = url.appending(path: ConfigurationClient.Constants.defaultFileName)
|
||||
}
|
||||
|
||||
if fileClient.fileExists(url) {
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import Foundation
|
||||
|
||||
extension ConfigurationClient {
|
||||
enum Constants {
|
||||
static let defaultFileNameWithoutExtension = ".bump-version"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user