Add hidden option to generate_appcast to set max CDATA threshold (#2075)

This commit is contained in:
Zorg authored and GitHub committed 2022-01-22 20:58:53 -08:00
1 parent 9e45a78e6f
commit 89e20a490d
3 files changed
+19 -16

No files matched your search

+8 -11
View File
@@ -5,9 +5,6 @@
import Foundation
// CDATA text must contain less characters than this threshold
let CDATA_HTML_FRAGMENT_THRESHOLD = 1000
class DeltaUpdate {
let fromVersion: String
let archivePath: URL
@@ -199,9 +196,9 @@ class ArchiveItem: CustomStringConvertible {
return releaseNotes
}
private func getReleaseNotesAsHTMLFragment(_ path: URL) -> String? {
private func getReleaseNotesAsHTMLFragment(_ path: URL, _ maxCDATAThreshold: Int) -> String? {
if let html = try? String(contentsOf: path) {
if html.utf8.count < CDATA_HTML_FRAGMENT_THRESHOLD &&
if html.utf8.count <= maxCDATAThreshold &&
!html.localizedCaseInsensitiveContains("<!DOCTYPE") &&
!html.localizedCaseInsensitiveContains("<body") {
return html
@@ -209,20 +206,20 @@ class ArchiveItem: CustomStringConvertible {
}
return nil
}
var releaseNotesHTML: String? {
func releaseNotesHTML(maxCDATAThreshold: Int) -> String? {
if let path = self.releaseNotesPath {
return self.getReleaseNotesAsHTMLFragment(path)
return self.getReleaseNotesAsHTMLFragment(path, maxCDATAThreshold)
}
return nil
}
var releaseNotesURL: URL? {
func releaseNotesURL(maxCDATAThreshold: Int) -> URL? {
guard let path = self.releaseNotesPath else {
return nil
}
// The file is already used as inline description
if self.getReleaseNotesAsHTMLFragment(path) != nil {
if self.getReleaseNotesAsHTMLFragment(path, maxCDATAThreshold) != nil {
return nil
}
return self.releaseNoteURL(for: path.lastPathComponent)
+3 -3
View File
@@ -49,7 +49,7 @@ func extractVersion(parent: XMLNode) -> String? {
return nil
}
func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem], newVersions: Set<String>?, maxNewVersionsInFeed: Int, fullReleaseNotesLink: String?, link: String?, newChannel: String?, majorVersion: String?, phasedRolloutInterval: Int?, criticalUpdateVersion: String?, informationalUpdateVersions: [String]?) throws -> (numNewUpdates: Int, numExistingUpdates: Int) {
func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem], newVersions: Set<String>?, maxNewVersionsInFeed: Int, fullReleaseNotesLink: String?, maxCDATAThreshold: Int, link: String?, newChannel: String?, majorVersion: String?, phasedRolloutInterval: Int?, criticalUpdateVersion: String?, informationalUpdateVersions: [String]?) throws -> (numNewUpdates: Int, numExistingUpdates: Int) {
let appBaseName = updates[0].appPath.deletingPathExtension().lastPathComponent
let sparkleNS = "http://www.andymatuschak.org/xml-namespaces/sparkle"
@@ -232,7 +232,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem], newVersions: Set
}
shortVersionElement?.setChildren([text(update.shortVersion)])
if let html = update.releaseNotesHTML {
if let html = update.releaseNotesHTML(maxCDATAThreshold: maxCDATAThreshold) {
let descElement = findOrCreateElement(name: "description", parent: item)
let cdata = XMLNode(kind: .text, options: .nodeIsCDATA)
cdata.stringValue = html
@@ -260,7 +260,7 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem], newVersions: Set
.contains(where: { $0.name == SUXMLLanguage }) }
let relElement = results?.first
if let url = update.releaseNotesURL {
if let url = update.releaseNotesURL(maxCDATAThreshold: maxCDATAThreshold) {
// The update includes a valid release notes URL
if let existingReleaseNotesElement = relElement {
// The existing item includes a release notes element. Update it.
+8 -2
View File
@@ -46,6 +46,8 @@ func loadPrivateKeys(_ account: String, _ privateDSAKey: SecKey?, _ privateEdStr
return PrivateKeys(privateDSAKey: privateDSAKey, privateEdKey: privateEdKey, publicEdKey: publicEdKey)
}
let DEFAULT_MAX_CDATA_THRESHOLD = 1000
struct GenerateAppcast: ParsableCommand {
static let programName = "generate_appcast"
static let programNamePath: String = CommandLine.arguments.first ?? "./\(programName)"
@@ -123,6 +125,10 @@ struct GenerateAppcast: ParsableCommand {
@Flag(help: .hidden)
var verbose: Bool = false
// CDATA text must contain <= this number of characters
@Option(name: .customLong("max-cdata-threshold"), help: .hidden)
var maxCDATAThreshold: Int = DEFAULT_MAX_CDATA_THRESHOLD
static var configuration = CommandConfiguration(
abstract: "Generate appcast from a directory of Sparkle update archives.",
discussion: """
@@ -132,7 +138,7 @@ struct GenerateAppcast: ParsableCommand {
Old entries in the appcast are kept intact. Otherwise, a new appcast file will be generated and written.
.html files that have the same filename as an archive (except for the file extension) will be used for release notes for that item.
If the contents of these files are short (< \(CDATA_HTML_FRAGMENT_THRESHOLD) characters) and do not include a DOCTYPE or body tags, they will be treated as embedded CDATA release notes.
If the contents of these files are short (< \(DEFAULT_MAX_CDATA_THRESHOLD) characters) and do not include a DOCTYPE or body tags, they will be treated as embedded CDATA release notes.
For new update entries, Sparkle infers the minimum system OS requirement based on your update's LSMinimumSystemVersion provided
by your application's Info.plist. If none is found, \(programName) defaults to Sparkle's own minimum system requirement (macOS 10.11).
@@ -242,7 +248,7 @@ struct GenerateAppcast: ParsableCommand {
relativeTo: archivesSourceDir)
// Write the appcast
let (numNewUpdates, numExistingUpdates) = try writeAppcast(appcastDestPath: appcastDestPath, updates: updates, newVersions: versions, maxNewVersionsInFeed: maxNewVersionsInFeed, fullReleaseNotesLink: fullReleaseNotesURL, link: link, newChannel: channel, majorVersion: majorVersion, phasedRolloutInterval: phasedRolloutInterval, criticalUpdateVersion: criticalUpdateVersion, informationalUpdateVersions: informationalUpdateVersions)
let (numNewUpdates, numExistingUpdates) = try writeAppcast(appcastDestPath: appcastDestPath, updates: updates, newVersions: versions, maxNewVersionsInFeed: maxNewVersionsInFeed, fullReleaseNotesLink: fullReleaseNotesURL, maxCDATAThreshold: maxCDATAThreshold, link: link, newChannel: channel, majorVersion: majorVersion, phasedRolloutInterval: phasedRolloutInterval, criticalUpdateVersion: criticalUpdateVersion, informationalUpdateVersions: informationalUpdateVersions)
// Inform the user, pluralizing "update" if necessary
let pluralizeUpdates = { $0 == 1 ? "update" : "updates" }