Skip to content

Commit

Permalink
Merge pull request #496 from nimblehq/chore/490-modify-deliverable-sw…
Browse files Browse the repository at this point in the history
…ift-commmand

[#490] Migrate `set_up_deliverable.sh` to Swift command
  • Loading branch information
blyscuit authored Jul 20, 2023
2 parents d754762 + d98959b commit 9828255
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 29 deletions.
1 change: 0 additions & 1 deletion .github/wiki/Deliverable-Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ The file [DeliverableConstants.rb](https://github.com/nimblehq/ios-templates/blo
## Configure later

- Developer can modify the `DeliverableConstants` at any time.
- Use the command `sh set_up_deliverable.sh` to open `DeliverableConstants` with Xcode.
- Open the file manually at `fastlane/Constants/DeliverableConstants.rb` with any IDE.
20 changes: 20 additions & 0 deletions Scripts/Swift/Helpers/SafeShell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Foundation

@discardableResult
func safeShell(_ command: String) throws -> String? {
let task = Process()
let pipe = Pipe()

task.standardOutput = pipe
task.standardError = pipe
task.arguments = ["-c", command]
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
task.standardInput = nil

try task.run()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output = String(data: data, encoding: .utf8)

return output
}
50 changes: 50 additions & 0 deletions Scripts/Swift/SetUpCICDService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/swift

import Foundation

let fileManager = FileManager.default

enum CICDService {
case github, bitrise, codemagic, later

init?(_ name: String) {
switch name.lowercased() {
case "g", "github":
self = .github
case "b", "bitrise":
self = .bitrise
case "c", "codemagic":
self = .codemagic
case "l", "later":
self = .later
default:
return nil
}
}
}

var service: CICDService? = nil

while service == nil {
print("Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: ")
service = CICDService(readLine() ?? "")
}

switch service {
case .github:
print("Setting template for Github Actions")
fileManager.removeItems(in: "bitrise.yml")
fileManager.removeItems(in: "codemagic.yaml")
case .bitrise:
print("Setting template for Bitrise")
fileManager.removeItems(in: "codemagic.yaml")
fileManager.removeItems(in: ".github/workflows")
case .codemagic:
print("Setting template for CodeMagic")
fileManager.removeItems(in: "bitrise.yml")
fileManager.removeItems(in: ".github/workflows")
case .later:
print("You can manually setup the template later.")
}

print("✅ Completed")
18 changes: 18 additions & 0 deletions Scripts/Swift/SetUpDeliveryConstants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/swift

import Foundation

let fileManager = FileManager.default

print("Do you want to set up Constants values? (Can be edited later) [Y/n]: ")

var arg = readLine() ?? "y"

switch arg.lowercased() {
case "y", "yes", "":
let error = try safeShell("open -a Xcode fastlane/Constants/Constant.swift")
guard let error = error, !error.isEmpty else { break }
print("Could not open Xcode. Make sure Xcode is installed and try again.\nRaw error: \(error)")
default:
print("✅ Completed. You can edit this file at 'fastlane/Constants/Constant.swift'.")
}
6 changes: 4 additions & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,18 @@ echo "Remove script files and git/index"
rm -rf make.sh
rm -rf .github/workflows/test_install_script.yml
rm -f .git/index
rm -rf Scripts
git reset

if [[ -z "${CI}" ]]; then
rm -rf fastlane/Tests
rm -f set_up_test_firebase.sh
rm -f set_up_test_testflight.sh
sh set_up_deliverable.sh
cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift'
cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift'
fi

rm -rf Scripts

echo "✅ Completed"

# Done!
Expand Down
26 changes: 0 additions & 26 deletions set_up_deliverable.sh

This file was deleted.

0 comments on commit 9828255

Please sign in to comment.