-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Process Provisioner and fix retry logic
- Loading branch information
Showing
14 changed files
with
125 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,4 +90,4 @@ fastlane/test_output | |
iOSInjectionProject/ | ||
|
||
# Mac System Files | ||
.DS_Store | ||
*.DS_Store |
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
Binary file not shown.
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
2 changes: 1 addition & 1 deletion
2
Cilicon/Config/GithubConfig.swift → Cilicon/Config/GithubProvisionerConfig.swift
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,19 @@ | ||
import Foundation | ||
|
||
struct ProcessProvisionerConfig: Decodable { | ||
/// The executable to be run | ||
let executablePath: String | ||
/// The arguments to be passed to the executable. These will be appended to the bundle path and action arguments. | ||
let arguments: [String] | ||
|
||
enum CodingKeys: CodingKey { | ||
case executablePath | ||
case arguments | ||
} | ||
|
||
init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.executablePath = try container.decode(String.self, forKey: .executablePath) | ||
self.arguments = try container.decodeIfPresent([String].self, forKey: .arguments) ?? [] | ||
} | ||
} |
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
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
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,50 @@ | ||
// | ||
// TaskProvisioner.swift | ||
// Cilicon | ||
// | ||
// Created by Marco Cancellieri on 30.11.22. | ||
// | ||
|
||
import Foundation | ||
/// The Process Provisioner will call an executable of your choice. With the bundle path as well as the action ("provision" or "deprovision") as arguments. | ||
class ProcessProvisioner: Provisioner { | ||
let path: String | ||
let arguments: [String] | ||
|
||
init(path: String, arguments: [String]) { | ||
self.path = path | ||
self.arguments = arguments | ||
} | ||
|
||
func provision(bundle: VMBundle) async throws { | ||
try runProcess(bundle: bundle, action: "provision") | ||
} | ||
|
||
func deprovision(bundle: VMBundle) async throws { | ||
try runProcess(bundle: bundle, action: "deprovision") | ||
} | ||
|
||
func runProcess(bundle: VMBundle, action: String) throws { | ||
let executableURL = URL(filePath: (path as NSString).standardizingPath) | ||
let args = [bundle.url.relativePath, action] + arguments | ||
let proc = try Process.run(executableURL, arguments: args) | ||
proc.waitUntilExit() | ||
let status = proc.terminationStatus | ||
guard status == 0 else { | ||
throw ProcessProvisionerError.nonZeroStatus(status: status, | ||
executable: executableURL, | ||
arguments: args) | ||
} | ||
} | ||
} | ||
|
||
enum ProcessProvisionerError: LocalizedError { | ||
case nonZeroStatus(status: Int32, executable: URL, arguments: [String]) | ||
|
||
var errorDescription: String? { | ||
switch self { | ||
case .nonZeroStatus(let status, let executable, let arguments): | ||
return "Expected 0 Termination status, got \(status) instead when running \(executable.relativePath) with arguments: \(arguments.joined(separator: " "))" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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