-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marko Justinek
committed
May 13, 2024
1 parent
4b7d382
commit c4fb46c
Showing
4 changed files
with
142 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' | ||
Support/build_test_linux |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file was deleted.
Oops, something went wrong.