Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions AppUpdater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -755,13 +755,18 @@ struct Release: Decodable, Comparable {
}
}

/// The DMG named `<repo>-<version>.dmg` for this release. The version in
/// the name is parsed the way the tag is, so `MyApp-2.1.dmg` matches a
/// `v2.1` tag even though the tag prints as `2.1.0`.
func viableAsset(forRepo repo: String) -> Asset? {
assets.first { asset in
let prefix = "\(repo.lowercased())-\(tagName)"
let prefix = "\(repo.lowercased())-"
return assets.first { asset in
let name = (asset.name as NSString).deletingPathExtension
.lowercased()
Comment thread
mxcl marked this conversation as resolved.

return name == prefix && asset.contentType == .dmg
guard asset.contentType == .dmg, name.hasPrefix(prefix) else {
return false
}
return Version(tolerant: name.dropFirst(prefix.count)) == tagName
}
}

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ $ ditto "$SWIFT_BIN/AppUpdater_AppUpdater.bundle" \
## Release layout

AppUpdater only accepts DMG assets. Name each asset
`<repository>-<semantic-version>.dmg`, for example `MyApp-2.1.0.dmg`.
`<repository>-<version>.dmg`, for example `MyApp-2.1.0.dmg`. The version is
read the way the tag is, so a `v2.1` release may name its asset `MyApp-2.1.dmg`.

The mounted DMG must contain one top-level app. Its filename must match the
installed app, including case. A release for `MyApp.app` therefore contains:
Expand Down
44 changes: 43 additions & 1 deletion Tests/AppUpdaterTests/AppUpdaterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,46 @@ final class AppUpdaterTests: XCTestCase {
}
}

@MainActor
func testCheckMatchesAssetNamedWithShortVersion() async throws {
let releases = try [
release("v2.1", prerelease: false, assetName: "AppUpdater-2.1.dmg"),
]
let updater = AppUpdater(
owner: "mxcl",
repo: "AppUpdater",
currentVersion: { Version(2, 0, 0) },
fetchReleases: { releases },
prepareAsset: { asset in preparedUpdate(assetName: asset.name) }
)

let update = try await updater.check()

XCTAssertEqual(update?.version, "2.1.0")
XCTAssertEqual(update?.assetName, "AppUpdater-2.1.dmg")
}

@MainActor
func testCheckDoesNotMatchAssetForAnotherVersion() async throws {
let releases = try [
release("v2.1", prerelease: false, assetName: "AppUpdater-2.1.1.dmg"),
]
let updater = AppUpdater(
owner: "mxcl",
repo: "AppUpdater",
currentVersion: { Version(2, 0, 0) },
fetchReleases: { releases },
prepareAsset: { _ in
XCTFail("update should not run")
return preparedUpdate()
}
)

let update = try await updater.check()

XCTAssertNil(update)
}

@MainActor
func testCheckDoesNotUpdateWithoutMatchingAsset() async throws {
let releases = try [
Expand Down Expand Up @@ -1447,7 +1487,9 @@ final class AppUpdaterTests: XCTestCase {
}
""".data(using: .utf8)!

return try JSONDecoder().decode(Release.self, from: json)
let decoder = JSONDecoder()
decoder.userInfo[.decodingMethod] = DecodingMethod.tolerant
return try decoder.decode(Release.self, from: json)
}

private func temporaryDirectory() throws -> URL {
Expand Down
Loading