From 9c62c06ebe57819e4928bbe6cded542330c5070e Mon Sep 17 00:00:00 2001 From: Michael Housh Date: Sun, 22 Dec 2024 12:29:12 -0500 Subject: [PATCH] feat: Renames some modules, updates plugins to stop using deprecated components. --- Dockerfile | 8 +++++ Package.resolved | 20 +++++------ Package.swift | 32 ++++++++++-------- .../BuildWithVersionPlugin.swift | 24 +++++++------ .../GenerateVersionPlugin.swift | 2 +- .../UpdateVersionPlugin.swift | 4 +-- .../{CliVersion => CliClient}/CliClient.swift | 0 .../{CliVersion => CliClient}/Constants.swift | 0 .../Articles/GettingStarted.md | 0 .../Articles/ManualPlugins.md | 0 .../Documentation.docc/CliVersion.md | 0 .../Resources/trust~dark.png | Bin .../{CliVersion => CliClient}/Helpers.swift | 0 .../{CliVersion => CliClient}/SemVar.swift | 0 Sources/cli-version/BuildCommand.swift | 4 +-- Sources/cli-version/BumpCommand.swift | 2 +- Sources/cli-version/CliVersionCommand.swift | 2 +- Sources/cli-version/GenerateCommand.swift | 4 +-- Sources/cli-version/GlobalOptions.swift | 2 +- Sources/cli-version/UpdateCommand.swift | 4 +-- Tests/CliVersionTests/CliVersionTests.swift | 17 ++++++---- justfile | 26 +++++++++++++- 22 files changed, 96 insertions(+), 55 deletions(-) create mode 100644 Dockerfile rename Sources/{CliVersion => CliClient}/CliClient.swift (100%) rename Sources/{CliVersion => CliClient}/Constants.swift (100%) rename Sources/{CliVersion => CliClient}/Documentation.docc/Articles/GettingStarted.md (100%) rename Sources/{CliVersion => CliClient}/Documentation.docc/Articles/ManualPlugins.md (100%) rename Sources/{CliVersion => CliClient}/Documentation.docc/CliVersion.md (100%) rename Sources/{CliVersion => CliClient}/Documentation.docc/Resources/trust~dark.png (100%) rename Sources/{CliVersion => CliClient}/Helpers.swift (100%) rename Sources/{CliVersion => CliClient}/SemVar.swift (100%) diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..db41303 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +ARG SWIFT_VERSION="6.0.3" +FROM swift:${SWIFT_VERSION} +WORKDIR /app +COPY ./Package.* ./ +RUN swift package resolve +COPY . . +RUN swift build +CMD ["swift", "test"] diff --git a/Package.resolved b/Package.resolved index 1171feb..1f66754 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "07a243cd8c2ed649f5fe5e76202ed091834801a0637c8b7785404e20b9e0cac1", + "originHash" : "867dabf4e0a92ed23018f0ef682d2d889f080ca5eaf99607665038dfb3a7532f", "pins" : [ { "identity" : "combine-schedulers", @@ -24,8 +24,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-argument-parser.git", "state" : { - "revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531", - "version" : "1.2.3" + "revision" : "41982a3656a71c768319979febd796c6fd111d5c", + "version" : "1.5.0" } }, { @@ -42,8 +42,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-concurrency-extras", "state" : { - "revision" : "ea631ce892687f5432a833312292b80db238186a", - "version" : "1.0.0" + "revision" : "82a4ae7170d98d8538ec77238b7eb8e7199ef2e8", + "version" : "1.3.1" } }, { @@ -60,14 +60,14 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-docc-plugin.git", "state" : { - "revision" : "26ac5758409154cc448d7ab82389c520fa8a8247", - "version" : "1.3.0" + "revision" : "85e4bb4e1cd62cec64a4b8e769dcefdf0c5b9d64", + "version" : "1.4.3" } }, { "identity" : "swift-docc-symbolkit", "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-docc-symbolkit", + "location" : "https://github.com/swiftlang/swift-docc-symbolkit", "state" : { "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", "version" : "1.0.0" @@ -78,8 +78,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-log.git", "state" : { - "revision" : "532d8b529501fb73a2455b179e0bbb6d49b652ed", - "version" : "1.5.3" + "revision" : "96a2f8a0fa41e9e09af4585e2724c4e825410b91", + "version" : "1.6.2" } }, { diff --git a/Package.swift b/Package.swift index 462f75b..4e14859 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version: 5.10 +// swift-tools-version: 6.0 import PackageDescription @@ -8,7 +8,7 @@ let package = Package( .macOS(.v13) ], products: [ - .library(name: "CliVersion", targets: ["CliVersion"]), + .library(name: "CliClient", targets: ["CliClient"]), .plugin(name: "BuildWithVersionPlugin", targets: ["BuildWithVersionPlugin"]), .plugin(name: "GenerateVersionPlugin", targets: ["GenerateVersionPlugin"]), .plugin(name: "UpdateVersionPlugin", targets: ["UpdateVersionPlugin"]) @@ -17,16 +17,29 @@ let package = Package( .package(url: "https://github.com/pointfreeco/swift-dependencies.git", from: "1.6.2"), .package(url: "https://github.com/m-housh/swift-shell-client.git", from: "0.2.0"), .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.2.2") + .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") ], targets: [ .executableTarget( name: "cli-version", dependencies: [ - "CliVersion", + "CliClient", .product(name: "ArgumentParser", package: "swift-argument-parser") ] ), + .target( + name: "CliClient", + dependencies: [ + "FileClient", + "GitClient", + .product(name: "Logging", package: "swift-log") + ] + ), + .testTarget( + name: "CliVersionTests", + dependencies: ["CliClient", "TestSupport"] + ), .target( name: "FileClient", dependencies: [ @@ -43,18 +56,7 @@ let package = Package( .product(name: "ShellClient", package: "swift-shell-client") ] ), - .target( - name: "CliVersion", - dependencies: [ - "FileClient", - "GitClient" - ] - ), .target(name: "TestSupport"), - .testTarget( - name: "CliVersionTests", - dependencies: ["CliVersion", "TestSupport"] - ), .plugin( name: "BuildWithVersionPlugin", capability: .buildTool(), diff --git a/Plugins/BuildWithVersionPlugin/BuildWithVersionPlugin.swift b/Plugins/BuildWithVersionPlugin/BuildWithVersionPlugin.swift index a817422..48d4e68 100644 --- a/Plugins/BuildWithVersionPlugin/BuildWithVersionPlugin.swift +++ b/Plugins/BuildWithVersionPlugin/BuildWithVersionPlugin.swift @@ -7,24 +7,28 @@ struct GenerateVersionBuildPlugin: BuildToolPlugin { context: PackagePlugin.PluginContext, target: PackagePlugin.Target ) async throws -> [PackagePlugin.Command] { - guard let target = target as? SourceModuleTarget else { return [] } + guard let target = target as? SwiftSourceModuleTarget else { return [] } - let gitDirectoryPath = target.directory - .removingLastComponent() - .removingLastComponent() + let gitDirectoryPath = target.directoryURL + .deletingLastPathComponent() + .deletingLastPathComponent() let tool = try context.tool(named: "cli-version") - let outputPath = context.pluginWorkDirectory + let outputPath = context.pluginWorkDirectoryURL - let outputFile = outputPath.appending("Version.swift") + let outputFile = outputPath.appending(path: "Version.swift") return [ .buildCommand( - displayName: "Build With Version Plugin", - executable: tool.path, - arguments: ["build", "--verbose", "--git-directory", gitDirectoryPath.string, "--target", outputPath.string], + displayName: "Build with Version Plugin", + executable: tool.url, + arguments: [ + "build", "--verbose", + "--git-directory", gitDirectoryPath.absoluteString, + "--target", outputPath.absoluteString + ], environment: [:], - inputFiles: target.sourceFiles.map(\.path), + inputFiles: target.sourceFiles.map(\.url), outputFiles: [outputFile] ) ] diff --git a/Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift b/Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift index 1ff4d2d..c27b322 100644 --- a/Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift +++ b/Plugins/GenerateVersionPlugin/GenerateVersionPlugin.swift @@ -15,7 +15,7 @@ struct GenerateVersionPlugin: CommandPlugin { else { continue } let process = Process() - process.executableURL = URL(fileURLWithPath: gitVersion.path.string) + process.executableURL = gitVersion.url process.arguments = arguments try process.run() process.waitUntilExit() diff --git a/Plugins/UpdateVersionPlugin/UpdateVersionPlugin.swift b/Plugins/UpdateVersionPlugin/UpdateVersionPlugin.swift index e2776c7..1dfb539 100644 --- a/Plugins/UpdateVersionPlugin/UpdateVersionPlugin.swift +++ b/Plugins/UpdateVersionPlugin/UpdateVersionPlugin.swift @@ -1,5 +1,5 @@ -import PackagePlugin import Foundation +import PackagePlugin @main struct UpdateVersionPlugin: CommandPlugin { @@ -15,7 +15,7 @@ struct UpdateVersionPlugin: CommandPlugin { else { continue } let process = Process() - process.executableURL = URL(fileURLWithPath: gitVersion.path.string) + process.executableURL = gitVersion.url process.arguments = arguments try process.run() process.waitUntilExit() diff --git a/Sources/CliVersion/CliClient.swift b/Sources/CliClient/CliClient.swift similarity index 100% rename from Sources/CliVersion/CliClient.swift rename to Sources/CliClient/CliClient.swift diff --git a/Sources/CliVersion/Constants.swift b/Sources/CliClient/Constants.swift similarity index 100% rename from Sources/CliVersion/Constants.swift rename to Sources/CliClient/Constants.swift diff --git a/Sources/CliVersion/Documentation.docc/Articles/GettingStarted.md b/Sources/CliClient/Documentation.docc/Articles/GettingStarted.md similarity index 100% rename from Sources/CliVersion/Documentation.docc/Articles/GettingStarted.md rename to Sources/CliClient/Documentation.docc/Articles/GettingStarted.md diff --git a/Sources/CliVersion/Documentation.docc/Articles/ManualPlugins.md b/Sources/CliClient/Documentation.docc/Articles/ManualPlugins.md similarity index 100% rename from Sources/CliVersion/Documentation.docc/Articles/ManualPlugins.md rename to Sources/CliClient/Documentation.docc/Articles/ManualPlugins.md diff --git a/Sources/CliVersion/Documentation.docc/CliVersion.md b/Sources/CliClient/Documentation.docc/CliVersion.md similarity index 100% rename from Sources/CliVersion/Documentation.docc/CliVersion.md rename to Sources/CliClient/Documentation.docc/CliVersion.md diff --git a/Sources/CliVersion/Documentation.docc/Resources/trust~dark.png b/Sources/CliClient/Documentation.docc/Resources/trust~dark.png similarity index 100% rename from Sources/CliVersion/Documentation.docc/Resources/trust~dark.png rename to Sources/CliClient/Documentation.docc/Resources/trust~dark.png diff --git a/Sources/CliVersion/Helpers.swift b/Sources/CliClient/Helpers.swift similarity index 100% rename from Sources/CliVersion/Helpers.swift rename to Sources/CliClient/Helpers.swift diff --git a/Sources/CliVersion/SemVar.swift b/Sources/CliClient/SemVar.swift similarity index 100% rename from Sources/CliVersion/SemVar.swift rename to Sources/CliClient/SemVar.swift diff --git a/Sources/cli-version/BuildCommand.swift b/Sources/cli-version/BuildCommand.swift index 1c89c0e..0f277c6 100644 --- a/Sources/cli-version/BuildCommand.swift +++ b/Sources/cli-version/BuildCommand.swift @@ -1,11 +1,11 @@ import ArgumentParser -import CliVersion +import CliClient import Foundation import ShellClient extension CliVersionCommand { struct Build: AsyncParsableCommand { - static var configuration: CommandConfiguration = .init( + static let configuration: CommandConfiguration = .init( abstract: "Used for the build with version plugin.", discussion: "This should generally not be interacted with directly, outside of the build plugin." ) diff --git a/Sources/cli-version/BumpCommand.swift b/Sources/cli-version/BumpCommand.swift index f8dde53..1f2e6f8 100644 --- a/Sources/cli-version/BumpCommand.swift +++ b/Sources/cli-version/BumpCommand.swift @@ -1,5 +1,5 @@ import ArgumentParser -import CliVersion +import CliClient import Dependencies extension CliVersionCommand { diff --git a/Sources/cli-version/CliVersionCommand.swift b/Sources/cli-version/CliVersionCommand.swift index 1a7cac5..cda11b2 100644 --- a/Sources/cli-version/CliVersionCommand.swift +++ b/Sources/cli-version/CliVersionCommand.swift @@ -3,7 +3,7 @@ import Foundation @main struct CliVersionCommand: AsyncParsableCommand { - static var configuration: CommandConfiguration = .init( + static let configuration: CommandConfiguration = .init( commandName: "cli-version", version: VERSION ?? "0.0.0", subcommands: [ diff --git a/Sources/cli-version/GenerateCommand.swift b/Sources/cli-version/GenerateCommand.swift index 671eb8b..4a105ae 100644 --- a/Sources/cli-version/GenerateCommand.swift +++ b/Sources/cli-version/GenerateCommand.swift @@ -1,12 +1,12 @@ import ArgumentParser -import CliVersion +import CliClient import Dependencies import Foundation import ShellClient extension CliVersionCommand { struct Generate: AsyncParsableCommand { - static var configuration: CommandConfiguration = .init( + static let configuration: CommandConfiguration = .init( abstract: "Generates a version file in a command line tool that can be set via the git tag or git sha.", discussion: "This command can be interacted with directly, outside of the plugin usage context.", version: VERSION ?? "0.0.0" diff --git a/Sources/cli-version/GlobalOptions.swift b/Sources/cli-version/GlobalOptions.swift index e719186..9bd5b55 100644 --- a/Sources/cli-version/GlobalOptions.swift +++ b/Sources/cli-version/GlobalOptions.swift @@ -1,5 +1,5 @@ import ArgumentParser -@_spi(Internal) import CliVersion +@_spi(Internal) import CliClient import Dependencies import Foundation diff --git a/Sources/cli-version/UpdateCommand.swift b/Sources/cli-version/UpdateCommand.swift index 17cc14c..443c21a 100644 --- a/Sources/cli-version/UpdateCommand.swift +++ b/Sources/cli-version/UpdateCommand.swift @@ -1,5 +1,5 @@ import ArgumentParser -import CliVersion +import CliClient import Dependencies import Foundation import ShellClient @@ -7,7 +7,7 @@ import ShellClient extension CliVersionCommand { struct Update: AsyncParsableCommand { - static var configuration: CommandConfiguration = .init( + static let configuration: CommandConfiguration = .init( abstract: "Updates a version string to the git tag or git sha.", discussion: "This command can be interacted with directly outside of the plugin context." ) diff --git a/Tests/CliVersionTests/CliVersionTests.swift b/Tests/CliVersionTests/CliVersionTests.swift index 30c90be..1eb5258 100644 --- a/Tests/CliVersionTests/CliVersionTests.swift +++ b/Tests/CliVersionTests/CliVersionTests.swift @@ -6,6 +6,7 @@ import ShellClient import TestSupport import XCTest +// TODO: Remove final class GitVersionTests: XCTestCase { override func invokeTest() { @@ -28,14 +29,16 @@ final class GitVersionTests: XCTestCase { .cleanFilePath } - func test_live() async throws { - @Dependency(\.gitClient) var versionClient: GitClient + #if !os(Linux) + func test_live() async throws { + @Dependency(\.gitClient) var versionClient: GitClient - let version = try await versionClient.currentVersion(in: gitDir) - print("VERSION: \(version)") - // can't really have a predictable result for the live client. - XCTAssertNotEqual(version, "blob") - } + let version = try await versionClient.currentVersion(in: gitDir) + print("VERSION: \(version)") + // can't really have a predictable result for the live client. + XCTAssertNotEqual(version, "blob") + } + #endif func test_file_client() async throws { try await withTemporaryDirectory { tmpDir in diff --git a/justfile b/justfile index 6cc95f2..7bb9c96 100644 --- a/justfile +++ b/justfile @@ -1,20 +1,44 @@ product := "cli-version" +docker_image := "cli-version" +docker_tag := "test" [private] default: @just --list -build configuration="release": +# Build locally. +build configuration="debug": @swift build \ --disable-sandbox \ --configuration {{configuration}} \ --product {{product}} +alias b := build + +# Build a docker image. +build-docker configuration="debug": + @docker build -t {{docker_image}}:{{docker_tag}} . + +# Run the command-line tool. run *ARGS: @swift run {{product}} {{ARGS}} +# Clean the build folder. clean: rm -rf .build +# Clean and build. +clean-build configuration="debug": clean (build configuration) + +alias cb := clean-build + +# Test locally. test *ARGS: @swift test {{ARGS}} + +# Build docker test container and run tests. +test-docker: build-docker + @docker run --rm {{docker_image}}:{{docker_tag}} + +test-docker-without-building: + @docker run --rm {{docker_image}}:{{docker_tag}} swift test