diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index e3115f7..257a23f 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -1,161 +1,50 @@ -name: Build and Test +name: "CI" on: push: branches: - - 'main' - - 'chore/**' - - 'docs/**' - - 'feat/**' - - 'feature/**' - - 'fix/**' - - 'refactor/**' - - 'releases/**' - - 'style/**' - - 'test/**' - - 'tech/**' - -env: - RUST_TARGET_PATH: pact-reference/rust/target - BINARIES_PATH: Resources + - 'legacy/**' jobs: - build: - name: "Prepare libpact_ffi binaries" - runs-on: macos-11 - timeout-minutes: 60 + test: + name: "Build & Test" + runs-on: ubuntu-latest + strategy: fail-fast: true concurrency: - group: build-macos11-${{ github.ref }} + group: pactswiftmockserver-${{ github.ref }} cancel-in-progress: true steps: - - name: "â™ģī¸ Checkout repository" - uses: actions/checkout@v2 - with: - submodules: recursive + - uses: fwal/setup-swift@v1 + - name: "Check swift version" + run: swift --version - - name: "â™ŧ Cache rust binaries" - uses: actions/cache@v3 - with: - path: | - ${{ env.RUST_TARGET_PATH }} - ${{ env.BINARIES_PATH }} - key: build-${{ runner.os }}-rust-${{ hashFiles('**/libpact_ffi.version') }} - restore-keys: | - build-${{ runner.os }}-rust- - - - name: "🔍 Check if binaries exist in ${{ env.BINARIES_PATH }}" - id: check_files - uses: andstor/file-existence-action@v1 - with: - files: "Resources/**/libpact_ffi.a" - - - name: "🎁 Prepare binaries (if not cached)" - if: steps.check_files.outputs.files_exist == 'false' - run: | - Support/build_rust_dependencies + - name: "âŦ‡ī¸ Checkout repository" + uses: actions/checkout@v4 - testMacOS11: - name: "Test macOS 11" - runs-on: macos-11 - needs: [build] - - concurrency: - group: test-${{ github.ref }}-${{ matrix.scheme }} - cancel-in-progress: true - - strategy: - fail-fast: true - matrix: - include: - - scheme: "PactSwiftMockServer-iOS" - destination: "platform=iOS Simulator,name=iPhone 12 Pro" - - scheme: "PactSwiftMockServer-macOS" - destination: "arch=x86_64" - - env: - SCHEME: ${{ matrix.scheme }} - DESTINATION: ${{ matrix.destination }} - - steps: - - name: "â™ģī¸ Checkout repository" - uses: actions/checkout@v2 - with: - submodules: recursive + - name: "Install Protoc" + uses: arduino/setup-protoc@v1 - name: "â™ŧ Cache rust binaries" uses: actions/cache@v3 with: path: | - ${{ env.RUST_TARGET_PATH }} - ${{ env.BINARIES_PATH }} - key: build-${{ runner.os }}-rust-${{ hashFiles('**/libpact_ffi.version') }} + pact-reference + key: build-${{ runner.os }}-rust-bin-${{ hashFiles('**/libpact_ffi.version') }} restore-keys: | + build-${{ runner.os }}-rust-bin build-${{ runner.os }}-rust- - - name: "🏗 Use Xcode 12.4" - run: sudo xcode-select -switch /Applications/Xcode_12.4.app - - - name: "🛠 Prepare Tools" + - name: "⚗ī¸ Build and Test" run: | - sh Support/prepare_build_tools + Support/build_test_linux - - name: "⚗ī¸ Run tests (Xcode)" - run: | - sh Support/build_test - - testMacOS12: - name: "Test macOS 12" - runs-on: macos-12 - needs: [build] - - strategy: - fail-fast: true - matrix: - include: - - scheme: "PactSwiftMockServer-iOS" - destination: "platform=iOS Simulator,name=iPhone 13 Pro" - - scheme: "PactSwiftMockServer-macOS" - destination: "arch=x86_64" - - env: - SCHEME: ${{ matrix.scheme }} - DESTINATION: ${{ matrix.destination }} - - concurrency: - group: test-${{ github.ref }}-${{ matrix.scheme }} - cancel-in-progress: true - - steps: - - name: "â™ģī¸ Checkout repository" - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: "â™ŧ Cache rust binaries" - uses: actions/cache@v3 + - name: "Upload code coverage" + id: codecov + uses: codecov/codecov-action@v4 with: - path: | - ${{ env.RUST_TARGET_PATH }} - ${{ env.BINARIES_PATH }} - key: build-${{ runner.os }}-rust-${{ hashFiles('**/libpact_ffi.version') }} - restore-keys: | - build-${{ runner.os }}-rust- - - - name: "🏗 Use Xcode 13.4.1" - run: sudo xcode-select -switch /Applications/Xcode_13.4.1.app - - - name: "🛠 Prepare Tools" - run: | - sh Support/prepare_build_tools - - - name: "⚗ī¸ Run tests (Xcode)" - run: | - sh Support/build_test - - - name: "âŦ†ī¸ Upload code coverage" - run: | - bash <(curl -s https://codecov.io/bash) -J 'PactSwiftMockServer' \ No newline at end of file + token: ${{ secrets.CODECOV_TOKEN }} + verbose: true diff --git a/.swiftlint.yml b/.swiftlint.yml index 335f20e..bcd8f51 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -48,13 +48,15 @@ opt_in_rules: - static_operator - toggle_bool - unneeded_parentheses_in_closure_argument - - unused_declaration - - unused_import - yoda_condition - xct_specific_matcher +analyzer_rules: + - unused_declaration + - unused_import + attributes: - always_on_same_line: ["@IBAction", "@objc"] + always_on_same_line: [] line_length: warning: 180 diff --git a/Package.swift b/Package.swift index e51dfcf..3fd2cc6 100644 --- a/Package.swift +++ b/Package.swift @@ -7,7 +7,7 @@ let package = Package( name: "PactSwiftMockServer", platforms: [ - .macOS(.v10_12), + .macOS(.v10_15), .iOS(.v12), .tvOS(.v12) ], @@ -28,8 +28,8 @@ let package = Package( targets: [ - // PactSwift is configured to use `https://github.com/surpher/PactSwiftServer.git` - // as a dependency. It must point to a zipped up XCFramework! + // PactSwift is configured to use `https://github.com/surpher/PactSwiftServer.git` as a dependency. + // It must point to a zipped up XCFramework not here! https://github.com/surpher/PactSwift/discussions/122 // Vending the framework for Linux platform .target( diff --git a/PactSwiftMockServer.xcfilelist b/PactSwiftMockServer.xcfilelist deleted file mode 100644 index acc0b07..0000000 --- a/PactSwiftMockServer.xcfilelist +++ /dev/null @@ -1,16 +0,0 @@ -$(SRCROOT)/Sources/Verifier.swift -$(SRCROOT)/Sources/MockServer.swift -$(SRCROOT)/Sources/Toolbox/SocketBinder.swift -$(SRCROOT)/Sources/Toolbox/Logger.swift -$(SRCROOT)/Sources/Toolbox/PactFileManager.swift -$(SRCROOT)/Sources/Model/TransferProtocol.swift -$(SRCROOT)/Sources/Model/VerificationErrorHandler.swift -$(SRCROOT)/Sources/Model/ProviderVerificationError.swift -$(SRCROOT)/Sources/Model/MismatchErrorType.swift -$(SRCROOT)/Sources/Model/VerificationErrorType.swift -$(SRCROOT)/Sources/Model/PactError.swift -$(SRCROOT)/Sources/Model/StateHandler.swift -$(SRCROOT)/Sources/Model/MismatchError.swift -$(SRCROOT)/Sources/Model/MockServerError.swift -$(SRCROOT)/Sources/Model/VerificationError.swift -$(SRCROOT)/Sources/Model/RequestError.swift diff --git a/README.md b/README.md index 7fb45bf..1e288e5 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,11 @@ -# PactSwiftMockServer +# PactSwiftMockServer -[![Build and Test](https://github.com/surpher/PactSwiftMockServer/actions/workflows/build_test.yml/badge.svg?branch=main)](https://github.com/surpher/PactSwiftMockServer/actions/workflows/build_test.yml) +[![CI](https://github.com/surpher/PactSwiftMockServer/actions/workflows/build_test.yml/badge.svg?branch=legacy%2Fv0.5.0)](https://github.com/surpher/PactSwiftMockServer/actions/workflows/build_test.yml) [![MIT License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE.md) [![codecov](https://codecov.io/gh/surpher/PactSwiftMockServer/branch/main/graph/badge.svg?token=0LYZVF36I9)](https://codecov.io/gh/surpher/PactSwiftMockServer) -A wrapper around [`libpact_ffi.a`](https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_ffi) binary and exposed as XCFramework to be primarily used by [`PactSwift`](https://github.com/surpher/PactSwift). +A wrapper around [`libpact_ffi.a`](https://github.com/pact-foundation/pact-reference/tree/master/rust/pact_ffi) binary and exposed as archived XCFramework (surpher/PactSwiftServer.git). -But nothing is stopping you from creating your own interface using this package. +Used as an external module to serve [`PactSwift`](https://github.com/surpher/PactSwift) for iOS, macOS and tvOS platforms. + +Used as a Swift Package for Linux platforms. diff --git a/Support/build_test_linux b/Support/build_test_linux new file mode 100755 index 0000000..a5285d0 --- /dev/null +++ b/Support/build_test_linux @@ -0,0 +1,120 @@ +#!/usr/bin/env bash + +set -euo pipefail + +# ### Pre-requisites: +# +# `pact-reference` repo and `PactSwift` repo are on the same folder level +# +# ### Usage: +# ./Support/build_rust_dependencies +# +# In order to minimise the built binary size update $LIBPACT_FFI_DI/Cargo.toml and append the following: +# +# [lib] +# crate-type = ["staticlib"] +# +# [profile.release] +# opt-level = 'z' +# lto = true +# panic = 'abort' +# +####################### + +PRODUCT_NAME="PactSwiftMockServer" +WORKSPACE=${GITHUB_WORKSPACE:-$PWD} +LIBPACT_FFI_VERSION="0.4.20" +LIBPACT_FFI_DIR="${WORKSPACE}/pact-reference/rust/pact_ffi" +LIBPACT_PRODUCT_DIR="${WORKSPACE}/pact-reference/rust/target/debug" +CI=${CI:-"false"} +PACT_FOUNDATION_REPO="https://github.com/pact-foundation/pact-reference.git" + +####################### +# Pre-requisite # +####################### + +if [ ! -d "$PWD/$PRODUCT_NAME.xcodeproj" ] +then + echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives." + echo "⚠ī¸ You are runing it in $PWD" + exit 1 +fi + +####################### +# If CI # +####################### + +echo "👮‍♀ī¸ Verifying project and dependencies' folder setup..." + +if [[ "$CI" == true ]]; then + echo "ℹī¸ Adding submodule ${PACT_FOUNDATION_REPO}" + if [ ! -d "$LIBPACT_FFI_DIR" ]; then + # git submodule add "$PACT_FOUNDATION_REPO" + git submodule update --init + + echo "ℹī¸ Changing location (1) to ${LIBPACT_FFI_DIR}" + cd "$LIBPACT_FFI_DIR" + git fetch --all --tags + git checkout "tags/libpact_ffi-v$LIBPACT_FFI_VERSION" + fi + + export LD_LIBRARY_PATH="/usr/local/lib" + +elif [ ! -d "$PWD/../pact-reference" ]; then + # TODO: fix this for running locally + echo "🚨 Missing pact-foundation/pact-reference repo." + echo "⚠ī¸ Make sure you 'git clone ${PACT_FOUNDATION_REPO}' at the same folder level as your $PRODUCT_NAME." + exit 1 +else + echo "👍 Project setup seems to be in order." +fi + +echo "ℹī¸ Changing location (2) to ${LIBPACT_FFI_DIR}" +cd "$LIBPACT_FFI_DIR" + +####################### +# Setup # +####################### + +# Validate dependencies + +echo "👮‍♀ī¸ Checking if Rust is installed..." +if which cargo >/dev/null; then + echo "👍 cargo installed" +elif command -v ~/.cargo/bin/cargo &> /dev/null; then + echo "👍 cargo installed in ~/.cargo/bin/" +else + echo "🚨 Rust/Cargo not installed" + echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install" + exit 1 +fi + +############################################## +# Build libpact_ffi libraries # +############################################## + +# Using debug build flag (or not providing it), otherwise libpact_ffi.so must be moved into /usr/local/lib/ +echo "🏗 Building libpact_ffi for current platform (debug build)" +cargo build +echo "✅ libpact_ffi built" + +echo "ℹī¸ Setting LD_LIBRARY_PATH to include $LIBPACT_PRODUCT_DIR" +export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$LIBPACT_PRODUCT_DIR" + +####################### +# Cleanup # +####################### + +echo "ℹī¸ Changing directory back to ${WORKSPACE}" +cd "${WORKSPACE}" + +############################################################################################################## +# Run Swift buld and test # +# https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#requiring-system-libraries # +############################################################################################################## + +echo "ℹī¸ Running swift build:" +swift build -Xlinker -L"$LIBPACT_PRODUCT_DIR" + +echo "ℹī¸ Running swift test with -Xlinker -L$LIBPACT_PRODUCT_DIR" +swift test -Xlinker -L"$LIBPACT_PRODUCT_DIR" --enable-code-coverage --verbose diff --git a/Support/carthage b/Support/carthage deleted file mode 100755 index c41d52d..0000000 --- a/Support/carthage +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bash - -# carthage workaround -# Usage example: ./carthage build --platform iOS -# -# Source(s): -# - https://github.com/Carthage/Carthage/issues/3201 -# - https://github.com/Carthage/Carthage/issues/3019#issuecomment-665136323 -# - https://github.com/Carthage/Carthage/issues/3019#issuecomment-734415287 -# - -set -euo pipefail - -# Determine architecture of current machine -ACTIVE_ARCH=$(uname -m) - -if [[ $ACTIVE_ARCH == "x86_64" ]]; then - - # If running on Intel machine, do the excluded architectures dance 💃đŸ•ē - - xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX) - trap 'rm -f "$xcconfig"' INT TERM HUP EXIT - - echo "⚠ī¸ NOTE: Using Carthage workaround script..." - - # For Xcode 12 and 13 make sure EXCLUDED_ARCHS is set to arm architectures otherwise - # the build will fail on lipo due to duplicate architectures. - - CURRENT_XCODE_VERSION="$(xcodebuild -version | grep "Xcode" | cut -d' ' -f2 | cut -d'.' -f1)00" - CURRENT_XCODE_BUILD=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3) - - echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_${CURRENT_XCODE_VERSION}__BUILD_${CURRENT_XCODE_BUILD} = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig - - echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_'${CURRENT_XCODE_VERSION}' = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_$(XCODE_VERSION_MAJOR)__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig - echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig - - export XCODE_XCCONFIG_FILE="$xcconfig" - carthage "$@" - -else - - # Running on arm64 machine so just use the plain carthage - echo "⚠ī¸ NOTE: Using plain vanilla Carthage..." - carthage "$@" - -fi diff --git a/libpact_ffi.version b/libpact_ffi.version index 271864d..b099455 100644 --- a/libpact_ffi.version +++ b/libpact_ffi.version @@ -1 +1 @@ -libpact_ffi-v0.3.11 +libpact_ffi-v0.4.20 diff --git a/pact-reference b/pact-reference index 14e5ce3..e44458a 160000 --- a/pact-reference +++ b/pact-reference @@ -1 +1 @@ -Subproject commit 14e5ce3334db82a09df550bcba91ac11e4e6b9c7 +Subproject commit e44458a8616856d3726470dd8f3884340999bf1e