Skip to content

Commit

Permalink
[#495] Add Swift package for Make
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Sep 28, 2023
1 parent 3449d97 commit 4cf4cbb
Show file tree
Hide file tree
Showing 23 changed files with 236 additions and 134 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_swiftui_install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: bundle install

- name: Start Install Script for SwiftUI Template App
run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp --interface SwiftUI
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface SwiftUI

- name: Build and Test
run: bundle exec fastlane buildAndTest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_uikit_install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: bundle install

- name: Start Install Script for UIKit Template App
run: sh make.sh --bundle-id co.nimblehq.template --bundle-id-staging co.nimblehq.template.staging --project-name TemplateApp --interface UIKit
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit

- name: Build and Test
run: bundle exec fastlane buildAndTest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_upload_build_to_firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
${{ runner.os }}-pods-
- name: Start Install Script for Template App
run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit

- name: Start Setup Script for Template App Firebase Upload
run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift -
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make-test-firebase
env:
MATCH_REPO: ${{ secrets.MATCH_REPO }}
STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_upload_build_to_test_flight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ jobs:
${{ runner.os }}-pods-
- name: Start Install Script for Template App
run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make --bundle-id-production co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit

- name: Start Setup Script for Template App TestFlight Upload
run: cat Scripts/Swift/SetUpTestTestFlight.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift -
run: swift run --package-path Scripts/Swift/iOSTemplateMaker iOSTemplateMaker make-test-test-flight
env:
MATCH_REPO: ${{ secrets.MATCH_REPO }}
API_KEY_ID: ${{ secrets.API_KEY_ID }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,6 @@ dependencies/

# Environment
.env
Scripts/Swift/iOSTemplateMaker/.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
Scripts/Swift/iOSTemplateMaker/.build
Scripts/Swift/iOSTemplateMaker/.swiftpm
16 changes: 0 additions & 16 deletions Scripts/Swift/SetUpTestFirebase.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Scripts/Swift/SetUpTestTestFlight.swift

This file was deleted.

14 changes: 14 additions & 0 deletions Scripts/Swift/iOSTemplateMaker/Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "8f4d2753f0e4778c76d5f05ad16c74f707390531",
"version" : "1.2.3"
}
}
],
"version" : 2
}
28 changes: 28 additions & 0 deletions Scripts/Swift/iOSTemplateMaker/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.7.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "iOSTemplateMaker",
products: [
.executable(
name: "iOSTemplateMaker",
targets: ["iOSTemplateMaker"]
),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-argument-parser.git",
from: "1.0.0"
),
],
targets: [
.executableTarget(
name: "iOSTemplateMaker",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser")
]
),
]
)
3 changes: 3 additions & 0 deletions Scripts/Swift/iOSTemplateMaker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# iOSTemplateMaker

A description of this package.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

extension Optional {

func unwrappedOr(_ defaultValue: Wrapped) -> Wrapped {
switch self {
case .none:
return defaultValue
case let .some(value):
return value
}
}
}

