From 1a7e5ca5de12c4b34281b935002b5c4c80783108 Mon Sep 17 00:00:00 2001 From: "T. R. Bernstein" Date: Wed, 11 Mar 2026 16:09:09 +0100 Subject: [PATCH] Scaffold project structure --- .gitignore | 1 + Package.resolved | 87 +++++++++++++++++++ Package.swift | 46 ++++++++++ Sources/Inotify/Inotify.swift | 2 + Sources/TaskCLI/Command.swift | 9 ++ Sources/TaskCLI/Global Options.swift | 25 ++++++ Sources/TaskCLI/Test Command.swift | 45 ++++++++++ .../InitialisationTests.swift | 9 ++ 8 files changed, 224 insertions(+) create mode 100644 .gitignore create mode 100644 Package.resolved create mode 100644 Package.swift create mode 100644 Sources/Inotify/Inotify.swift create mode 100644 Sources/TaskCLI/Command.swift create mode 100644 Sources/TaskCLI/Global Options.swift create mode 100644 Sources/TaskCLI/Test Command.swift create mode 100644 Tests/InotifyIntegrationTests/InitialisationTests.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..24e5b0a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.build diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..02e22f7 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,87 @@ +{ + "originHash" : "db0ba74c125e968c67646390cbba012a5572a5c9c54171588ecbb73e370a448d", + "pins" : [ + { + "identity" : "noora", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tuist/Noora", + "state" : { + "revision" : "70c6d1477a982f3e4cd46ed2d122e04e9d0a0b59", + "version" : "0.56.0" + } + }, + { + "identity" : "path", + "kind" : "remoteSourceControl", + "location" : "https://github.com/tuist/path", + "state" : { + "revision" : "7c74ac435e03a927c3a73134c48b61e60221abcb", + "version" : "0.3.8" + } + }, + { + "identity" : "rainbow", + "kind" : "remoteSourceControl", + "location" : "https://github.com/onevcat/Rainbow", + "state" : { + "revision" : "cdf146ae671b2624917648b61c908d1244b98ca1", + "version" : "4.2.1" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser", + "state" : { + "revision" : "c5d11a805e765f52ba34ec7284bd4fcd6ba68615", + "version" : "1.7.0" + } + }, + { + "identity" : "swift-async-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-async-algorithms", + "state" : { + "revision" : "9d349bcc328ac3c31ce40e746b5882742a0d1272", + "version" : "1.1.3" + } + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections.git", + "state" : { + "revision" : "8d9834a6189db730f6264db7556a7ffb751e99ee", + "version" : "1.4.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log", + "state" : { + "revision" : "bbd81b6725ae874c69e9b8c8804d462356b55523", + "version" : "1.10.1" + } + }, + { + "identity" : "swift-subprocess", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swiftlang/swift-subprocess.git", + "state" : { + "revision" : "ba5888ad7758cbcbe7abebac37860b1652af2d9c", + "version" : "0.3.0" + } + }, + { + "identity" : "swift-system", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-system", + "state" : { + "revision" : "7c6ad0fc39d0763e0b699210e4124afd5041c5df", + "version" : "1.6.4" + } + } + ], + "version" : 3 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..e1c2fa6 --- /dev/null +++ b/Package.swift @@ -0,0 +1,46 @@ +// swift-tools-version: 6.0 +import PackageDescription + +let package = Package( + name: "Inotify", + platforms: [.macOS(.v13), .custom("Linux", versionString: "4.4.302")], + products: [ + .library( + name: "Inotify", + targets: ["Inotify"] + ), + .executable( + name: "task", + targets: ["TaskCLI"] + ) + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.7.0"), + .package(url: "https://github.com/apple/swift-async-algorithms", from: "1.1.3"), + .package(url: "https://github.com/apple/swift-log", from: "1.10.1"), + .package(url: "https://github.com/swiftlang/swift-subprocess.git", from: "0.3.0"), + .package(url: "https://github.com/tuist/Noora", from: "0.55.1") + ], + targets: [ + .target( + name: "Inotify", + dependencies: [ + .product(name: "Logging", package: "swift-log"), + ] + ), + .testTarget( + name: "InotifyIntegrationTests", + dependencies: ["Inotify"], + ), + .executableTarget( + name: "TaskCLI", + dependencies: [ + .product(name: "ArgumentParser", package: "swift-argument-parser"), + .product(name: "AsyncAlgorithms", package: "swift-async-algorithms"), + .product(name: "Logging", package: "swift-log"), + .product(name: "Subprocess", package: "swift-subprocess"), + .product(name: "Noora", package: "Noora") + ] + ) + ] +) diff --git a/Sources/Inotify/Inotify.swift b/Sources/Inotify/Inotify.swift new file mode 100644 index 0000000..2451248 --- /dev/null +++ b/Sources/Inotify/Inotify.swift @@ -0,0 +1,2 @@ +actor Inotify { +} diff --git a/Sources/TaskCLI/Command.swift b/Sources/TaskCLI/Command.swift new file mode 100644 index 0000000..cbc1edf --- /dev/null +++ b/Sources/TaskCLI/Command.swift @@ -0,0 +1,9 @@ +import ArgumentParser + +@main +struct Command: AsyncParsableCommand { + static let configuration = CommandConfiguration( + abstract: "Project tasks of Astzweig's Swift Inotify project.", + subcommands: [TestCommand.self] + ) +} diff --git a/Sources/TaskCLI/Global Options.swift b/Sources/TaskCLI/Global Options.swift new file mode 100644 index 0000000..f96ab36 --- /dev/null +++ b/Sources/TaskCLI/Global Options.swift @@ -0,0 +1,25 @@ +import ArgumentParser +import Logging + +struct GlobalOptions: ParsableArguments { + @Flag( + name: .short, + help: "Increase logging verbosity. Use -v, -vv, or -vvv." + ) + var verbose: Int + + var logLevel: Logger.Level { + switch verbose { + case 0: return .notice + case 1: return .info + case 2: return .debug + default: return .trace + } + } + + func makeLogger(labeled label: String) -> Logger { + var logger = Logger(label: label) + logger.logLevel = logLevel + return logger + } +} diff --git a/Sources/TaskCLI/Test Command.swift b/Sources/TaskCLI/Test Command.swift new file mode 100644 index 0000000..eae5633 --- /dev/null +++ b/Sources/TaskCLI/Test Command.swift @@ -0,0 +1,45 @@ +import ArgumentParser +import AsyncAlgorithms +import Foundation +import Subprocess +import Noora + +struct TestCommand: AsyncParsableCommand { + static let configuration = CommandConfiguration( + commandName: "test", + abstract: "Run swift test in a linux container.", + aliases: ["t"], + ) + + @OptionGroup var global: GlobalOptions + + // MARK: - Run + + func run() async throws { + let noora = Noora() + let logger = global.makeLogger(labeled: "swift-inotify.cli.task.test") + let currentDirectory = FileManager.default.currentDirectoryPath + + noora.info("Running tests on Linux.") + logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"]) + async let monitorResult = Subprocess.run( + .name("docker"), + arguments: ["run", "-v", "\(currentDirectory):/code", "--platform", "linux/arm64", "-w", "/code", "swift:latest", "swift", "test"], + preferredBufferSize: 10, + ) { execution, standardInput, standardOutput, standardError in + print("") + let stdout = standardOutput.lines() + let stderr = standardError.lines() + for try await line in merge(stdout, stderr) { + noora.passthrough("\(line)") + } + print("") + } + + if (try await monitorResult.terminationStatus.isSuccess) { + noora.success("All tests completed successfully.") + } else { + noora.error("Not all tests completed successfully.") + } + } +} diff --git a/Tests/InotifyIntegrationTests/InitialisationTests.swift b/Tests/InotifyIntegrationTests/InitialisationTests.swift new file mode 100644 index 0000000..faef273 --- /dev/null +++ b/Tests/InotifyIntegrationTests/InitialisationTests.swift @@ -0,0 +1,9 @@ +import Testing +@testable import Inotify + +@Suite("Initialisation") +struct InitTests { + @Test func createsCleanly() async throws { + let _ = Inotify() + } +}