From c4fb46c4f1324b4f6b1b813e04f8d198a9ba9c44 Mon Sep 17 00:00:00 2001 From: Marko Justinek <2903490-surpher@users.noreply.gitlab.com> Date: Mon, 13 May 2024 21:33:56 +1000 Subject: [PATCH] tech: Fix CI workflow --- .github/workflows/build_test.yml | 156 ++++--------------------------- Package.swift | 6 +- Support/build_test_linux | 120 ++++++++++++++++++++++++ Support/carthage | 46 --------- 4 files changed, 142 insertions(+), 186 deletions(-) create mode 100755 Support/build_test_linux delete mode 100755 Support/carthage diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index e3115f7..877e83d 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -1,161 +1,43 @@ -name: Build and Test +name: "Build & Test" 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_linux: + name: "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 - - - 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 - - testMacOS11: - name: "Test macOS 11" - runs-on: macos-11 - needs: [build] + - uses: fwal/setup-swift@v1 + - name: Get swift version + run: swift --version - 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" + - name: "âŦ‡ī¸ Checkout repository" + uses: actions/checkout@v4 - 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('**/Package.resolved') }} 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" - run: | - sh Support/prepare_build_tools - - - 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 - 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" + - name: "⚗ī¸ Build and Test" run: | - bash <(curl -s https://codecov.io/bash) -J 'PactSwiftMockServer' \ No newline at end of file + Support/build_test_linux 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/Support/build_test_linux b/Support/build_test_linux new file mode 100755 index 0000000..8ee15e6 --- /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 "$PWD/pact-reference" ]; then + git submodule add "$PACT_FOUNDATION_REPO" + git submodule update --init + + echo "ℹī¸ Changing location 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 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" 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