Skip to content

Commit

Permalink
Strict concurrency and project maintenance (#132)
Browse files Browse the repository at this point in the history
* Support strict concurrency
* Update CI builds to run on macOS 14
* Update snapshot tests to run on iOS 17 and iPadOS 17
* Bump minimum deployment target to iOS 13
  • Loading branch information
NickEntin authored Aug 29, 2024
1 parent 420dc31 commit f426143
Show file tree
Hide file tree
Showing 203 changed files with 219 additions and 132 deletions.
26 changes: 12 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ on:
jobs:
xcode-build:
name: Xcode Build
runs-on: macOS-11
runs-on: macOS-14
strategy:
matrix:
platform: ['iOS_14', 'iOS_13']
platform: ['iOS_17', 'iPadOS_17']
fail-fast: false
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_13.2.1.app/Contents/Developer
- name: Prepare Simulator Runtimes
run: Scripts/github/prepare-simulators.sh ${{ matrix.platform }}
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer
- name: Bundle Install
run: bundle install
- name: Pod Install
Expand All @@ -35,37 +33,37 @@ jobs:
path: .build/derivedData/**/Logs/Test/*.xcresult
pod-lint:
name: Lint Pod
runs-on: macOS-12
runs-on: macOS-14
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Bundle Install
run: bundle install
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_14.1.app/Contents/Developer
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer
- name: Lint Podspec
run: bundle exec pod lib lint --verbose --fail-fast
spm:
name: SPM Build
runs-on: macOS-12
runs-on: macOS-14
strategy:
matrix:
platform: ['iOS_16', 'iOS_15']
platform: ['iOS_17']
fail-fast: false
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_14.1.app/Contents/Developer
- name: Prepare Simulator Runtimes
run: Scripts/github/prepare-simulators.sh ${{ matrix.platform }}
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer
- name: Build
run: Scripts/build.swift spm ${{ matrix.platform }} `which xcpretty`
bazel:
name: Bazel
runs-on: macOS-12
runs-on: macOS-14
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer
- name: Build and Test
run: bazel test //...
run: bazel test //... --xcode_version=15.4.0
6 changes: 4 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ swift_library(
name = "Paralayout.lib",
srcs = glob(["Paralayout/**/*.swift"]),
module_name = "Paralayout",
copts = ["-strict-concurrency=complete"],
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [],
Expand All @@ -22,6 +23,7 @@ swift_library(
testonly = True,
srcs = glob(["ParalayoutTests/**/*.swift"]),
module_name = "ParalayoutTests",
copts = ["-strict-concurrency=complete"],
tags = ["manual"],
deps = [":Paralayout.lib"],
)
Expand All @@ -34,15 +36,15 @@ ios_framework(
"ipad",
],
infoplists = ["Paralayout/Info.plist"],
minimum_os_version = "12.0",
minimum_os_version = "13.0",
visibility = ["//visibility:public"],
deps = [":Paralayout.lib"],
)

ios_unit_test(
name = "ParalayoutTests",
bundle_name = "ParalayoutTests",
minimum_os_version = "12.0",
minimum_os_version = "13.0",
runner = "@rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner",
deps = [":ParalayoutTests.lib"],
)
4 changes: 3 additions & 1 deletion Example/ParalayoutDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 51;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -418,6 +418,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = complete;
};
name = Debug;
};
Expand Down Expand Up @@ -472,6 +473,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_STRICT_CONCURRENCY = complete;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
26 changes: 15 additions & 11 deletions Example/ParalayoutSnapshotTests/SnapshotTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

import SnapshotTesting
@preconcurrency import SnapshotTesting
import XCTest

class SnapshotTestCase: XCTestCase {
Expand All @@ -31,6 +31,7 @@ class SnapshotTestCase: XCTestCase {

// MARK: - Public Methods

@MainActor
func matchesCurrentDevice() -> Bool {
let device = UIDevice.current
let screen = UIScreen.main
Expand All @@ -46,28 +47,31 @@ class SnapshotTestCase: XCTestCase {

private static let testedDevices = [

// iPhone 12 Pro (14.4)
TestDeviceConfig(systemVersion: "14.4", screenSize: CGSize(width: 390, height: 844), screenScale: 3),
// iPhone 15 Pro - iOS 17.5
TestDeviceConfig(systemVersion: "17.5", screenSize: CGSize(width: 393, height: 852), screenScale: 3),

// iPhone 11 Pro (13.7)
TestDeviceConfig(systemVersion: "13.7", screenSize: CGSize(width: 375, height: 812), screenScale: 3),
// iPad (10th Generation) - iPadOS 17.5
TestDeviceConfig(systemVersion: "17.5", screenSize: CGSize(width: 820, height: 1180), screenScale: 2),

]

// MARK: - XCTestCase

override class func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()

guard SnapshotTestCase.testedDevices.contains(where: { $0.matchesCurrentDevice() }) else {
fatalError("Attempting to run tests on a device for which we have not collected test data")
}
await Task { @MainActor in
guard SnapshotTestCase.testedDevices.contains(where: { $0.matchesCurrentDevice() }) else {
fatalError("Attempting to run tests on a device for which we have not collected test data")
}

isRecording = false
isRecording = false
}.value
}

// MARK: - Public Methods

@MainActor
func nameForSnapshot(with parameters: [String?]) -> String {
let size = UIScreen.main.bounds.size
let scale = UIScreen.main.scale
Expand Down
10 changes: 10 additions & 0 deletions Example/ParalayoutSnapshotTests/ViewAlignmentSnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import SnapshotTesting

final class ViewAlignmentSnapshotTests: SnapshotTestCase {

@MainActor
func testSiblingAlignment() {
let containerView = UIView(frame: .init(x: 0, y: 0, width: 200, height: 200))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -80,6 +81,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
verifySnapshot(receiverPosition: .center, targetPosition: .topRight, verticalOffset: -15)
}

@MainActor
func testLayoutDirection() {
let containerView = UIView(frame: .init(x: 0, y: 0, width: 100, height: 100))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -140,6 +142,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testTransformHasNoEffect() {
let containerView = UIView(frame: .init(x: 0, y: 0, width: 100, height: 100))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -185,6 +188,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
verifySnapshot(receiverTransform: .identity, targetTransform: .init(scaleX: 2, y: 3))
}

@MainActor
func testNonZeroBoundsOrigin() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -213,6 +217,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testAlignmentWithLayoutMargins() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -246,6 +251,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: ["bothLayoutMargins"]))
}

@MainActor
func testAlignmentUsingCapInsets() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 100))
containerView.backgroundColor = .white
Expand All @@ -269,6 +275,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testAlignmentUsingFirstLine() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 100))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -299,6 +306,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testAlignmentUsingFirstLineCapInsets() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 250, height: 100))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -329,6 +337,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testAlignmentWithRect() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -365,6 +374,7 @@ final class ViewAlignmentSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testAlignmentWithFrame() {
let targetTransform = CGAffineTransform(translationX: -20, y: 10)
let receiverTransform = CGAffineTransform(scaleX: 0.8, y: 0.8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import SnapshotTesting

final class ViewDistributionSnapshotTests: SnapshotTestCase {

@MainActor
func testDistribution() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
containerView.backgroundColor = .white
Expand All @@ -45,6 +46,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: ["vertical"]))
}

