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
10 changes: 9 additions & 1 deletion .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Nodes with values to reuse in the pipeline.
common_params:
plugins: &common_plugins
- automattic/a8c-ci-toolkit#2.17.0
- automattic/a8c-ci-toolkit#3.4.1
# Common environment values to use with the `env` key.

steps:
Expand Down Expand Up @@ -71,6 +71,14 @@ steps:
plugins: *common_plugins
agents:
queue: mac
- label: ":swift: :cocoapods: Validate CocoaPods Support"
command: .buildkite/validate-cocoapods.sh
env:
IMAGE_ID: xcode-15.3
depends_on: xcframework
plugins: *common_plugins
agents:
queue: mac
- label: ":swift: :linux: Build and Test"
command: |
echo "--- :swift: Building + Testing"
Expand Down
55 changes: 55 additions & 0 deletions .buildkite/validate-cocoapods.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -euo pipefail

# Commit a podspec file to the repo may give a fasle sense of CocoaPods support.
# This script validates the podspec file generated by the build script.
# We may need to tweak the podspec content if the project structure changes.
#
# Here are a few potential fixes if this script fails on CI.
# - There is no "WordPressAPIInternal" module when building using CocoaPods.
# Be sure to add `#if canImport(WordPressAPIInternal)` before `import WordPressAPIInternal`.

echo "--- :hammer: Generating a podspec file"
cat <<EOT | tee WordPressAPI.podspec
Pod::Spec.new do |spec|
spec.name = "WordPressAPI"
spec.version = "0.0.1"
spec.summary = "WordPressAPI."
spec.description = "WordPress API in Swift."
spec.homepage = "https://github.com/automattic/wordpress-rs"
spec.license = "MIT"
spec.author = { 'The WordPress Mobile Team' => 'mobile@wordpress.org' }

spec.ios.deployment_target = '13.0'
spec.osx.deployment_target = '11.0'

# zip -r swift-source-archive.zip native/swift target/libwordpressFFI.xcframework
spec.source = { :http => "http://s3.com/WordPressAPI.zip" }

spec.swift_version = '5.10'
spec.source_files = 'native/swift/Sources/**/*.{swift}'
spec.vendored_frameworks = 'target/libwordpressFFI.xcframework'

spec.pod_target_xcconfig = {
'SWIFT_PACKAGE_NAME' => 'WordPressAPI'
}

spec.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'native/swift/Tests/**/*.{swift}'
end
end
EOT

echo "--- :arrow_down: Downloading xcframework"
buildkite-agent artifact download target/libwordpressFFI.xcframework.zip . --step "xcframework"
buildkite-agent artifact download native/swift/Sources/wordpress-api-wrapper/wp_api.swift . --step "xcframework"
unzip target/libwordpressFFI.xcframework.zip -d .
rm target/libwordpressFFI.xcframework.zip
export SKIP_PACKAGE_WP_API=true

echo "--- :rubygems: Setting up Gems"
install_gems

echo "--- :cocoapods: Validating Podspec"
validate_podspec --allow-warnings
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
source 'https://rubygems.org'

gem 'fastlane', '~> 2.220'
gem 'cocoapods', '~> 1.15'
77 changes: 75 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,21 @@ GEM
base64
nkf
rexml
activesupport (7.1.3.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
artifactory (3.0.17)
atomos (0.1.3)
aws-eventstream (1.3.0)
Expand All @@ -27,17 +40,61 @@ GEM
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
bigdecimal (3.1.8)
claide (1.1.0)
cocoapods (1.15.2)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.15.2)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.15.2)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored (1.2)
colored2 (3.1.2)
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
declarative (0.0.20)
digest-crc (0.6.5)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.6.20240107)
dotenv (2.8.1)
drb (2.2.1)
emoji_regex (3.2.3)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
excon (0.110.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
Expand Down Expand Up @@ -109,6 +166,9 @@ GEM
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.3.0)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
ffi (1.16.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.54.0)
google-apis-core (>= 0.11.0, < 2.a)
Expand Down Expand Up @@ -150,21 +210,28 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.7.2)
jwt (2.8.1)
base64
mini_magick (4.12.0)
mini_mime (1.1.5)
minitest (5.23.1)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.4.0)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
nkf (0.2.0)
optparse (0.5.0)
os (1.1.4)
plist (3.7.1)
public_suffix (5.0.5)
public_suffix (4.0.7)
rake (13.2.1)
representable (3.2.0)
declarative (< 0.1.0)
Expand All @@ -173,6 +240,7 @@ GEM
retriable (3.1.2)
rexml (3.2.6)
rouge (2.0.7)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
security (0.1.5)
Expand All @@ -192,6 +260,10 @@ GEM
tty-screen (0.8.2)
tty-spinner (0.9.3)
tty-cursor (~> 0.7)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unicode-display_width (2.5.0)
word_wrap (1.0.0)
Expand All @@ -211,7 +283,8 @@ PLATFORMS
arm64-darwin-22

DEPENDENCIES
cocoapods (~> 1.15)
fastlane (~> 2.220)

BUNDLED WITH
2.4.19
2.3.23
2 changes: 2 additions & 0 deletions native/swift/Example/Example/LoginManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

