diff --git a/.github/wiki/Deliverable-Configurations.md b/.github/wiki/Deliverable-Configurations.md index 28c892d1..1568bc23 100644 --- a/.github/wiki/Deliverable-Configurations.md +++ b/.github/wiki/Deliverable-Configurations.md @@ -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. diff --git a/Scripts/Swift/Helpers/SafeShell.swift b/Scripts/Swift/Helpers/SafeShell.swift new file mode 100644 index 00000000..dbca3d27 --- /dev/null +++ b/Scripts/Swift/Helpers/SafeShell.swift @@ -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 +} diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift new file mode 100644 index 00000000..35a22abb --- /dev/null +++ b/Scripts/Swift/SetUpCICDService.swift @@ -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") diff --git a/Scripts/Swift/SetUpDeliveryConstants.swift b/Scripts/Swift/SetUpDeliveryConstants.swift new file mode 100644 index 00000000..dfaf1f43 --- /dev/null +++ b/Scripts/Swift/SetUpDeliveryConstants.swift @@ -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'.") +} diff --git a/make.sh b/make.sh index d960d79d..3f8b6ef3 100644 --- a/make.sh +++ b/make.sh @@ -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! diff --git a/set_up_deliverable.sh b/set_up_deliverable.sh deleted file mode 100644 index 445c4ca7..00000000 --- a/set_up_deliverable.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -read -p "Which CI/CD service do you use (Can be edited later) [(g)ithub/(b)itrise/(c)odemagic/(l)ater]: " ciService - -if [ "$ciService" = "g" -o "$ciService" = "github" ]; then - echo "Setting template for Github Actions" - rm bitrise.yml - rm codemagic.yaml -elif [ "$ciService" = "b" -o "$ciService" = "bitrise" ]; then - echo "Setting template for Bitrise" - rm -rf .github/workflows - rm codemagic.yaml -elif [ "$ciService" = "c" -o "$ciService" = "codemagic" ]; then - echo "Setting template for CodeMagic" - rm -rf .github/workflows - rm bitrise.yml -else - echo "You can manually setup the template later." -fi -echo "✅ Completed" - -read -n1 -p "Do you want to set up Constants values? (Can be edited later) [Y/n]:" confirm -if ! echo $confirm | grep '^[Yy]\?$'; then - echo "✅ Completed" -else - open -a Xcode fastlane/Constants/Constant.swift -fi