wip
This commit is contained in:
@@ -8,6 +8,12 @@ struct GenerateVersionBuildPlugin: BuildToolPlugin {
|
|||||||
target: PackagePlugin.Target
|
target: PackagePlugin.Target
|
||||||
) async throws -> [PackagePlugin.Command] {
|
) async throws -> [PackagePlugin.Command] {
|
||||||
guard let target = target as? SourceModuleTarget else { return [] }
|
guard let target = target as? SourceModuleTarget else { return [] }
|
||||||
|
|
||||||
|
let gitDirectoryPath = target.directory
|
||||||
|
.removingLastComponent()
|
||||||
|
.removingLastComponent()
|
||||||
|
.removingLastComponent()
|
||||||
|
|
||||||
let tool = try context.tool(named: "git-version")
|
let tool = try context.tool(named: "git-version")
|
||||||
let outputPath = context.pluginWorkDirectory
|
let outputPath = context.pluginWorkDirectory
|
||||||
|
|
||||||
@@ -17,7 +23,7 @@ struct GenerateVersionBuildPlugin: BuildToolPlugin {
|
|||||||
.buildCommand(
|
.buildCommand(
|
||||||
displayName: "Build With Version",
|
displayName: "Build With Version",
|
||||||
executable: tool.path,
|
executable: tool.path,
|
||||||
arguments: ["generate", "--verbose", outputPath.string],
|
arguments: ["build", "--git-directory", gitDirectoryPath.string, outputPath.string],
|
||||||
environment: [:],
|
environment: [:],
|
||||||
inputFiles: target.sourceFiles.map(\.path),
|
inputFiles: target.sourceFiles.map(\.path),
|
||||||
outputFiles: [outputFile]
|
outputFiles: [outputFile]
|
||||||
|
|||||||
47
Sources/git-version/BuildCommand.swift
Normal file
47
Sources/git-version/BuildCommand.swift
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import ArgumentParser
|
||||||
|
import Foundation
|
||||||
|
import GitVersion
|
||||||
|
import ShellClient
|
||||||
|
|
||||||
|
extension GitVersionCommand {
|
||||||
|
struct Build: ParsableCommand {
|
||||||
|
static var configuration: CommandConfiguration = .init(
|
||||||
|
abstract: "Used for the build with version plugin."
|
||||||
|
)
|
||||||
|
|
||||||
|
// @OptionGroup var shared: SharedOptions
|
||||||
|
|
||||||
|
@Argument(help: "The output file path.")
|
||||||
|
var outputPath: String
|
||||||
|
|
||||||
|
@Option(
|
||||||
|
name: .customLong("git-directory"),
|
||||||
|
help: "The git directory for the version."
|
||||||
|
)
|
||||||
|
var gitDirectory: String? = nil
|
||||||
|
|
||||||
|
func run() throws {
|
||||||
|
try withDependencies {
|
||||||
|
$0.logger.logLevel = .debug
|
||||||
|
$0.fileClient = .liveValue
|
||||||
|
$0.gitVersionClient = .liveValue
|
||||||
|
} operation: {
|
||||||
|
@Dependency(\.gitVersionClient) var gitVersion
|
||||||
|
@Dependency(\.fileClient) var fileClient
|
||||||
|
@Dependency(\.logger) var logger
|
||||||
|
|
||||||
|
let fileUrl = URL(fileURLWithPath: outputPath)
|
||||||
|
let fileString = fileUrl.fileString()
|
||||||
|
|
||||||
|
let currentVersion = try gitVersion.currentVersion(in: gitDirectory)
|
||||||
|
|
||||||
|
let fileContents = template
|
||||||
|
.replacingOccurrences(of: "nil", with: "\"\(currentVersion)\"")
|
||||||
|
|
||||||
|
try fileClient.write(string: fileContents, to: fileUrl)
|
||||||
|
logger.info("Updated version file: \(fileString)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -8,6 +8,7 @@ struct GitVersionCommand: ParsableCommand {
|
|||||||
commandName: "git-version",
|
commandName: "git-version",
|
||||||
version: VERSION ?? "0.0.0",
|
version: VERSION ?? "0.0.0",
|
||||||
subcommands: [
|
subcommands: [
|
||||||
|
Build.self,
|
||||||
Generate.self,
|
Generate.self,
|
||||||
Update.self
|
Update.self
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user