diff --git a/.buildkite/download-xcframework.sh b/.buildkite/download-xcframework.sh new file mode 100755 index 000000000..612f70c10 --- /dev/null +++ b/.buildkite/download-xcframework.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -euo pipefail + +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 diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 6af53a1c2..96232f625 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -85,8 +85,14 @@ steps: make test-swift-linux - label: ":swift: Lint" command: | + .buildkite/download-xcframework.sh echo "--- :swift: Swiftlint" make lint-swift + depends_on: xcframework + env: + IMAGE_ID: xcode-15.3 + agents: + queue: mac # # Kotlin Group - group: ":kotlin: Kotlin Wrapper" diff --git a/.buildkite/swift-test.sh b/.buildkite/swift-test.sh index 455da7712..a4f64fe09 100755 --- a/.buildkite/swift-test.sh +++ b/.buildkite/swift-test.sh @@ -2,11 +2,8 @@ set -euo pipefail -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 +.buildkite/download-xcframework.sh + export SKIP_PACKAGE_WP_API=true function run_tests() { @@ -23,6 +20,7 @@ function build_for_real_device() { xcodebuild -destination "generic/platform=$platform" \ -scheme WordPress \ -derivedDataPath DerivedData \ + -skipPackagePluginValidation \ build | xcbeautify } diff --git a/.buildkite/validate-cocoapods.sh b/.buildkite/validate-cocoapods.sh index fe24ad8dc..faa5bd57a 100755 --- a/.buildkite/validate-cocoapods.sh +++ b/.buildkite/validate-cocoapods.sh @@ -41,11 +41,8 @@ Pod::Spec.new do |spec| 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 +.buildkite/download-xcframework.sh + export SKIP_PACKAGE_WP_API=true echo "--- :rubygems: Setting up Gems" diff --git a/.swiftlint.yml b/.swiftlint.yml index a03c9e1e0..8f4983eda 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,4 +1,4 @@ -swiftlint_version: 0.53.0 +swiftlint_version: 0.55.1 strict: true included: - native/swift diff --git a/Makefile b/Makefile index d8e06c87d..ca6f5616e 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ docker_container_repo_dir=/app # Common docker options rust_docker_container := public.ecr.aws/docker/library/rust:1.76 -swiftlint_container := ghcr.io/realm/swiftlint:0.53.0 docker_opts_shared := --rm -v "$(PWD)":$(docker_container_repo_dir) -w $(docker_container_repo_dir) rust_docker_run := docker run -v $(PWD):/$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it -e CARGO_HOME=/app/.cargo $(rust_docker_container) @@ -181,10 +180,10 @@ lint-rust: $(rust_docker_run) /bin/bash -c "rustup component add clippy && cargo clippy --all -- -D warnings && cargo clippy --tests --all -- -D warnings" lint-swift: - docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint + swift package plugin swiftlint lintfix-swift: - docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint --autocorrect + swift package plugin swiftlint --autocorrect fmt-rust: $(rust_docker_run) /bin/bash -c "rustup component add rustfmt && cargo fmt" diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 000000000..62c52f596 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,86 @@ +{ + "pins" : [ + { + "identity" : "collectionconcurrencykit", + "kind" : "remoteSourceControl", + "location" : "https://github.com/JohnSundell/CollectionConcurrencyKit.git", + "state" : { + "revision" : "b4f23e24b5a1bff301efc5e70871083ca029ff95", + "version" : "0.2.0" + } + }, + { + "identity" : "cryptoswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krzyzanowskim/CryptoSwift.git", + "state" : { + "revision" : "c9c3df6ab812de32bae61fc0cd1bf6d45170ebf0", + "version" : "1.8.2" + } + }, + { + "identity" : "sourcekitten", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/SourceKitten.git", + "state" : { + "revision" : "fd4df99170f5e9d7cf9aa8312aa8506e0e7a44e7", + "version" : "0.35.0" + } + }, + { + "identity" : "swift-argument-parser", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-argument-parser.git", + "state" : { + "revision" : "0fbc8848e389af3bb55c182bc19ca9d5dc2f255b", + "version" : "1.4.0" + } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-syntax.git", + "state" : { + "revision" : "303e5c5c36d6a558407d364878df131c3546fad8", + "version" : "510.0.2" + } + }, + { + "identity" : "swiftlint", + "kind" : "remoteSourceControl", + "location" : "https://github.com/realm/SwiftLint", + "state" : { + "revision" : "b515723b16eba33f15c4677ee65f3fef2ce8c255", + "version" : "0.55.1" + } + }, + { + "identity" : "swiftytexttable", + "kind" : "remoteSourceControl", + "location" : "https://github.com/scottrhoyt/SwiftyTextTable.git", + "state" : { + "revision" : "c6df6cf533d120716bff38f8ff9885e1ce2a4ac3", + "version" : "0.9.0" + } + }, + { + "identity" : "swxmlhash", + "kind" : "remoteSourceControl", + "location" : "https://github.com/drmohundro/SWXMLHash.git", + "state" : { + "revision" : "a853604c9e9a83ad9954c7e3d2a565273982471f", + "version" : "7.0.2" + } + }, + { + "identity" : "yams", + "kind" : "remoteSourceControl", + "location" : "https://github.com/jpsim/Yams.git", + "state" : { + "revision" : "9234124cff5e22e178988c18d8b95a8ae8007f76", + "version" : "5.1.2" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift index 49e91dec4..7279d37a3 100644 --- a/Package.swift +++ b/Package.swift @@ -1,12 +1,8 @@ // swift-tools-version:5.10 +import Foundation import PackageDescription -enum WordPressRSVersion { - case local - case release(version: String, checksum: String) -} - let libwordpressFFIVersion: WordPressRSVersion = .local #if os(Linux) @@ -15,20 +11,10 @@ let libwordpressFFI: Target = .systemLibrary( path: "target/swift-bindings/libwordpressFFI-linux/" ) #elseif os(macOS) -let libwordpressFFI: Target -switch libwordpressFFIVersion { - case .local: - libwordpressFFI = .binaryTarget(name: "libwordpressFFI", path: "target/libwordpressFFI.xcframework") - case let .release(version, checksum): - libwordpressFFI = .binaryTarget( - name: "libwordpressFFI", - url: "https://github.com/Automattic/wordpress-rs/releases/download/\(version)/libwordpressFFI.xcframework.zip", - checksum: checksum - ) -} +let libwordpressFFI: Target = libwordpressFFIVersion.target #endif -let package = Package( +var package = Package( name: "WordPress", platforms: [ .iOS(.v13), @@ -75,3 +61,66 @@ let package = Package( ) ] ) + +// MARK: - Enable local development toolings + +let localDevelopment = libwordpressFFIVersion.isLocal + +if localDevelopment { + try enableSwiftLint() +} + +// MARK: - Helpers + +enum WordPressRSVersion { + case local + case release(version: String, checksum: String) + + var isLocal: Bool { + if case .local = self { + return true + } + return false + } + + var target: Target { + switch libwordpressFFIVersion { + case .local: + return .binaryTarget(name: "libwordpressFFI", path: "target/libwordpressFFI.xcframework") + case let .release(version, checksum): + return .binaryTarget( + name: "libwordpressFFI", + url: "https://github.com/Automattic/wordpress-rs/releases/download/\(version)/libwordpressFFI.xcframework.zip", + checksum: checksum + ) + } + } +} + +// Add SwiftLint to the package so that we can see linting issues directly from Xcode. +func enableSwiftLint() throws { +#if os(macOS) + let version = try String(contentsOf: URL(string:"./.swiftlint.yml", relativeTo: URL(filePath: #filePath))!) + .split(separator: "\n") + .first(where: { $0.starts(with: "swiftlint_version") })? + .split(separator: ":") + .last? + .trimmingCharacters(in: .whitespaces) + guard let version else { + fatalError("Can't find swiftlint_version in .swiftlint.yml") + } + + package.dependencies.append(.package(url: "https://github.com/realm/SwiftLint", exact: .init(version)!)) + + var platforms = package.platforms ?? [] + if let mac = platforms.firstIndex(where: { $0 == .macOS(.v11) }) { + platforms.remove(at: mac) + platforms.append(.macOS(.v12)) + } + package.platforms = platforms + + if let target = package.targets.first(where: { $0.name == "WordPressAPI" }) { + target.plugins = (target.plugins ?? []) + [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")] + } +#endif +} diff --git a/scripts/xcodebuild-test.sh b/scripts/xcodebuild-test.sh index 46c2ccdde..89f47149c 100755 --- a/scripts/xcodebuild-test.sh +++ b/scripts/xcodebuild-test.sh @@ -14,5 +14,6 @@ xcodebuild \ -scheme WordPress \ -derivedDataPath DerivedData \ -destination "id=${device_id}" \ + -skipPackagePluginValidation \ test \ | xcbeautify