-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
// Created by Sam Deane on 03/09/24. | ||
// All code (c) 2024 - present day, Elegant Chaos Limited. | ||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
|
||
import Foundation | ||
import PackagePlugin | ||
|
||
@main struct ReleaseToolsPlugin: CommandPlugin { | ||
func run(tool: String, arguments: [String], context: PackagePlugin.PluginContext, cwd: URL) async throws -> String { | ||
let tool = try context.tool(named: tool) | ||
|
||
Diagnostics.remark("Running \(tool) \(arguments.joined(separator: " ")).") | ||
|
||
let outputPipe = Pipe() | ||
return try await withCheckedThrowingContinuation { continuation in | ||
let process = Process() | ||
process.executableURL = tool.url | ||
process.arguments = arguments | ||
process.currentDirectoryURL = cwd | ||
|
||
process.standardOutput = outputPipe | ||
process.terminationHandler = { process in | ||
let data = outputPipe.fileHandleForReading.readDataToEndOfFile() | ||
continuation.resume( | ||
returning: String(decoding: data, as: UTF8.self) | ||
) | ||
} | ||
do { | ||
try process.run() | ||
} catch { | ||
continuation.resume(throwing: error) | ||
} | ||
} | ||
} | ||
|
||
func performCommand(context: PackagePlugin.PluginContext, arguments: [String]) async throws { | ||
let output = try await run( | ||
tool: "ActionBuilderTool", arguments: arguments, context: context, cwd: context.package.directoryURL) | ||
|
||
Diagnostics.remark(output) | ||
|
||
} | ||
} |