Skip to content

Commit

Permalink
[#498] Create Enum for gifhub runner type
Browse files Browse the repository at this point in the history
  • Loading branch information
ducbm051291 committed Dec 4, 2023
1 parent 622af2a commit c1ae290
Showing 1 changed file with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ struct SetUpCICDService {
}
}
}

enum GithubRunnerType {

case macOSLatest, selfHosted, later

init?(_ name: String) {
switch name.lowercased() {
case "m", "macOS":
self = .macOSLatest
case "s", "self-hosted":
self = .selfHosted
case "l", "later":
self = .later
default:
return nil
}
}
}

private let fileManager = FileManager.default

Expand All @@ -33,28 +51,27 @@ struct SetUpCICDService {

switch service {
case .github:
var runnerType: String?
var runnerType: GithubRunnerType?
while runnerType == nil {
print("Which workflow runner do you want to use? [(m)acos-latest/(s)elf-hosted]: ")
runnerType = readLine()?.lowercased()
if runnerType != "m" && runnerType != "s" {
print("Invalid input. Please enter 'm' for macOS-latest or 's' for self-hosted.")
runnerType = nil
}
print("Which workflow runner do you want to use? [(m)acos-latest/(s)elf-hosted/(l)ater]: ")
runnerType = GithubRunnerType(readLine().string)
}
print("Setting template for Github Actions")
fileManager.removeItems(in: "bitrise.yml")
fileManager.removeItems(in: "codemagic.yaml")
fileManager.removeItems(in: ".github/workflows")
fileManager.createDirectory(path: ".github/workflows")
if runnerType == "s" {
fileManager.moveFiles(in: ".github/self_hosted_project_workflows", to: ".github/workflows")
switch runnerType {
case .macOSLatest:
fileManager.moveFiles(in: ".github/project_workflows", to: ".github/workflows")
fileManager.removeItems(in: ".github/project_workflows")
fileManager.removeItems(in: ".github/self_hosted_project_workflows")
} else {
fileManager.moveFiles(in: ".github/project_workflows", to: ".github/workflows")
case .selfHosted:
fileManager.moveFiles(in: ".github/self_hosted_project_workflows", to: ".github/workflows")
fileManager.removeItems(in: ".github/project_workflows")
fileManager.removeItems(in: ".github/self_hosted_project_workflows")
case .later, .none:
print("You can manually setup the runner later.")
}
case .bitrise:
print("Setting template for Bitrise")
Expand Down

0 comments on commit c1ae290

Please sign in to comment.