Skip to content

Commit

Permalink
added upload command
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Feb 25, 2020
1 parent 70c0ffd commit c63cf3a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Sources/ReleaseTools/Commands/NotarizeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class NotarizeCommand: RTCommand {
}

shell.log("Creating archive for notarization.")
let exportedAppPath = exportURL.appendingPathComponent(archive.name)
let ditto = DittoRunner(shell: shell)

let zipResult = try ditto.zip(exportedAppPath, as: exportedZipURL)
let zipResult = try ditto.zip(exportedAppURL, as: exportedZipURL)
if zipResult.status != 0 {
return Result.exportFailed.adding(runnerResult: zipResult)
}
Expand Down
54 changes: 54 additions & 0 deletions Sources/ReleaseTools/Commands/UploadCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Created by Sam Deane on 25/02/20.
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import Foundation
import CommandShell
import Runner

extension Result {
static let uploadingFailed = Result(620, "Uploading failed.")
static let savingUploadReceiptFailed = Result(621, "Saving upload receipt failed.")
}

class UploadCommand: RTCommand {

override var description: Command.Description {
return Description(
name: "upload",
help: "Upload the archived app to Apple Connect portal for processing.",
usage: ["[\(userOption) [\(setDefaultOption)]] [\(platformOption)]"],
options: [
platformOption: platformOptionHelp,
userOption: userOptionHelp,
setDefaultOption: setDefaultOptionHelp
],
returns: [.uploadingFailed, .savingUploadReceiptFailed]
)
}

override func run(shell: Shell) throws -> Result {

let gotRequirements = require([.workspace, .user, .archive, .scheme])
guard gotRequirements == .ok else {
return gotRequirements
}

shell.log("Uploading archive to Apple Connect.")
let xcrun = XCRunRunner(shell: shell)
let result = try xcrun.run(arguments: ["altool", "--upload-app", "--username", user, "--password", "@keychain:AC_PASSWORD", "--file", exportedIPAURL.path, "--output-format", "xml"])
if result.status != 0 {
return Result.uploadingFailed.adding(runnerResult: result)
}

shell.log("Finished uploading.")
do {
try result.stdout.write(to: uploadingReceiptURL, atomically: true, encoding: .utf8)
} catch {
return Result.savingUploadReceiptFailed.adding(supplementary: "\(error)")
}

return .ok
}
}
6 changes: 6 additions & 0 deletions Sources/ReleaseTools/RTCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ class RTCommand: Command {
let rootURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)

var exportedZipURL: URL { return exportURL.appendingPathComponent("exported.zip") }

var exportedAppURL: URL { return exportURL.appendingPathComponent(archive.name) }
var exportedIPAURL: URL { return exportURL.appendingPathComponent(scheme).appendingPathExtension("ipa") }

var notarizingReceiptURL: URL { return exportURL.appendingPathComponent("receipt.xml") }

var uploadingReceiptURL: URL { return exportURL.appendingPathComponent("receipt.xml") }

var buildURL: URL {
return rootURL.appendingPathComponents([".build", platform])
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ let shell = Shell(commands: [
NotarizeCommand(),
PublishCommand(),
UpdateBuildCommand(),
WaitForNotarizationCommand()
UploadCommand(),
WaitForNotarizationCommand(),
]
)

Expand Down

0 comments on commit c63cf3a

Please sign in to comment.