class LoginManager: NSObject, ObservableObject {

Expand Down
2 changes: 2 additions & 0 deletions native/swift/Sources/wordpress-api/Endpoints/Plugins.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

extension WordPressAPI {
public var plugins: AnyNamespace<SparsePlugin> {
Expand Down
2 changes: 2 additions & 0 deletions native/swift/Sources/wordpress-api/Endpoints/Users.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

extension SparseUser: Contextual {
public typealias ID = UserId
Expand Down
4 changes: 4 additions & 0 deletions native/swift/Sources/wordpress-api/Exports.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// We could export all of them using `@_exported import`, but that probably puts
// us in a position where we need to make major releases due to Rust code changes.

#if canImport(WordPressAPIInternal)

import WordPressAPIInternal

public typealias WpApiError = WordPressAPIInternal.WpApiError
Expand Down Expand Up @@ -31,3 +33,5 @@ public typealias PluginListParams = WordPressAPIInternal.PluginListParams
public typealias PluginUpdateParams = WordPressAPIInternal.PluginUpdateParams
public typealias PluginCreateParams = WordPressAPIInternal.PluginCreateParams
public typealias PluginDeleteResponse = WordPressAPIInternal.PluginDeleteResponse

#endif
6 changes: 4 additions & 2 deletions native/swift/Sources/wordpress-api/Login/API+Login.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

#if canImport(FoundationNetworking)
import FoundationNetworking
Expand All @@ -11,11 +13,11 @@ public extension WordPressAPI {
let ephemeralClient = WordPressAPI(urlSession: session, baseUrl: url, authenticationStategy: .none)
let response = try await ephemeralClient.perform(request: request)

return WordPressAPIInternal.getLinkHeader(response: response, name: "https://api.w.org/")?.asUrl()
return getLinkHeader(response: response, name: "https://api.w.org/")?.asUrl()
}

func getRestAPICapabilities(forApiRoot url: URL, using session: URLSession) async throws -> WpapiDetails {
let wpResponse = try await self.perform(request: WpNetworkRequest(method: .get, url: url, headerMap: [:]))
return try WordPressAPIInternal.parseApiDetailsResponse(response: wpResponse)
return try parseApiDetailsResponse(response: wpResponse)
}
}
18 changes: 10 additions & 8 deletions native/swift/Sources/wordpress-api/Namespace.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

public protocol Namespace {
associatedtype T
Expand Down Expand Up @@ -51,8 +53,8 @@ public protocol ContextualNamespace: Namespace where T: Contextual {

var context: WpContext { get }

func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> R
func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> [R]
func parseResponse(_ response: WpNetworkResponse) throws -> R
func parseResponse(_ response: WpNetworkResponse) throws -> [R]
}

public struct ViewNamespace<T: Contextual>: ContextualNamespace {
Expand All @@ -63,11 +65,11 @@ public struct ViewNamespace<T: Contextual>: ContextualNamespace {
parent.api
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> T.ViewContext {
public func parseResponse(_ response: WpNetworkResponse) throws -> T.ViewContext {
try T.parseResponse(response)
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> [T.ViewContext] {
public func parseResponse(_ response: WpNetworkResponse) throws -> [T.ViewContext] {
try T.parseResponse(response)
}
}
Expand All @@ -80,11 +82,11 @@ public struct EditNamespace<T: Contextual>: ContextualNamespace {
parent.api
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> T.EditContext {
public func parseResponse(_ response: WpNetworkResponse) throws -> T.EditContext {
try T.parseResponse(response)
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> [T.EditContext] {
public func parseResponse(_ response: WpNetworkResponse) throws -> [T.EditContext] {
try T.parseResponse(response)
}
}
Expand All @@ -97,11 +99,11 @@ public struct EmbedNamespace<T: Contextual>: ContextualNamespace {
parent.api
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> T.EmbedContext {
public func parseResponse(_ response: WpNetworkResponse) throws -> T.EmbedContext {
try T.parseResponse(response)
}

public func parseResponse(_ response: WordPressAPIInternal.WpNetworkResponse) throws -> [T.EmbedContext] {
public func parseResponse(_ response: WpNetworkResponse) throws -> [T.EmbedContext] {
try T.parseResponse(response)
}
}
Expand Down
4 changes: 3 additions & 1 deletion native/swift/Sources/wordpress-api/WordPressAPI.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

#if os(Linux)
import FoundationNetworking
Expand Down Expand Up @@ -71,7 +73,7 @@ public struct WordPressAPI {
}

public static func extractLoginDetails(from url: URL) -> WpapiApplicationPasswordDetails? {
return WordPressAPIInternal.extractLoginDetailsFromUrl(url: url.asRestUrl())
return extractLoginDetailsFromUrl(url: url.asRestUrl())
}
}

Expand Down
2 changes: 2 additions & 0 deletions native/swift/Tests/wordpress-api/WordPressAPITests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import XCTest
import Foundation
import WordPressAPI
#if canImport(WordPressAPIInternal)
import WordPressAPIInternal
#endif

final class WordPressAPITests: XCTestCase {

Expand Down