extension Optional where Wrapped == String {

var string: String { unwrappedOr("") }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Foundation

extension String {

/// Match string with regex expression
static func ~= (lhs: String, rhs: String) -> Bool {
guard let regex = try? NSRegularExpression(pattern: rhs) else { return false }
let range = NSRange(location: 0, length: lhs.utf16.count)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

struct SetUpCICDService {

enum CICDService {
Expand Down Expand Up @@ -26,7 +28,7 @@ struct SetUpCICDService {
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() ?? "")
service = CICDService(readLine().string)
}

switch service {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Foundation

struct SetUpInterface {

enum Interface {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

struct SetUpTestFirebase {

private let teamIdPlaceholder = "<#teamId#>"
private let stagingFirebaseAppIdPlaceholder = "<#stagingFirebaseAppId#>"
private let firebaseTesterGroupsPlaceholder = "<#group1#>, <#group2#>"
private let matchRepoPlaceholder = "[email protected]:{organization}/{repo}.git"

private let firebaseTesterGroup = "nimble"
private let fileManager = FileManager.default

let matchRepo: String
let stagingFirebaseAppId: String
let teamId: String

func perform() {
fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: teamId)
fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: stagingFirebaseAppId)
fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup)
fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: matchRepo)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

struct SetUpTestTestFlight {

private let teamIdPlaceholder = "<#teamId#>"
private let apiKeyIdPlaceholder = "<#API_KEY_ID#>"
private let issuerIdPlaceholder = "<#ISSUER_ID#>"
private let matchRepoPlaceholder = "[email protected]:{organization}/{repo}.git"

private let fileManager = FileManager.default

let matchRepo: String
let apiKey: String
let issuerId: String
let teamId: String

func perform() {
fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: teamId)
fileManager.replaceAllOccurrences(of: apiKeyIdPlaceholder, to: apiKey)
fileManager.replaceAllOccurrences(of: issuerIdPlaceholder, to: issuerId)
fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: matchRepo)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/swift
import Foundation

class SetUpIOSProject {

Expand All @@ -14,7 +14,21 @@ class SetUpIOSProject {
private var minimumVersion = ""
private var interface: SetUpInterface.Interface?
private var projectNameNoSpace: String { projectName.trimmingCharacters(in: .whitespacesAndNewlines) }
private var isCI = !(ProcessInfo.processInfo.environment["CI"] ?? "").isEmpty
private var isCI = !((ProcessInfo.processInfo.environment["CI"]).string).isEmpty

init(
bundleIdProduction: String = "",
bundleIdStaging: String = "",
projectName: String = "",
minimumVersion: String = "",
interface: String = ""
) {
self.bundleIdProduction = bundleIdProduction
self.bundleIdStaging = bundleIdStaging
self.projectName = projectName
self.minimumVersion = minimumVersion
self.interface = .init(interface)
}

func perform() {
readArguments()
Expand All @@ -34,42 +48,30 @@ class SetUpIOSProject {
}

private func readArguments() {
// TODO: Should be replaced with ArgumentParser instead of command line
for (index, argument) in CommandLine.arguments.enumerated() {
switch index {
case 1: bundleIdProduction = argument
case 2: bundleIdStaging = argument
case 3: projectName = argument
case 4: minimumVersion = argument
case 5: interface = .init(argument)
default: break
}
}

if isCI {
minimumVersion = "14.0"
}

while bundleIdProduction.isEmpty || !checkPackageName(bundleIdProduction) {
print("BUNDLE ID PRODUCTION (i.e. com.example.project):")
bundleIdProduction = readLine() ?? ""
bundleIdProduction = readLine().string
}
while bundleIdStaging.isEmpty || !checkPackageName(bundleIdStaging) {
print("BUNDLE ID STAGING (i.e. com.example.project.staging):")
bundleIdStaging = readLine() ?? ""
bundleIdStaging = readLine().string
}
while projectName.isEmpty {
print("PROJECT NAME (i.e. NewProject):")
projectName = readLine() ?? ""
projectName = readLine().string
}
while minimumVersion.isEmpty || !checkVersion(minimumVersion) {
print("iOS Minimum Version (i.e. 14.0):")
let version = readLine() ?? ""
let version = readLine().string
minimumVersion = !version.isEmpty ? version : "14.0"
}
while interface == nil {
print("Interface [(S)wiftUI or (U)IKit]:")
interface = SetUpInterface.Interface(readLine() ?? "")
interface = SetUpInterface.Interface(readLine().string)
}
}

Expand Down Expand Up @@ -191,5 +193,3 @@ class SetUpIOSProject {
return valid
}
}

SetUpIOSProject().perform()
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import ArgumentParser
import Foundation

@main
struct iOSTemplateMaker: ParsableCommand {

static let configuration: CommandConfiguration = CommandConfiguration(
abstract: "Set up an iOS Project",
subcommands: [Make.self, MakeTestFirebase.self, MakeTestTestFlight.self],
defaultSubcommand: Make.self
)
}

extension iOSTemplateMaker {

struct Make: ParsableCommand {

@Option(help: "The production id (i.e. com.example.package)")
var bundleIdProduction: String?
@Option(help: "The staging id (i.e. com.example.package.staging)")
var bundleIdStaging: String?
@Option(help: "The project name (i.e. MyApp)")
var projectName: String?
@Option(help: "The minimum iOS version (14.0)")
var minimumVersion: String?
@Option(help: "The user interface frameword (SwiftUI or UIKit)")
var interface: String?

mutating func run() {
SetUpIOSProject(
bundleIdProduction: bundleIdProduction.string,
bundleIdStaging: bundleIdStaging.string,
projectName: projectName.string,
minimumVersion: minimumVersion.string,
interface: interface.string
).perform()
}
}
}

extension iOSTemplateMaker {

struct MakeTestFirebase: ParsableCommand {

mutating func run() {
let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"].string
let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"].string
let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"].string

SetUpTestFirebase(
matchRepo: envMatchRepo,
stagingFirebaseAppId: envStagingFirebaseAppId,
teamId: envTeamId
).perform()
}
}
}


extension iOSTemplateMaker {

struct MakeTestTestFlight: ParsableCommand {

mutating func run() {
let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"].string
let envApiKey = ProcessInfo.processInfo.environment["API_KEY_ID"].string
let envIssuerId = ProcessInfo.processInfo.environment["ISSUER_ID"].string
let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"].string

SetUpTestTestFlight(
matchRepo: envMatchRepo,
apiKey: envApiKey,
issuerId: envIssuerId,
teamId: envTeamId
).perform()
}
}
}
Loading

0 comments on commit 4cf4cbb

Please sign in to comment.