Merge pull request #1644 from oneeightyg/feature-1642-release-notes-url-prefix

Add —release-notes-url-prefix to generate_appcast
This commit is contained in:
Kornel authored and GitHub committed 2020-09-01 22:13:13 +01:00
commit 7ea72a2af4
2 files changed
+36 -8

No files matched your search

+6 -1
View File
@@ -48,6 +48,7 @@ class ArchiveItem: CustomStringConvertible {
var dsaSignature: String?
var edSignature: String?
var downloadUrlPrefix: URL?
var releaseNotesURLPrefix: URL?
init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws {
self.version = version
@@ -188,7 +189,11 @@ class ArchiveItem: CustomStringConvertible {
guard let escapedFilename = path.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else {
return nil
}
if let relative = self.feedURL {
if let releaseNotesURLPrefix = self.releaseNotesURLPrefix {
// If a URL prefix for release notes was passed on the command-line, use it
return URL(string: escapedFilename, relativeTo: releaseNotesURLPrefix)
} else if let relative = self.feedURL {
return URL(string: escapedFilename, relativeTo: relative)
}
return URL(string: escapedFilename)
+30 -7
View File
@@ -34,7 +34,8 @@ func printHelp() {
"\t-n: provide the name of the private DSA key. This option has to be used together with `-k`\n",
"\t-k: provide the name of the keychain. This option has to be used together with `-n`\n",
"\t-s: provide the path to the private EdDSA key\n",
"\t--download-url-prefix: provide a static url that will be used as prefix for the url from where updates will be downloaded\n"
"\t--download-url-prefix: provide a prefix used to construct URLs for update downloads\n",
"\t--release-notes-url-prefix: provide a prefix used to construct URLs for release notes\n"
)
}
@@ -78,7 +79,7 @@ func loadPrivateKeys(_ privateDSAKey: SecKey?, _ privateEdString: String?) -> Pr
/**
* Parses all possible command line options and returns the values in a tuple.
*/
func parseCommandLineOptions(argumentList: [String]) -> (privateDSAKey: SecKey?, privateEdString: String?, downloadUrlPrefix: URL?, archivesSourceDir: URL) {
func parseCommandLineOptions(argumentList: [String]) -> (privateDSAKey: SecKey?, privateEdString: String?, downloadUrlPrefix: URL?, releaseNotesURLPrefix: URL?, archivesSourceDir: URL) {
// if the option `-h` is in the argument list print the help dialog
if argumentList.contains("-h") {
printHelp()
@@ -94,6 +95,7 @@ func parseCommandLineOptions(argumentList: [String]) -> (privateDSAKey: SecKey?,
var privateDSAKey: SecKey?
var privateEdString: String?
var downloadUrlPrefix: URL?
var releaseNotesURLPrefix: URL?
var archivesSourceDir: URL
// check if the private dsa key option is present
@@ -174,6 +176,21 @@ func parseCommandLineOptions(argumentList: [String]) -> (privateDSAKey: SecKey?,
arguments.remove(at: downloadUrlPrefixOptionIndex + 1)
arguments.remove(at: downloadUrlPrefixOptionIndex)
}
// Check if a URL prefix was specified for the release notes
if let releaseNotesURLPrefixOptionIndex = arguments.firstIndex(of: "--release-notes-url-prefix") {
if releaseNotesURLPrefixOptionIndex + 1 >= arguments.count {
print("Foo few arguments were given")
exit(1)
}
// Get the URL prefix for the release notes
releaseNotesURLPrefix = URL(string: arguments[releaseNotesURLPrefixOptionIndex + 1])
// Remove the parsed argument
arguments.remove(at: releaseNotesURLPrefixOptionIndex + 1)
arguments.remove(at: releaseNotesURLPrefixOptionIndex)
}
// now that all command line options have been removed from the arguments array
// there should only be the path to the private DSA key (if provided) path to the archives dir left
@@ -195,7 +212,7 @@ func parseCommandLineOptions(argumentList: [String]) -> (privateDSAKey: SecKey?,
// now only the archives source dir is left
archivesSourceDir = URL(fileURLWithPath: arguments[0], isDirectory: true)
return (privateDSAKey, privateEdString, downloadUrlPrefix, archivesSourceDir)
return (privateDSAKey, privateEdString, downloadUrlPrefix, releaseNotesURLPrefix, archivesSourceDir)
}
func main() {
@@ -208,20 +225,26 @@ func main() {
var privateDSAKey: SecKey?
var privateEdString: String?
var downloadUrlPrefix: URL?
var releaseNotesURLPrefix: URL?
var archivesSourceDir: URL
(privateDSAKey, privateEdString, downloadUrlPrefix, archivesSourceDir) = parseCommandLineOptions(argumentList: args)
(privateDSAKey, privateEdString, downloadUrlPrefix, releaseNotesURLPrefix, archivesSourceDir) = parseCommandLineOptions(argumentList: args)
let keys = loadPrivateKeys(privateDSAKey, privateEdString)
do {
let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose: verbose)
// if a download url prefix was provided set it for each archive item
if downloadUrlPrefix != nil {
// If a URL prefix was provided, set on the archive items
if downloadUrlPrefix != nil || releaseNotesURLPrefix != nil {
for (_, archiveItems) in allUpdates {
for archiveItem in archiveItems {
archiveItem.downloadUrlPrefix = downloadUrlPrefix
if downloadUrlPrefix != nil {
archiveItem.downloadUrlPrefix = downloadUrlPrefix
}
if releaseNotesURLPrefix != nil {
archiveItem.releaseNotesURLPrefix = releaseNotesURLPrefix
}
}
}
}