@MainActor
func testDistributionIgnoresTransform() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -72,6 +74,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testDistributionUsingCapInsets() {
let containerView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80))
containerView.backgroundColor = .white
Expand Down Expand Up @@ -104,6 +107,7 @@ final class ViewDistributionSnapshotTests: SnapshotTestCase {
assertSnapshot(matching: containerView, as: .image, named: nameForSnapshot(with: []))
}

@MainActor
func testHorizontalDistributionFollowsLayoutDirection() {
let view = HorizontalDistributionView(frame: CGRect(x: 0, y: 0, width: 160, height: 60))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import SnapshotTesting

final class ViewSpeadingSnapshotTests: SnapshotTestCase {

@MainActor
func testHorizontallySpreadSubviews() {
let container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 100))
container.backgroundColor = .white
Expand Down Expand Up @@ -92,6 +93,7 @@ final class ViewSpeadingSnapshotTests: SnapshotTestCase {
verifySnapshot(margin: 40, inRect: CGRect(x: 20, y: 10, width: 300, height: 50))
}

@MainActor
func testVerticallySpreadSubviews() {
let container = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 100))
container.backgroundColor = .white
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Diff not rendered.
8 changes: 4 additions & 4 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Paralayout (1.0.0)
- Paralayout/Tests (1.0.0)
- Paralayout (1.1.0)
- Paralayout/Tests (1.1.0)
- SnapshotTesting (1.8.2)

DEPENDENCIES:
Expand All @@ -17,9 +17,9 @@ EXTERNAL SOURCES:
:path: "../Paralayout.podspec"

SPEC CHECKSUMS:
Paralayout: 63a087763d2c7a1b9c55843064e889aa27bdb56a
Paralayout: 148233f7ff311384bcb209bf0b1b8a1578ad1d34
SnapshotTesting: 38947050d13960d57a4a9c166fcf51bca7d56970

PODFILE CHECKSUM: f0cdc6633e8d65e479af433fa427d7c0ce7c72b1

COCOAPODS: 1.11.3
COCOAPODS: 1.14.3
17 changes: 10 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.0.1
// swift-tools-version:5.9

//
// Copyright 2020 Square Inc.
Expand All @@ -21,7 +21,7 @@ import PackageDescription
let package = Package(
name: "Paralayout",
platforms: [
.iOS(.v12),
.iOS(.v13),
],
products: [
.library(
Expand All @@ -33,13 +33,16 @@ let package = Package(
.target(
name: "Paralayout",
dependencies: [],
path: "Paralayout"
path: "Paralayout",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "ParalayoutTests",
dependencies: ["Paralayout"],
path: "ParalayoutTests"
),
name: "ParalayoutTests",
dependencies: ["Paralayout"],
path: "ParalayoutTests"
),
],
swiftLanguageVersions: [.v5]
)
6 changes: 3 additions & 3 deletions Paralayout.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = 'Paralayout'
s.version = '1.0.0'
s.version = '1.1.0'
s.license = 'Apache License, Version 2.0'
s.summary = 'Paralayout is a simple set of assistive UI layout utilities. Size and position your UI with pixel-perfect precision. Design will love you!'
s.homepage = 'https://github.com/square/Paralayout'
s.authors = 'Square'
s.source = { :git => 'https://github.com/square/Paralayout.git', :tag => s.version }
s.source_files = 'Paralayout/*.{swift}'
s.ios.deployment_target = '12.0'
s.swift_version = '5.0'
s.ios.deployment_target = '13.0'
s.swift_version = '5.9'

s.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'ParalayoutTests/*{.swift}'
Expand Down
Loading

0 comments on commit f426143

Please sign in to comment.