Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
10943f9ce3 | ||
|
|
6927464d47 | ||
|
|
31ed16c828 | ||
|
|
ac1c86c431 | ||
|
|
4b28c293cb |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"originHash" : "fd1e824e418c767633bb79b055a4e84d9c86165746bc881d5d27457ad34b0c20",
|
||||
"originHash" : "17ce26ba5c862ca674cd3ceeb43a9fe8a5c5251c5561de65e632a06d79916342",
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "noora",
|
||||
@@ -33,17 +33,8 @@
|
||||
"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"
|
||||
"revision" : "626b5b7b2f45e1b0b1c6f4a309296d1d21d7311b",
|
||||
"version" : "1.7.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -11,8 +11,7 @@ let package = Package(
|
||||
)
|
||||
],
|
||||
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-argument-parser", from: "1.7.1"),
|
||||
.package(url: "https://github.com/apple/swift-log", from: "1.10.1"),
|
||||
.package(url: "https://github.com/apple/swift-nio", from: "2.95.0"),
|
||||
.package(url: "https://github.com/apple/swift-system", from: "1.6.4"),
|
||||
@@ -41,7 +40,6 @@ let package = Package(
|
||||
name: "InotifyTaskCLI",
|
||||
dependencies: [
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
|
||||
.product(name: "Logging", package: "swift-log"),
|
||||
.product(name: "_NIOFileSystem", package: "swift-nio"),
|
||||
.product(name: "Subprocess", package: "swift-subprocess"),
|
||||
|
||||
@@ -6,8 +6,8 @@ public actor Inotify {
|
||||
private var excludedItemNames: Set<String> = []
|
||||
private var watches = InotifyWatchManager()
|
||||
private var eventReader: any DispatchSourceRead
|
||||
private var eventStream: AsyncStream<RawInotifyEvent>
|
||||
public var events: AsyncCompactMapSequence<AsyncStream<RawInotifyEvent>, InotifyEvent> {
|
||||
private nonisolated let eventStream: AsyncStream<RawInotifyEvent>
|
||||
public nonisolated var events: AsyncCompactMapSequence<AsyncStream<RawInotifyEvent>, InotifyEvent> {
|
||||
self.eventStream.compactMap(self.transform(_:))
|
||||
}
|
||||
|
||||
|
||||
9
Sources/TaskCLI/Docker.swift
Normal file
9
Sources/TaskCLI/Docker.swift
Normal file
@@ -0,0 +1,9 @@
|
||||
struct Docker {
|
||||
static func getLinuxPlatformStringWithHostArchitecture() -> String {
|
||||
#if arch(x86_64)
|
||||
return "linux/amd64"
|
||||
#else
|
||||
return "linux/arm64"
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import ArgumentParser
|
||||
import AsyncAlgorithms
|
||||
import Foundation
|
||||
import Logging
|
||||
import Noora
|
||||
@@ -43,28 +42,21 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
|
||||
let script = Self.makeRunScript(for: targets)
|
||||
|
||||
logger.debug("Container script", metadata: ["script": "\(script)"])
|
||||
let dockerResult = try await Subprocess.run(
|
||||
let dockerRunResult = try await Subprocess.run(
|
||||
.name("docker"),
|
||||
arguments: [
|
||||
"run", "--rm",
|
||||
"-v", "\(tempDirectory.path(percentEncoded: false)):/code",
|
||||
"--platform", "linux/arm64",
|
||||
"-v", "\(tempDirectory.path):/code",
|
||||
"-v", "swift-inotify-build-cache:/code/.build",
|
||||
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
|
||||
"-w", "/code",
|
||||
"swift:latest",
|
||||
"/bin/bash", "-c", script,
|
||||
"/bin/bash", "-c", script
|
||||
],
|
||||
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("")
|
||||
}
|
||||
|
||||
guard dockerResult.terminationStatus.isSuccess else {
|
||||
output: .standardOutput,
|
||||
error: .standardError
|
||||
)
|
||||
if !dockerRunResult.terminationStatus.isSuccess {
|
||||
noora.error("Documentation generation failed.")
|
||||
return
|
||||
}
|
||||
@@ -116,10 +108,11 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
|
||||
}
|
||||
|
||||
private static func packageTargets() async throws -> [(name: String, path: String)] {
|
||||
let packageDescription = try await Subprocess.run(
|
||||
let packageDescriptionResult = try await Subprocess.run(
|
||||
.name("swift"),
|
||||
arguments: ["package", "describe", "--type", "json"],
|
||||
output: .data(limit: 20_000)
|
||||
output: .data(limit: 10_000),
|
||||
error: .standardError
|
||||
)
|
||||
|
||||
struct PackageDescription: Codable {
|
||||
@@ -130,7 +123,11 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
|
||||
let path: String
|
||||
}
|
||||
|
||||
let package = try JSONDecoder().decode(PackageDescription.self, from: packageDescription.standardOutput)
|
||||
if !packageDescriptionResult.terminationStatus.isSuccess {
|
||||
throw GenerateDocumentationError.unableToReadPackageDescription
|
||||
}
|
||||
|
||||
let package = try JSONDecoder().decode(PackageDescription.self, from: packageDescriptionResult.standardOutput)
|
||||
return package.targets.map { ($0.name, $0.path) }
|
||||
}
|
||||
|
||||
@@ -175,15 +172,16 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
|
||||
// MARK: - Dependency Injection
|
||||
|
||||
private func injectDoccPluginDependency(in directory: URL, logger: Logger) async throws {
|
||||
let result = try await Subprocess.run(
|
||||
let swiftRunResult = try await Subprocess.run(
|
||||
.name("swift"),
|
||||
arguments: [
|
||||
"package", "--package-path", directory.path(percentEncoded: false),
|
||||
"add-dependency", "--from", Self.doccPluginMinVersion, Self.doccPluginURL
|
||||
],
|
||||
) { _ in }
|
||||
|
||||
guard result.terminationStatus.isSuccess else {
|
||||
output: .standardOutput,
|
||||
error: .standardError
|
||||
)
|
||||
if !swiftRunResult.terminationStatus.isSuccess {
|
||||
throw GenerateDocumentationError.dependencyInjectionFailed
|
||||
}
|
||||
|
||||
@@ -193,11 +191,14 @@ struct GenerateDocumentationCommand: AsyncParsableCommand {
|
||||
|
||||
enum GenerateDocumentationError: Error, CustomStringConvertible {
|
||||
case dependencyInjectionFailed
|
||||
case unableToReadPackageDescription
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .dependencyInjectionFailed:
|
||||
"Failed to add swift-docc-plugin dependency to Package.swift."
|
||||
case .unableToReadPackageDescription:
|
||||
"Failed to read the package description."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import ArgumentParser
|
||||
import AsyncAlgorithms
|
||||
import Foundation
|
||||
import Subprocess
|
||||
import Noora
|
||||
import Subprocess
|
||||
|
||||
struct TestCommand: AsyncParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
@@ -22,21 +21,21 @@ struct TestCommand: AsyncParsableCommand {
|
||||
|
||||
noora.info("Running tests on Linux.")
|
||||
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
|
||||
async let monitorResult = Subprocess.run(
|
||||
let dockerRunResult = try await Subprocess.run(
|
||||
.name("docker"),
|
||||
arguments: ["run", "-v", "\(currentDirectory):/code", "--security-opt", "systempaths=unconfined", "--platform", "linux/arm64", "-w", "/code", "swift:latest", "/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"],
|
||||
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) {
|
||||
arguments: [
|
||||
"run",
|
||||
"-v", "\(currentDirectory):/code",
|
||||
"-v", "swift-inotify-build-cache:/code/.build",
|
||||
"--security-opt", "systempaths=unconfined",
|
||||
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
|
||||
"-w", "/code", "swift:latest",
|
||||
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
|
||||
],
|
||||
output: .standardOutput,
|
||||
error: .standardError
|
||||
)
|
||||
if dockerRunResult.terminationStatus.isSuccess {
|
||||
noora.success("All tests completed successfully.")
|
||||
} else {
|
||||
noora.error("Not all tests completed successfully.")
|
||||
|
||||
Reference in New Issue
Block a user