Add host argument to `dev` and `test` commands (#213)
* Add host argument to dev and test commands * Delete Brewfile.lock.json * Update swift.yml * Update Sources/CartonCLI/Commands/Dev.swift Co-authored-by: Max Desiatov <max@desiatov.com> * Update Sources/CartonCLI/Commands/Test.swift Co-authored-by: Max Desiatov <max@desiatov.com> Co-authored-by: Max Desiatov <max@desiatov.com>
This commit is contained in:
parent
fe272a95ce
commit
046ce7e106
|
@ -15,6 +15,7 @@ jobs:
|
|||
- name: Build on macOS 10.15 with Swift 5.2
|
||||
run: |
|
||||
sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer
|
||||
rm '/usr/local/bin/swiftlint'
|
||||
brew bundle
|
||||
swift build -c release --build-tests --enable-test-discovery
|
||||
swift test -c release --enable-test-discovery
|
||||
|
@ -29,6 +30,7 @@ jobs:
|
|||
- name: Build on macOS 11.0 with Swift 5.2
|
||||
run: |
|
||||
sudo xcode-select --switch /Applications/Xcode_11.7.app/Contents/Developer
|
||||
rm '/usr/local/bin/swiftlint'
|
||||
brew bundle
|
||||
swift build -c release --build-tests --enable-test-discovery
|
||||
swift test -c release --enable-test-discovery
|
||||
|
@ -43,6 +45,7 @@ jobs:
|
|||
- name: Build on macOS 10.15 with Swift 5.3
|
||||
run: |
|
||||
sudo xcode-select --switch /Applications/Xcode_12.app/Contents/Developer
|
||||
rm '/usr/local/bin/swiftlint'
|
||||
brew bundle
|
||||
swift build -c release --build-tests --enable-test-discovery
|
||||
swift test -c release --enable-test-discovery
|
||||
|
@ -57,6 +60,7 @@ jobs:
|
|||
- name: Build on macOS 11.0 with Swift 5.3
|
||||
run: |
|
||||
sudo xcode-select --switch /Applications/Xcode_12.2.app/Contents/Developer
|
||||
rm '/usr/local/bin/swiftlint'
|
||||
brew bundle
|
||||
swift build -c release --build-tests --enable-test-discovery
|
||||
swift test -c release --enable-test-discovery
|
||||
|
|
|
@ -1,127 +0,0 @@
|
|||
{
|
||||
"entries": {
|
||||
"brew": {
|
||||
"pre-commit": {
|
||||
"version": "2.9.3",
|
||||
"bottle": {
|
||||
"cellar": ":any",
|
||||
"prefix": "/usr/local",
|
||||
"files": {
|
||||
"big_sur": {
|
||||
"url": "https://homebrew.bintray.com/bottles/pre-commit-2.9.3.big_sur.bottle.tar.gz",
|
||||
"sha256": "81f18e83e858feffacc9a9441c836a2abcf5b1a880f09ee99a261f12ac8ceca7"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "https://homebrew.bintray.com/bottles/pre-commit-2.9.3.catalina.bottle.tar.gz",
|
||||
"sha256": "16977b9f715b4330e7975761edddbaad4b891b25e6c8e4c4186ca4e2e99b11e7"
|
||||
},
|
||||
"mojave": {
|
||||
"url": "https://homebrew.bintray.com/bottles/pre-commit-2.9.3.mojave.bottle.tar.gz",
|
||||
"sha256": "82af5cc062aed6375aff5dfc759bac2cbc549ae0709f1a720ec805368944b46e"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"swiftformat": {
|
||||
"version": "0.47.8",
|
||||
"bottle": {
|
||||
"cellar": ":any_skip_relocation",
|
||||
"prefix": "/usr/local",
|
||||
"files": {
|
||||
"big_sur": {
|
||||
"url": "https://homebrew.bintray.com/bottles/swiftformat-0.47.8.big_sur.bottle.tar.gz",
|
||||
"sha256": "47e3aa92792a53413eb0866d3b6709e88c7164184f406c3e49c560e82a2fe589"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "https://homebrew.bintray.com/bottles/swiftformat-0.47.8.catalina.bottle.tar.gz",
|
||||
"sha256": "c268a44da4ed4e7836d2b43f917a1411f3b8f13488ee25c66f4bd8bb2f4d5e05"
|
||||
},
|
||||
"mojave": {
|
||||
"url": "https://homebrew.bintray.com/bottles/swiftformat-0.47.8.mojave.bottle.tar.gz",
|
||||
"sha256": "38abb30c870974c65ee0a3afed11cd5f983ab05a13923061fc67c4b6566df6f8"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"swiftlint": {
|
||||
"version": "0.42.0",
|
||||
"bottle": {
|
||||
"cellar": ":any_skip_relocation",
|
||||
"prefix": "/usr/local",
|
||||
"files": {
|
||||
"big_sur": {
|
||||
"url": "https://homebrew.bintray.com/bottles/swiftlint-0.42.0.big_sur.bottle.tar.gz",
|
||||
"sha256": "1a0540f0ff6cac2da0a51672db7963aef71cc58954c34791e9b01dafd63c5898"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "https://homebrew.bintray.com/bottles/swiftlint-0.42.0.catalina.bottle.tar.gz",
|
||||
"sha256": "e9023ed754eb8cb78a9f2b469a90875ca42a7afffd3e96f8142252e81d889793"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"binaryen": {
|
||||
"version": "98",
|
||||
"bottle": {
|
||||
"cellar": ":any",
|
||||
"prefix": "/usr/local",
|
||||
"files": {
|
||||
"big_sur": {
|
||||
"url": "https://homebrew.bintray.com/bottles/binaryen-98.big_sur.bottle.tar.gz",
|
||||
"sha256": "5d5ac79ec3aabebd8e62433c84bd0d61b0f4ee44d56e4c4f47475276a6428bd8"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "https://homebrew.bintray.com/bottles/binaryen-98.catalina.bottle.tar.gz",
|
||||
"sha256": "260a8deac0c78a9fead982cf6d05fd818330bc4e28cdc73ecd5de6952ded6e8b"
|
||||
},
|
||||
"mojave": {
|
||||
"url": "https://homebrew.bintray.com/bottles/binaryen-98.mojave.bottle.tar.gz",
|
||||
"sha256": "7a68230a62307fbd61638803e942e4d556f99b8e4d6fbbdd3dbaf6997b3b2843"
|
||||
},
|
||||
"high_sierra": {
|
||||
"url": "https://homebrew.bintray.com/bottles/binaryen-98.high_sierra.bottle.tar.gz",
|
||||
"sha256": "4656a9b10a7db143e3619126ea1e0c169d05b06b27c7e75d5f641c86135c7b1f"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"wasmer": {
|
||||
"version": "0.16.2",
|
||||
"bottle": {
|
||||
"cellar": ":any_skip_relocation",
|
||||
"prefix": "/usr/local",
|
||||
"files": {
|
||||
"big_sur": {
|
||||
"url": "https://homebrew.bintray.com/bottles/wasmer-0.16.2.big_sur.bottle.tar.gz",
|
||||
"sha256": "63d91bbfece68628e7bb464cd8d3a90a6dc89344c4889ada157f174db62f05da"
|
||||
},
|
||||
"catalina": {
|
||||
"url": "https://homebrew.bintray.com/bottles/wasmer-0.16.2.catalina.bottle.tar.gz",
|
||||
"sha256": "751b4b059036dbca254eef935bc03240e1fd559465a376a0cff8f5a41dcd3980"
|
||||
},
|
||||
"mojave": {
|
||||
"url": "https://homebrew.bintray.com/bottles/wasmer-0.16.2.mojave.bottle.tar.gz",
|
||||
"sha256": "725d2b857e0954b1e2fd8a01021847e168d5daec33cd76c32f90a0ae12fdf422"
|
||||
},
|
||||
"high_sierra": {
|
||||
"url": "https://homebrew.bintray.com/bottles/wasmer-0.16.2.high_sierra.bottle.tar.gz",
|
||||
"sha256": "42ea898c1ebd9c0ac58bf21117c05df6a4726123590444c19173a01586c80c63"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"system": {
|
||||
"macos": {
|
||||
"big_sur": {
|
||||
"HOMEBREW_VERSION": "2.6.2",
|
||||
"HOMEBREW_PREFIX": "/usr/local",
|
||||
"Homebrew/homebrew-core": "386111a04c8f09f72c60548e519a3e27fade9c34",
|
||||
"CLT": "",
|
||||
"Xcode": "12.2",
|
||||
"macOS": "11.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,9 @@ struct Dev: ParsableCommand {
|
|||
@Option(name: .shortAndLong, help: "Set the HTTP port the development server will run on.")
|
||||
var port = 8080
|
||||
|
||||
@Option(name: .shortAndLong, help: "Set the location where the development server will run. Default is `127.0.0.1`.")
|
||||
var host = "127.0.0.1"
|
||||
|
||||
@Flag(name: .long, help: "Skip automatically opening app in system browser.")
|
||||
var skipAutoOpen = false
|
||||
|
||||
|
@ -108,6 +111,7 @@ struct Dev: ParsableCommand {
|
|||
verbose: verbose,
|
||||
skipAutoOpen: skipAutoOpen,
|
||||
port: port,
|
||||
host: host,
|
||||
customIndexContent: HTML.readCustomIndexPage(at: customIndexPage, on: localFileSystem),
|
||||
// swiftlint:disable:next force_try
|
||||
package: try! toolchain.package.get(),
|
||||
|
|
|
@ -60,6 +60,12 @@ struct Test: ParsableCommand {
|
|||
)
|
||||
var port = 8080
|
||||
|
||||
@Option(
|
||||
name: .shortAndLong,
|
||||
help: "Set the location where the testing server will run. Default is `127.0.0.1`."
|
||||
)
|
||||
var host = "127.0.0.1"
|
||||
|
||||
func run() throws {
|
||||
let terminal = InteractiveWriter.stdout
|
||||
|
||||
|
@ -87,6 +93,7 @@ struct Test: ParsableCommand {
|
|||
verbose: true,
|
||||
skipAutoOpen: false,
|
||||
port: port,
|
||||
host: host,
|
||||
customIndexContent: nil,
|
||||
// swiftlint:disable:next force_try
|
||||
package: try! toolchain.package.get(),
|
||||
|
|
|
@ -20,6 +20,7 @@ import Vapor
|
|||
extension Application {
|
||||
struct Configuration {
|
||||
let port: Int
|
||||
let host: String
|
||||
let mainWasmPath: AbsolutePath
|
||||
let customIndexContent: String?
|
||||
let package: SwiftToolchain.Package
|
||||
|
@ -31,6 +32,7 @@ extension Application {
|
|||
|
||||
func configure(with configuration: Configuration) {
|
||||
http.server.configuration.port = configuration.port
|
||||
http.server.configuration.hostname = configuration.host
|
||||
|
||||
let directory = FileManager.default.homeDirectoryForCurrentUser
|
||||
.appendingPathComponent(".carton")
|
||||
|
|
|
@ -81,6 +81,7 @@ public final class Server {
|
|||
let verbose: Bool
|
||||
let skipAutoOpen: Bool
|
||||
let port: Int
|
||||
let host: String
|
||||
let customIndexContent: String?
|
||||
let package: SwiftToolchain.Package
|
||||
let product: Product?
|
||||
|
@ -92,6 +93,7 @@ public final class Server {
|
|||
verbose: Bool,
|
||||
skipAutoOpen: Bool,
|
||||
port: Int,
|
||||
host: String,
|
||||
customIndexContent: String?,
|
||||
package: SwiftToolchain.Package,
|
||||
product: Product?,
|
||||
|
@ -102,6 +104,7 @@ public final class Server {
|
|||
self.verbose = verbose
|
||||
self.skipAutoOpen = skipAutoOpen
|
||||
self.port = port
|
||||
self.host = host
|
||||
self.customIndexContent = customIndexContent
|
||||
self.package = package
|
||||
self.product = product
|
||||
|
@ -123,7 +126,7 @@ public final class Server {
|
|||
name: configuration.verbose ? "development" : "production",
|
||||
arguments: ["vapor"]
|
||||
)
|
||||
localURL = "http://127.0.0.1:\(configuration.port)/"
|
||||
localURL = "http://\(configuration.host):\(configuration.port)/"
|
||||
skipAutoOpen = configuration.skipAutoOpen
|
||||
|
||||
try LoggingSystem.bootstrap(from: &env)
|
||||
|
@ -131,6 +134,7 @@ public final class Server {
|
|||
app.configure(
|
||||
with: .init(
|
||||
port: configuration.port,
|
||||
host: configuration.host,
|
||||
mainWasmPath: configuration.mainWasmPath,
|
||||
customIndexContent: configuration.customIndexContent,
|
||||
package: configuration.package,
|
||||
|
|
|
@ -23,6 +23,7 @@ extension DevCommandTests: Testable {}
|
|||
|
||||
final class DevCommandTests: XCTestCase {
|
||||
private var client: HTTPClient?
|
||||
private var process: Process?
|
||||
|
||||
override func tearDown() {
|
||||
try? client?.syncShutdown()
|
||||
|
@ -32,15 +33,6 @@ final class DevCommandTests: XCTestCase {
|
|||
func testWithNoArguments() throws {
|
||||
let url = "http://127.0.0.1:8080"
|
||||
|
||||
// client time out for connecting and responding
|
||||
let timeOut: Int64 = 60
|
||||
|
||||
// client delay... let the server start up
|
||||
let delay: UInt32 = 30
|
||||
|
||||
// only try 5 times.
|
||||
let polls = 5
|
||||
|
||||
// the directory was built using `carton init --template tokamak`
|
||||
let package = "Milk"
|
||||
let packageDirectory = testFixturesDirectory.appending(component: package)
|
||||
|
@ -51,6 +43,59 @@ final class DevCommandTests: XCTestCase {
|
|||
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
|
||||
guard let process = executeCommand(
|
||||
command: "carton dev --verbose",
|
||||
cwd: packageDirectory.url
|
||||
) else {
|
||||
XCTFail("Could not create process")
|
||||
return
|
||||
}
|
||||
self.process = process
|
||||
|
||||
checkForExpectedContent(at: url)
|
||||
|
||||
// clean up
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
}
|
||||
|
||||
func testWithArguments() throws {
|
||||
let url = "http://0.0.0.0:8081"
|
||||
|
||||
// the directory was built using `carton init --template tokamak`
|
||||
let package = "Milk"
|
||||
let packageDirectory = testFixturesDirectory.appending(component: package)
|
||||
XCTAssertTrue(
|
||||
packageDirectory.exists,
|
||||
"\(package) directory does not exist. Cannot execute tests."
|
||||
)
|
||||
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
|
||||
guard let process = executeCommand(
|
||||
command: "carton dev --verbose --port 8081 --host 0.0.0.0",
|
||||
cwd: packageDirectory.url
|
||||
) else {
|
||||
XCTFail("Could not create process")
|
||||
return
|
||||
}
|
||||
self.process = process
|
||||
|
||||
checkForExpectedContent(at: url)
|
||||
|
||||
// clean up
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
}
|
||||
|
||||
func checkForExpectedContent(at url: String) {
|
||||
// client time out for connecting and responding
|
||||
let timeOut: Int64 = 60
|
||||
|
||||
// client delay... let the server start up
|
||||
let delay: UInt32 = 30
|
||||
|
||||
// only try 5 times.
|
||||
let polls = 5
|
||||
|
||||
let expectedHtml =
|
||||
"""
|
||||
<html>
|
||||
|
@ -64,14 +109,6 @@ final class DevCommandTests: XCTestCase {
|
|||
</html>
|
||||
"""
|
||||
|
||||
guard let process = executeCommand(
|
||||
command: "carton dev --verbose",
|
||||
cwd: packageDirectory.url
|
||||
) else {
|
||||
XCTFail("Could not create process")
|
||||
return
|
||||
}
|
||||
|
||||
let timeout = HTTPClient.Configuration.Timeout(
|
||||
connect: .seconds(timeOut),
|
||||
read: .seconds(timeOut)
|
||||
|
@ -91,7 +128,7 @@ final class DevCommandTests: XCTestCase {
|
|||
} while count < polls && response == nil
|
||||
|
||||
// end the process regardless of success
|
||||
process.terminate()
|
||||
process?.terminate()
|
||||
|
||||
if let response = response {
|
||||
XCTAssertTrue(response.status == .ok, "Response was not ok")
|
||||
|
@ -102,7 +139,7 @@ final class DevCommandTests: XCTestCase {
|
|||
return
|
||||
}
|
||||
guard let actualHtml = String(data: data, encoding: .utf8) else {
|
||||
XCTFail("Could convert data to string")
|
||||
XCTFail("Could not convert data to string")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -113,8 +150,5 @@ final class DevCommandTests: XCTestCase {
|
|||
print("no response from server after \(count) tries or \(Int(count) * Int(delay)) seconds")
|
||||
XCTFail("Could not reach server")
|
||||
}
|
||||
|
||||
// clean up
|
||||
do { try packageDirectory.appending(component: ".build").delete() } catch {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue