Skip to content

Commit

Permalink
Update Toolbox for new Templates (#410)
Browse files Browse the repository at this point in the history
* Update Swift version

* Add deprecation notices to most commands

* Crude check for executable name in manifest

* Fix warning

* File fixes

* Update test.yml Swift version

* Update CI
  • Loading branch information
0xTim authored Apr 30, 2023
1 parent 6000cc5 commit 3e11f77
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- --leaf
- --no-leaf
os: [ubuntu-latest]
image: ["swift:5.6-focal"]
image: ["swift:5.8-focal"]
runs-on: ${{ matrix.os }}
container: ${{ matrix.image }}
steps:
Expand All @@ -44,7 +44,7 @@ jobs:
environments: ${{ steps.output.outputs.environments }}
steps:
- id: output
run: echo "::set-output name=environments::[{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.4-focal\", \"toolchain\":null},{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.6-focal\", \"toolchain\":null},{\"os\":\"macos-11\", \"image\":null, \"toolchain\":\"latest\"}]"
run: echo "::set-output name=environments::[{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.6-focal\", \"toolchain\":null},{\"os\":\"ubuntu-latest\", \"image\":\"swift:5.8-focal\", \"toolchain\":null},{\"os\":\"macos-13\", \"image\":null, \"toolchain\":\"latest\"}]"

test-toolbox:
needs: createJSON
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ DerivedData
.swiftpm
Tests/LinuxMain.swift
Package.resolved
.vscode
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.4
// swift-tools-version:5.6
import PackageDescription

let package = Package(
Expand All @@ -25,7 +25,7 @@ let package = Package(
.testTarget(name: "VaporToolboxTests", dependencies: [
.target(name: "VaporToolbox"),
]),
.target(name: "Executable", dependencies: [
.executableTarget(name: "Executable", dependencies: [
.target(name: "VaporToolbox"),
]),
]
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ struct Build: AnyCommand {
let help = "Builds an app in the console."

func run(using context: inout CommandContext) throws {
context.console.warning("This command is deprecated. Use `swift build` instead.")

context.console.output("Building project...")

var flags = [String]()
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Clean.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Cleaner {
}

func run() throws {
ctx.console.warning("This command is deprecated. Use `swift package clean` instead.")

var ops: [(String, () throws -> CleanResult)] = []
ops.append((".build", cleanBuildFolder))
ops.append(("Package.resolved", cleanPackageResolved))
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Heroku/HerokuInit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ struct HerokuInit: Command {
let help = "Configures app for deployment to Heroku."

func run(using ctx: CommandContext, signature: Signature) throws {
ctx.console.warning("This command is deprecated. Use `heroku init` instead.")

// Get Swift package name
let name = try Process.swift.package.dump().name
ctx.console.list(key: "Package", value: name)
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Heroku/HerokuPush.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct HerokuPush: Command {
let help = "Deploys app to Heroku."

func run(using context: CommandContext, signature: Signature) throws {
context.console.warning("This command is deprecated. Use `git push heroku <branch>` instead.")

// Get Swift package name
let name = try Process.swift.package.dump().name
context.console.list(key: "Package", value: name)
Expand Down
35 changes: 33 additions & 2 deletions Sources/VaporToolbox/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import Foundation

// Generates an Xcode project
struct Run: AnyCommand {
let help = "Runs an app from the console.\nEquivalent to `swift run Run`.\nThe --enable-test-discovery flag is automatically set if needed."
let help = "Runs an app from the console.\nEquivalent to `swift run App`.\nThe --enable-test-discovery flag is automatically set if needed."

func run(using context: inout CommandContext) throws {
context.console.warning("This command is deprecated. Use `swift run App` instead.")

var flags = [String]()
if isEnableTestDiscoveryFlagNeeded() {
flags.append("--enable-test-discovery")
Expand All @@ -15,7 +17,36 @@ struct Run: AnyCommand {
if let confirmOverride = context.console.confirmOverride {
extraArguments.append(confirmOverride ? "--yes" : "--no")
}
try exec(Process.shell.which("swift"), ["run"] + flags + ["Run"] + context.input.arguments + extraArguments)

let appName: String

let filename = "Package.swift"
let urlString = FileManager.default.currentDirectoryPath.trailingSlash.appendingPathComponents(filename)
let manifestContents: String

guard let url = URL(string: "file://\(urlString)") else {
throw "Invalid URL: \(urlString)"
}

context.console.info("Reading file at \(urlString)")

do {
manifestContents = try String(contentsOf: url, encoding: .utf8)
} catch {
context.console.error("Failed to read manifest - are you in the correct directory?")
context.console.error("\(error)")
return
}

if manifestContents.contains(".executableTarget(name: \"Run\"") {
appName = "Run"
} else {
appName = "App"
}

context.console.info("Running \(appName)...")

try exec(Process.shell.which("swift"), ["run"] + flags + [appName] + context.input.arguments + extraArguments)
}

func outputHelp(using context: inout CommandContext) {
Expand Down
4 changes: 3 additions & 1 deletion Sources/VaporToolbox/Supervisor/SupervisorInit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ struct SupervisorInit: Command {
}

func run(using context: CommandContext, signature: Signature) throws {
context.console.warning("This command is deprecated. Follow the docs for the latest instructions at https://docs.vapor.codes/deploy/supervisor/")

let package = try Process.swift.package.dump()
let cwd = FileManager.default.currentDirectoryPath
let user = NSUserName()
let config = SupervisorConfiguration(
program: package.name,
attributes: [
"command": "\(cwd)/.build/release/Run serve --env production",
"command": "\(cwd)/.build/release/App serve --env production",
"directory": cwd,
"user": user,
"stdout_logfile": "/var/log/supervisor/\(package.name)-stdout.log",
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Supervisor/SupervisorRestart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct SupervisorRestart: Command {
}

func run(using context: CommandContext, signature: Signature) throws {
context.console.warning("This command is deprecated. Use `supervisorctl restart <AppName>` instead.")

let package = try Process.swift.package.dump()
context.console.print("Restarting \(package.name).")
try Process.run(Process.shell.which("supervisorctl"), "restart", package.name)
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Supervisor/SupervisorUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct SupervisorUpdate: Command {
}

func run(using context: CommandContext, signature: Signature) throws {
context.console.warning("This command is deprecated. Use `supervisorctl update <AppName>` instead.")

let package = try Process.swift.package.dump()
try Process.run(Process.shell.which("supervisorctl"), "update", package.name)
context.console.info("Supervisor entry for \(package.name) updated.")
Expand Down
2 changes: 2 additions & 0 deletions Sources/VaporToolbox/Xcode/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ struct Xcode: Command {

/// See `Command`.
func run(using ctx: CommandContext, signature: Signature) throws {
ctx.console.warning("This command is deprecated. Use `open Package.swift` or `code .` instead.")

ctx.console.info("Opening project in Xcode.")
do {
#if os(macOS)
Expand Down

0 comments on commit 3e11f77

Please sign in to comment.