Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Setup for CocoaPods and SPM distribution #5

Merged
merged 12 commits into from
Jul 18, 2023
9 changes: 9 additions & 0 deletions .buildkite/build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ brew install xcbeautify

echo "--- :xcode: Building"
make bundle-ios xcframework

echo "--- :amazon-s3: Uploading"
GIT_HASH=$(git rev-parse --short HEAD)
aws s3 cp dist/WooCommerceShared.xcframework.zip s3://a8c-apps-public-artifacts/woocommerce-shared/${GIT_HASH}/WooCommerceShared.xcframework.zip
Comment on lines +57 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started building an upload_to_s3 command in the CI toolkit, but I half regret it now... There's really little difference than calling aws directly


echo "--- 🧮 Hashing"
ZIP_HASH=$(swift package compute-checksum dist/WooCommerceShared.xcframework.zip)
echo $ZIP_HASH | tee dist/WooCommerceShared.xcframework.zip.checksum.txt
aws s3 cp dist/WooCommerceShared.xcframework.zip.checksum.txt s3://a8c-apps-public-artifacts/woocommerce-shared/${GIT_HASH}/WooCommerceShared.xcframework.zip.checksum.txt
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ steps:
queue: "mac"
artifact_paths:
- "dist/*.tar.gz"
- "dist/*.zip"
- "logs/**/*"

#################
Expand Down
16 changes: 16 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AllCops:
Exclude:
- DerivedData/**/*
- Pods/**/*
- vendor/**/*
- node_modules/**/*
NewCops: enable

Naming/FileName:
Exclude:
- '*.podspec'


Metrics/BlockLength:
Exclude:
- '*.podspec'
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ gems: bundle
pods: gems
bundle exec pod install --project-directory=libraries/ios

validate-pod:
bundle exec pod spec lint

# Build an XCFramework of this project – this is the primary distribution artifact for iOS
#
xcframework:
Expand Down Expand Up @@ -79,8 +82,8 @@ xcframework:

@echo "--- :compression: Packaging XCFramework"

rm -rf dist/WooCommerceShared.xcframework.tar.gz
tar -czf dist/WooCommerceShared.xcframework.tar.gz -C dist/ WooCommerceShared.xcframework
rm -rf dist/WooCommerceShared.xcframework.zip
ditto -c -k --sequesterRsrc --keepParent dist/WooCommerceShared.xcframework dist/WooCommerceShared.xcframework.zip

# Remove all downloaded dependencies and compiled code
#
Expand Down
25 changes: 25 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "WooCommerceShared",
platforms: [
.iOS(.v13),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "WooCommerceShared",
targets: ["WooCommerceShared"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
],
targets: [
.binaryTarget(
name: "WooCommerceShared",
url: "https://cdn.a8c-ci.services/woocommerce-shared/6cba1e9/WooCommerceShared.xcframework.zip",
checksum: "d815fb1b3a897e1a42c27c6ea1373ab25c818d3beaa4a73205390c6031768d1c"
)
]
)
62 changes: 61 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,57 @@

A React Native project used to share code between WooCommerce iOS and Android.

## Getting Started
## Quickstart

### iOS – CocoaPods

#### Production Builds
```ruby
pod 'woocommerce-shared', '~> 0.0.1'
```

#### Development Builds
```ruby
# Reference a commit hash
pod 'WooCommerceShared', git: 'https://github.com/woocommerce/WooCommerce-Shared.git', commit: '6cba1e9'

# Reference a branch
pod 'WooCommerceShared', git: 'https://github.com/woocommerce/WooCommerce-Shared.git', branch: 'trunk'
Comment on lines +14 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this CocoaPod uses pre-built binaries, referencing a commit or a branch might not result in the binary that's downloaded reflecting the state of the source code.


# Reference a local copy
pod 'WooCommerceShared', path: '../WooCommerce-Shared'
```

### iOS – SwiftPM

#### Production Builds
```swift
dependencies: [
.package(url: "https://github.com/woocommerce/woocommerce-shared.git", .upToNextMajor(from: "0.0.1"))
]
```

#### Development Builds
```swift
// Development Builds require two entries – one for the binary target:
targets: [
.binaryTarget(
name: "WooCommerceShared",
url: "https://cdn.a8c-ci.services/woocommerce-shared/[commit-hash]/WooCommerceShared.xcframework.zip",
checksum: "[Contents of https://cdn.a8c-ci.services/woocommerce-shared/[commit-hash]/WooCommerceShared.xcframework.zip.checksum.txt]"
)

]

// And a second to make the target depend on it:
.executable(name: "MyApp", targets: [
"WooCommerceShared",
])

```


## Development

This project uses `make` for most of its operations. You probably already have it installed if you've used your computer for development tasks in the past.

Expand All @@ -17,3 +67,13 @@ Run `make dev` to start working on this project locally.
## Build + Ship

Running `make` (with no other arguments) will build every component of the project (if possible on the current machine). See the `Makefile` for all of the individual build tasks involved in this.

## Releases

Because of various CocoaPods and SwiftPM idiosyncracies around `xcframework` distribution, releases are a bit tricky. To perform a release, you should:

1. Create a `release/$VERSION` branch, and push it up to github.com
2. Wait for CI to publish the tip of your release branch, and note the commit shorthash.
3. Update the URL in `Package.swift`, and update the `checksum` field with the hash printed in the build log (if you need it, it's also published to `https://cdn.a8c-ci.services/woocommerce-shared/{commit-hash}/WooCommerceShared.xcframework.zip.checksum.txt`.
4. Commit your change as `Tag {$VERSION}`, then tag that commit with your version number.
5. Publish the tag to github.com
26 changes: 26 additions & 0 deletions WooCommerceShared.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

CURRENT_SHORTHASH = `git rev-parse --short HEAD`.strip!.freeze

Pod::Spec.new do |s|
s.name = 'WooCommerceShared'
s.version = '0.1.0'

s.summary = 'Shared components used for the iOS and Android WooCommerce Apps.'
s.description = "#{s.summary} It's a React Native library project."

s.homepage = 'https://github.com/woocommerce/WooCommerce-Shared'
s.license = { type: 'MPL', text: File.read('LICENSE') }
s.author = { 'The WooCommerce Mobile Team' => '[email protected]' }

s.platform = :ios, '13.0'
s.swift_version = '5.0'

s.source_files = 'WooCommerceShared.xcframework'

s.source = {
http: "https://cdn.a8c-ci.services/woocommerce-shared/#{CURRENT_SHORTHASH}/WooCommerceShared.xcframework.zip"
}

s.vendored_frameworks = 'WooCommerceShared.xcframework'
end