Skip to content

Commit

Permalink
Merge pull request #123 from Automattic/add/migrate-to-separate-modules
Browse files Browse the repository at this point in the history
Migrate to separate modules for `Gravatar` and `GravatarUI`
  • Loading branch information
andrewdmontgomery authored Mar 21, 2024
2 parents a1a0d9c + a821977 commit b715d99
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 17 deletions.
6 changes: 3 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ steps:
command: |
echo "--- 🛠 Building + Testing"
make test
plugins: [$CI_TOOLKIT]
###################
# Validate Podspec
###################
- label: "🧪 Validate Podspec"
command: validate_podspec
plugins: [$CI_TOOLKIT]
command: |
echo "--- :microscope: Validate Podspec"
make validate-pod-ci
14 changes: 14 additions & 0 deletions Demo/Gravatar-Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
495775E42B5B34970082812A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 495775E32B5B34970082812A /* SceneDelegate.swift */; };
495775EB2B5B34980082812A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 495775EA2B5B34980082812A /* Assets.xcassets */; };
495775EE2B5B34980082812A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 495775EC2B5B34980082812A /* LaunchScreen.storyboard */; };
497783312BAC8A99008C29F7 /* GravatarUI in Frameworks */ = {isa = PBXBuildFile; productRef = 497783302BAC8A99008C29F7 /* GravatarUI */; };
497783332BAC8AA9008C29F7 /* GravatarUI in Frameworks */ = {isa = PBXBuildFile; productRef = 497783322BAC8AA9008C29F7 /* GravatarUI */; };
49C5D60E2B5B33E20067C2A8 /* DemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C5D60D2B5B33E20067C2A8 /* DemoApp.swift */; };
49C5D6102B5B33E20067C2A8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 49C5D60F2B5B33E20067C2A8 /* ContentView.swift */; };
49C5D6122B5B33E20067C2A8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 49C5D6112B5B33E20067C2A8 /* Assets.xcassets */; };
Expand Down Expand Up @@ -53,6 +55,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
497783312BAC8A99008C29F7 /* GravatarUI in Frameworks */,
4948C4EC2B61C41100AC4875 /* Gravatar in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -61,6 +64,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
497783332BAC8AA9008C29F7 /* GravatarUI in Frameworks */,
4948C4EE2B61C41800AC4875 /* Gravatar in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -167,6 +171,7 @@
name = "Gravatar-Demo";
packageProductDependencies = (
4948C4EB2B61C41100AC4875 /* Gravatar */,
497783302BAC8A99008C29F7 /* GravatarUI */,
);
productName = "Gravatar-Demo";
productReference = 495775DF2B5B34970082812A /* Gravatar-Demo.app */;
Expand All @@ -187,6 +192,7 @@
name = "Gravatar-SwiftUI-Demo";
packageProductDependencies = (
4948C4ED2B61C41800AC4875 /* Gravatar */,
497783322BAC8AA9008C29F7 /* GravatarUI */,
);
productName = Demo;
productReference = 49C5D60A2B5B33E20067C2A8 /* Gravatar-SwiftUI-Demo.app */;
Expand Down Expand Up @@ -582,6 +588,14 @@
isa = XCSwiftPackageProductDependency;
productName = Gravatar;
};
497783302BAC8A99008C29F7 /* GravatarUI */ = {
isa = XCSwiftPackageProductDependency;
productName = GravatarUI;
};
497783322BAC8AA9008C29F7 /* GravatarUI */ = {
isa = XCSwiftPackageProductDependency;
productName = GravatarUI;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 49C5D6022B5B33E20067C2A8 /* Project object */;
Expand Down
8 changes: 4 additions & 4 deletions Gravatar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Gravatar'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'A convient library for accessing the Gravatar API'

s.homepage = 'https://gravatar.com'
Expand All @@ -18,14 +18,14 @@ Pod::Spec.new do |s|

s.ios.deployment_target = ios_deployment_target

s.source_files = 'Sources/**/*.swift'
s.source_files = 'Sources/Gravatar/**/*.swift'

s.test_spec 'Tests' do |swift_unit_tests|
s.test_spec 'GravatarTests' do |swift_unit_tests|
swift_unit_tests.platforms = {
:ios => ios_deployment_target,
}
swift_unit_tests.source_files = [
'Tests/**/*.swift'
'Tests/GravatarTests/**/*.swift'
]
swift_unit_tests.resource_bundles = {
GravatarTestsResources: [
Expand Down
40 changes: 40 additions & 0 deletions GravatarUI.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Pod::Spec.new do |s|
s.name = 'GravatarUI'
s.version = '0.1.1'
s.summary = 'A convient library of Gravatar UI components'

s.homepage = 'https://gravatar.com'
s.license = { :type => 'Mozilla Public License v2', :file => 'LICENSE.md' }
s.authors = 'Automattic, Inc.'
s.source = {
:git => 'https://github.com/Automattic/Gravatar-SDK-iOS.git',
:tag => s.version.to_s
}
s.documentation_url = 'https://automattic.github.io/Gravatar-SDK-iOS/'

s.swift_version = '5.9'

ios_deployment_target = '15.0'
s.ios.deployment_target = ios_deployment_target

s.source_files = 'Sources/GravatarUI/**/*.swift'
s.dependency 'Gravatar', s.version.to_s
s.ios.framework = 'UIKit'

s.test_spec 'GravatarUITests' do |swift_unit_tests|
swift_unit_tests.platforms = {
:ios => ios_deployment_target,
}
swift_unit_tests.source_files = [
'Tests/GravatarUITests/**/*.swift'
]
swift_unit_tests.resource_bundles = {
GravatarUITestsResources: [
'Tests/GravatarUITests/Resources/**/*'
]
}
swift_unit_tests.requires_app_host = false
end
end


17 changes: 14 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dev-demo:

test:
xcodebuild test \
-scheme Gravatar \
-scheme Gravatar-Package \
-destination 'platform=$(PLATFORM),OS=$(OS),name=$(DEVICE)'

swiftformat:
Expand All @@ -30,6 +30,17 @@ lint:
swiftformat \
--lint

lint-pod:
validate-pod:
bundle install
bundle exec pod lib lint --verbose --fail-fast
bundle exec pod lib lint \
--include-podspecs="*.podspec" \
--verbose --fail-fast

validate-pod-ci:
# For some reason this fixes a failure in `lib lint`
# https://github.com/Automattic/buildkite-ci/issues/7
xcrun simctl list >> /dev/null
bundle install
bundle exec pod lib lint \
--include-podspecs="*.podspec" \
--verbose --fail-fast
21 changes: 18 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ let package = Package(
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Gravatar",
targets: ["Gravatar"]),
targets: ["Gravatar"]
),
.library(
name: "GravatarUI",
targets: ["GravatarUI"]
),
],
dependencies: [
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.53.0")
Expand All @@ -21,11 +26,21 @@ let package = Package(
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Gravatar"),
name: "Gravatar"
),
.testTarget(
name: "GravatarTests",
dependencies: ["Gravatar"],
resources: [.process("Resources")]
)
),
.target(
name: "GravatarUI",
dependencies: ["Gravatar"]
),
.testTarget(
name: "GravatarUITests",
dependencies: ["GravatarUI"],
resources: [.process("Resources")]
),
]
)
1 change: 1 addition & 0 deletions Sources/GravatarUI/RenameMe.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Foundation
2 changes: 1 addition & 1 deletion Tests/GravatarTests/Bundle+ResourceBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Bundle {
/// If installed via CocoaPods, this will be GravatarTestsResources.bundle,
/// otherwise it will be the module bundle.
///
public class var gravatarTestsBundle: Bundle {
public class var testsBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
Expand Down
4 changes: 2 additions & 2 deletions Tests/GravatarTests/ImageHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ImageHelper {
}

static func dataFromImage(named: String, type: String) -> Data? {
guard let url = Bundle.gravatarTestsBundle.url(forResource: named, withExtension: type) else {
guard let url = Bundle.testsBundle.url(forResource: named, withExtension: type) else {
return nil
}
var data: Data? = nil
Expand All @@ -29,7 +29,7 @@ class ImageHelper {
}

static func image(named: String, type: String) -> UIImage? {
guard let path = Bundle.gravatarTestsBundle.path(forResource: named, ofType: type) else {
guard let path = Bundle.testsBundle.path(forResource: named, ofType: type) else {
return nil
}
return UIImage(contentsOfFile: path)
Expand Down
26 changes: 26 additions & 0 deletions Tests/GravatarTests/RenameMeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import XCTest

final class RenameMeTests_swift: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
2 changes: 1 addition & 1 deletion Tests/GravatarTests/UserProfileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ extension UserProfileTests {
}

private func json(for profile: Profile) throws -> Data {
guard let url = Bundle.gravatarTestsBundle.url(forResource: profile.rawValue, withExtension: "json") else {
guard let url = Bundle.testsBundle.url(forResource: profile.rawValue, withExtension: "json") else {
throw UserProfileTestError.profileNotFound
}

Expand Down
27 changes: 27 additions & 0 deletions Tests/GravatarUITests/Bundle+ResourceBundle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation

#if !SWIFT_PACKAGE
private class BundleFinder: NSObject {}
#endif

extension Bundle {
/// Returns the GravatarUITests Bundle
/// If installed via CocoaPods, this will be GravatarUITestsResources.bundle,
/// otherwise it will be the module bundle.
///
public class var testsBundle: Bundle {
#if SWIFT_PACKAGE
return Bundle.module
#else
let defaultBundle = Bundle(for: BundleFinder.self)
// If installed with CocoaPods, resources will be in GravatarUITestsResources.bundle
if let bundleURL = defaultBundle.resourceURL,
let resourceBundle = Bundle(url: bundleURL.appendingPathComponent("GravatarUITestsResources.bundle"))
{
return resourceBundle
}
// Otherwise, the default bundle is used for resources
return defaultBundle
#endif
}
}
26 changes: 26 additions & 0 deletions Tests/GravatarUITests/RenameMeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import XCTest

final class RenameMeTests_swift: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
}
Binary file added Tests/GravatarUITests/Resources/dummy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b715d99

Please sign in to comment.