-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for installing Stagehand via SPM (#15)
* Adds support for installing Stagehand via Swift Package Manager * Adds scripts for running builds on CI * Updates directory structure to recommended SPM structure * Updates installation instructions in README This resolves part of #2, since it only supports Stagehand and not StagehandTesting.
- Loading branch information
Showing
30 changed files
with
282 additions
and
12 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 |
---|---|---|
|
@@ -30,3 +30,8 @@ Pods/ | |
|
||
# Swift Playgrounds | ||
timeline.xctimeline | ||
|
||
# Swift Pacakge Manager | ||
generated/ | ||
.build/ | ||
.swiftpm/ |
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
language: objective-c | ||
jobs: | ||
- osx_image: xcode11.3 | ||
env: DEST='platform=iOS Simulator,OS=13.3,name=iPhone 11 Pro' | ||
env: ACTIONS="xcode,pod-lint";PLATFORM="iOS_13" | ||
- osx_image: xcode10.3 | ||
env: DEST='platform=iOS Simulator,OS=12.4,name=iPhone Xs' | ||
env: ACTIONS="xcode,pod-lint";PLATFORM="iOS_12" | ||
- osx_image: xcode10.3 | ||
env: DEST='platform=iOS Simulator,OS=11.4,name=iPhone X' | ||
env: ACTIONS="xcode,pod-lint";PLATFORM="iOS_11" | ||
- osx_image: xcode10.3 | ||
env: DEST='platform=iOS Simulator,OS=10.3.1,name=iPhone 7' | ||
env: ACTIONS="xcode,pod-lint";PLATFORM="iOS_10" | ||
- osx_image: xcode11.3 | ||
env: ACTIONS="spm";PLATFORM="iOS_13" | ||
install: | ||
- bundle install --gemfile=Example/Gemfile | ||
- bundle exec --gemfile=Example/Gemfile pod install --project-directory=Example | ||
script: | ||
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/Stagehand.xcworkspace -scheme "Stagehand Demo App" -sdk iphonesimulator -destination "$DEST" ONLY_ACTIVE_ARCH=NO | xcpretty | ||
- bundle exec --gemfile=Example/Gemfile pod lib lint | ||
- ./Scripts/ci.sh | ||
branches: | ||
only: | ||
- master |
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,42 @@ | ||
// swift-tools-version:5.0.1 | ||
|
||
// | ||
// Copyright 2020 Square Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Stagehand", | ||
platforms: [ | ||
.iOS(.v10), | ||
], | ||
products: [ | ||
.library( | ||
name: "Stagehand", | ||
targets: ["Stagehand"] | ||
), | ||
], | ||
targets: [ | ||
.target( | ||
name: "Stagehand", | ||
dependencies: [], | ||
path: "Sources/Stagehand" | ||
), | ||
], | ||
swiftLanguageVersions: [.v5] | ||
) | ||
|
||
let version = Version(2, 0, 3) |
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,182 @@ | ||
#!/usr/bin/env swift | ||
|
||
import Foundation | ||
|
||
// Usage: build.swift <spm|xcode> <platform> [<path_to_xcpretty>] | ||
|
||
func execute(commandPath: String, arguments: [String], pipedTo pipeProcess: Process? = nil) throws { | ||
let task = Process() | ||
task.launchPath = commandPath | ||
task.arguments = arguments | ||
|
||
let argumentsString = arguments | ||
.map { argument in | ||
if argument.contains(" ") { | ||
return "\"\(argument)\"" | ||
} else { | ||
return argument | ||
} | ||
} | ||
.joined(separator: " ") | ||
|
||
if let pipeProcess = pipeProcess, let pipePath = pipeProcess.launchPath { | ||
let pipe = Pipe() | ||
task.standardOutput = pipe | ||
pipeProcess.standardInput = pipe | ||
|
||
print("Launching command: \(commandPath) \(argumentsString) | \(pipePath)") | ||
|
||
} else { | ||
print("Launching command: \(commandPath) \(argumentsString)") | ||
} | ||
|
||
task.launch() | ||
|
||
pipeProcess?.launch() | ||
|
||
task.waitUntilExit() | ||
|
||
guard task.terminationStatus == 0 else { | ||
throw TaskError.code(task.terminationStatus) | ||
} | ||
} | ||
|
||
enum TaskError: Error { | ||
case code(Int32) | ||
} | ||
|
||
enum Platform: String, CustomStringConvertible { | ||
case iOS_13 | ||
case iOS_12 | ||
case iOS_11 | ||
case iOS_10 | ||
|
||
var destination: String { | ||
switch self { | ||
case .iOS_13: | ||
return "platform=iOS Simulator,OS=13.3,name=iPhone 11 Pro" | ||
case .iOS_12: | ||
return "platform=iOS Simulator,OS=12.4,name=iPhone Xs" | ||
case .iOS_11: | ||
return "platform=iOS Simulator,OS=11.4,name=iPhone X" | ||
case .iOS_10: | ||
return "platform=iOS Simulator,OS=10.3.1,name=iPhone 7" | ||
} | ||
} | ||
|
||
var description: String { | ||
return rawValue | ||
} | ||
} | ||
|
||
enum Task: String, CustomStringConvertible { | ||
case spm | ||
case xcode | ||
|
||
var workspace: String? { | ||
switch self { | ||
case .xcode: | ||
return "Example/Stagehand.xcworkspace" | ||
case .spm: | ||
return nil | ||
} | ||
} | ||
|
||
var project: String? { | ||
switch self { | ||
case .spm: | ||
return "generated/Stagehand.xcodeproj" | ||
case .xcode: | ||
return nil | ||
} | ||
} | ||
|
||
var scheme: String { | ||
switch self { | ||
case .xcode: | ||
return "Stagehand Demo App" | ||
case .spm: | ||
return "Stagehand-Package" | ||
} | ||
} | ||
|
||
var shouldGenerateXcodeProject: Bool { | ||
switch self { | ||
case .spm: | ||
return true | ||
case .xcode: | ||
return false | ||
} | ||
} | ||
|
||
var shouldRunTests: Bool { | ||
switch self { | ||
case .spm: | ||
return false | ||
case .xcode: | ||
return true | ||
} | ||
} | ||
|
||
var description: String { | ||
return rawValue | ||
} | ||
} | ||
|
||
guard CommandLine.arguments.count > 2 else { | ||
print("Usage: build.swift [spm|xcode] <platform>") | ||
throw TaskError.code(1) | ||
} | ||
|
||
let rawTask = CommandLine.arguments[1] | ||
let rawPlatform = CommandLine.arguments[2] | ||
|
||
guard let task = Task(rawValue: rawTask) else { | ||
print("Received unknown task \"\(rawTask)\"") | ||
throw TaskError.code(1) | ||
} | ||
|
||
if task.shouldGenerateXcodeProject { | ||
try execute(commandPath: "/usr/bin/swift", arguments: ["package", "generate-xcodeproj", "--output=generated/"]) | ||
} | ||
|
||
guard let platform = Platform(rawValue: rawPlatform) else { | ||
print("Received unknown platform \"\(rawPlatform)\"") | ||
throw TaskError.code(1) | ||
} | ||
|
||
var xcodeBuildArguments: [String] = [] | ||
|
||
if let workspace = task.workspace { | ||
xcodeBuildArguments.append("-workspace") | ||
xcodeBuildArguments.append(workspace) | ||
} else if let project = task.project { | ||
xcodeBuildArguments.append("-project") | ||
xcodeBuildArguments.append(project) | ||
} | ||
|
||
xcodeBuildArguments.append( | ||
contentsOf: [ | ||
"-scheme", task.scheme, | ||
"-sdk", "iphonesimulator", | ||
"-PBXBuildsContinueAfterErrors=0", | ||
"-destination", platform.destination, | ||
"ONLY_ACTIVE_ARCH=NO", | ||
] | ||
) | ||
|
||
xcodeBuildArguments.append("build") | ||
|
||
if task.shouldRunTests { | ||
xcodeBuildArguments.append("test") | ||
} | ||
|
||
let xcpretty: Process? | ||
if CommandLine.arguments.count > 3 { | ||
xcpretty = .init() | ||
xcpretty?.launchPath = CommandLine.arguments[3] | ||
} else { | ||
xcpretty = nil | ||
} | ||
|
||
try execute(commandPath: "/usr/bin/xcodebuild", arguments: xcodeBuildArguments, pipedTo: xcpretty) |
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,22 @@ | ||
#!/bin/bash -l | ||
set -e | ||
|
||
# Find the directory in which this script resides. | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
|
||
actionstr=$(echo $ACTIONS | tr "," "\n") | ||
for action in $actionstr ; do | ||
case $action in | ||
xcode) | ||
$DIR/build.swift xcode $PLATFORM `which xcpretty` | ||
;; | ||
|
||
spm) | ||
$DIR/build.swift spm $PLATFORM | ||
;; | ||
|
||
pod-lint) | ||
bundle exec --gemfile=Example/Gemfile pod lib lint --verbose --fail-fast | ||
;; | ||
esac | ||
done |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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