From 5cde8beacd1dcc370ed0d93558b03480d753ff8a Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 8 Apr 2024 13:20:35 +1000 Subject: [PATCH 1/3] Require macOS 12 in `Package.swift` to satisfy SwiftLint requirement `swift build` failed with: > error: the library 'WordPressShared' requires macos 10.13, but depends on the product 'SwiftLintPlugin' which requires macos 12.0; consider changing the library 'WordPressShared' to require macos 12.0 or later, or the product 'SwiftLintPlugin' to require macos 10.13 or earlier. --- Package.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.swift b/Package.swift index 263da84..5e19286 100644 --- a/Package.swift +++ b/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let package = Package( name: "WordPressShared", - platforms: [.iOS(.v13)], + platforms: [.iOS(.v13), .macOS(.v12)], products: [ .library(name: "WordPressShared", targets: ["WordPressShared"]) ], From e61824cb4a235d9cbe95257aa424447e5d4d9ad9 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 8 Apr 2024 13:21:44 +1000 Subject: [PATCH 2/3] Print SwiftLint config path during error handling --- Package.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index 5e19286..78fe677 100644 --- a/Package.swift +++ b/Package.swift @@ -63,10 +63,12 @@ let package = Package( ) func loadSwiftLintVersion() -> Version { - guard let yamlString = try? String(contentsOf: URL(fileURLWithPath: #file) + let swiftLintConfigURL = URL(fileURLWithPath: #file) .deletingLastPathComponent() - .appendingPathComponent(".swiftlint.yml")) else { - fatalError("Failed to read YAML file.") + .appendingPathComponent(".swiftlint.yml") + + guard let yamlString = try? String(contentsOf: swiftLintConfigURL) else { + fatalError("Failed to read SwiftLint config file at \(swiftLintConfigURL).") } guard let versionLine = yamlString.components(separatedBy: .newlines) From 8969098cefdb2dbca7d25b2c40d92e14e2ce13e1 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 12 Apr 2024 10:02:52 +1000 Subject: [PATCH 3/3] Use Swift 5.10 toolchain --- .buildkite/pipeline.yml | 2 +- Package.swift | 4 ++-- Sources/WordPressShared/Utility/NSDate+Helpers.swift | 9 ++------- Tests/WordPressSharedTests/NSDateHelperTest.swift | 12 ++++++++---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index c1eb62d..25425ac 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -3,7 +3,7 @@ common_params: plugins: &common_plugins - automattic/a8c-ci-toolkit#3.1.0 env: &common_env - IMAGE_ID: xcode-15.0.1 + IMAGE_ID: xcode-15.3-v3 # This is the default pipeline – it will build and test the pod steps: diff --git a/Package.swift b/Package.swift index 78fe677..10231c9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.5 +// swift-tools-version:5.10 import Foundation import PackageDescription @@ -15,7 +15,7 @@ let package = Package( // See https://github.com/erikdoe/ocmock/issues/500#issuecomment-1002700625 .package(url: "https://github.com/erikdoe/ocmock", revision: "afd2c6924e8a36cb872bc475248b978f743c6050"), .package(url: "https://github.com/Quick/Quick", from: "6.0.0"), - .package(url: "https://github.com/realm/SwiftLint", .exactItem(loadSwiftLintVersion())) + .package(url: "https://github.com/realm/SwiftLint", exact: loadSwiftLintVersion()) ], targets: [ .target( diff --git a/Sources/WordPressShared/Utility/NSDate+Helpers.swift b/Sources/WordPressShared/Utility/NSDate+Helpers.swift index 4f26d12..7e17260 100644 --- a/Sources/WordPressShared/Utility/NSDate+Helpers.swift +++ b/Sources/WordPressShared/Utility/NSDate+Helpers.swift @@ -140,14 +140,9 @@ extension Date { } /// Formats the current date as a medium relative date/time. - /// - Parameter timeZone: An optional time zone used to adjust the date formatters. - /// - /// - Example: Tomorrow, 6:45 AM - /// - Example: Today, 8:09 AM - /// - Example: Yesterday, 11:36 PM - /// - Example: Jan 28, 2017, 1:51 PM - /// - Example: Jan 22, 2017, 2:18 AM + /// That is, it uses the `DateFormatter` `dateStyle` `.medium` and `timeStyle` `.short`. /// + /// - Parameter timeZone: An optional time zone used to adjust the date formatters. public func mediumStringWithTime(timeZone: TimeZone? = nil) -> String { let formatter = DateFormatters.mediumDateTime if let timeZone = timeZone { diff --git a/Tests/WordPressSharedTests/NSDateHelperTest.swift b/Tests/WordPressSharedTests/NSDateHelperTest.swift index 625bb52..c938168 100644 --- a/Tests/WordPressSharedTests/NSDateHelperTest.swift +++ b/Tests/WordPressSharedTests/NSDateHelperTest.swift @@ -56,22 +56,26 @@ class NSDateHelperTest: XCTestCase { } /// Verifies that `mediumStringWithTime` takes into account the time zone adjustment - /// If this test is failing, check that the Test Plan is still using en-US as its language + /// + /// This legacy test is a bit silly because it is simply testing that the code calls `DateFormatter` with the expected configuration. + /// This was done to make the test robust against underlying changes in `DateFormatter`'s behavior. + /// Example failure this avoids: https://buildkite.com/automattic/wordpress-shared-ios/builds/235#018ed45e-c2be-40e5-9759-6bd7c0735ce9/6-2623 func testMediumStringTimeZoneAdjust() { let date = Date() let timeZone = TimeZone(secondsFromGMT: Calendar.current.timeZone.secondsFromGMT() - (60 * 60)) XCTAssertEqual(date.toMediumString(inTimeZone: timeZone), "now") let timeFormatter = DateFormatter() - timeFormatter.dateStyle = .none + timeFormatter.doesRelativeDateFormatting = true + timeFormatter.dateStyle = .medium timeFormatter.timeStyle = .short let withoutTimeZoneAdjust = timeFormatter.string(from: date) - XCTAssertEqual(date.mediumStringWithTime(), "Today, \(withoutTimeZoneAdjust)") + XCTAssertEqual(date.mediumStringWithTime(), withoutTimeZoneAdjust) timeFormatter.timeZone = timeZone let withTimeZoneAdjust = timeFormatter.string(from: date) - XCTAssertEqual(date.mediumStringWithTime(timeZone: timeZone), "Today, \(withTimeZoneAdjust)") + XCTAssertEqual(date.mediumStringWithTime(timeZone: timeZone), withTimeZoneAdjust) } }