Files
swift-inotify/Sources/TaskCLI/Test Command.swift
T. R. Bernstein ac1c86c431 Run linux container with same architechture as host
As the development team uses both Intel and Apple Silicon Macs,
we have to get the host CPU architecture at compilation time instead of
harcoding it.
If the container has a different architecture, the guest has to be
emulated.
2026-03-22 17:51:24 +01:00

39 lines
1.1 KiB
Swift

import Foundation
import Script
import Noora
struct TestCommand: Script {
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
let docker = try await executable(named: "docker")
noora.info("Running tests on Linux.")
logger.debug("Current directory", metadata: ["current-directory": "\(currentDirectory)"])
do {
try await docker(
"run",
"-v", "\(currentDirectory):/code",
"--security-opt", "systempaths=unconfined",
"--platform", Docker.getLinuxPlatformStringWithHostArchitecture(),
"-w", "/code", "swift:latest",
"/bin/bash", "-c", "swift test --skip InotifyLimitTests; swift test --skip-build --filter InotifyLimitTests"
)
noora.success("All tests completed successfully.")
} catch {
noora.error("Not all tests completed successfully.")
}
}
}