diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ca135af5..037e3ea9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,8 @@ jobs: os: macos-15 - arch: ARM64 os: ubuntu-24.04-arm + - arch: ARM64 + os: windows-11-arm runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v7 @@ -75,8 +77,52 @@ jobs: name: nupkgs path: ./dist/*.* + build-dotnet-containers: + runs-on: ubuntu-latest + name: ${{ matrix.os }}-${{ matrix.distro }}-build-dotnet-container + strategy: + fail-fast: false + matrix: + os: + - ubuntu-24.04 + - ubuntu-24.04-arm + distro: + - "mcr.microsoft.com/dotnet/sdk:8.0" + - "mcr.microsoft.com/dotnet/sdk:8.0-alpine3.22" + - "mcr.microsoft.com/dotnet/sdk:8.0-alpine3.23" + - "mcr.microsoft.com/dotnet/sdk:8.0-alpine3.24" + + steps: + - uses: actions/checkout@v4 + + - name: Docker dependencies + id: docker_commands + shell: bash + run: | + if [[ ${{ matrix.distro }} == *"alpine"* ]]; then + echo "deps=apk add --no-cache curl bash gzip && " >> "$GITHUB_OUTPUT" + else + echo "deps=apt-get update && apt-get install -y --no-install-recommends unzip xz-utils && " >> "$GITHUB_OUTPUT" + fi + + - name: Restore, Build & Test + run: | + docker run \ + --rm \ + -v $(pwd):/${{ github.workspace }} \ + -w ${{ github.workspace }} \ + --entrypoint /bin/sh \ + ${{ matrix.distro }} \ + -c '${{ steps.docker_commands.outputs.deps }} \ + build/download-native-libs.sh && \ + dotnet restore && dotnet build --no-restore && \ + dotnet test --no-build --verbosity normal' + release: - needs: build-dotnet + needs: [ + build-dotnet, + build-dotnet-containers + ] if: github.ref_type == 'tag' runs-on: ubuntu-latest steps: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a8aa3f7a..3d4b830c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -53,14 +53,16 @@ Building PactNet ---------------- In order to build PactNet you must first download the native Rust FFI libraries. You can pull the current supported -version by executing the script in Bash (or Git Bash on Windows): +version by executing the script in Bash (or Git Bash on Windows). The script needs `curl`, `tar` with xz support, and +`unzip` (or `7z`) on the path, and verifies each archive against its `.sha256` file: ```bash build/download-native-libs.sh ``` -Alternatively you can download a particular FFI version from the [pact-reference] releases or build your own version -locally, and then copy the artifacts into the folders: +Alternatively you can download a particular FFI version from the [pact-reference] `pact_ffi-v` releases (one +archive per Rust target, e.g. `pact_ffi-aarch64-apple-darwin.tar.xz`) or build your own version locally, and then copy +the shared libraries into the folders: ``` build/ @@ -69,12 +71,14 @@ build/ libpact_ffi.so aarch64/ libpact_ffi.so - osx/ + macos/ aarch64/ libpact_ffi.dylib x86_64/ libpact_ffi.dylib windows/ + aarch64/ + pact_ffi.dll x86_64/ pact_ffi.dll ``` diff --git a/README.md b/README.md index c70c541b..9da77baf 100644 --- a/README.md +++ b/README.md @@ -232,16 +232,18 @@ For writing messaging pacts instead of requests/response pacts, see the [messagi Due to using a shared native library instead of C# for the main Pact logic only certain OSs are supported: -| OS | Arch | Support | -| ------------ | ------------ | -------------------------------------------------------------------| -| Windows | x86 | ❌ No | -| Windows | x64 | ✔️ Yes | -| Linux (libc) | ARM64 | ✔️ Yes | -| Linux (libc) | x64 | ✔️ Yes | -| Linux (libc) | x86 | ❌ No | -| Linux (musl) | Any | ❌ [No](https://github.com/pact-foundation/pact-net/issues/374) | -| OSX | x64 | ✔️ Yes | -| OSX | ARM64 (M1/M2)| ✔️ Yes | +| OS | Arch | Support | +| ------------ | ------------- | -------------------------------------------------------------------| +| Windows | x86 | ❌ No | +| Windows | x64 | ✔️ Yes | +| Windows | ARM64 | ✔️ Yes | +| Linux (libc) | ARM64 | ✔️ Yes | +| Linux (libc) | x64 | ✔️ Yes | +| Linux (libc) | x86 | ❌ No | +| Linux (musl) | ARM64 | ✔️ Yes | +| Linux (musl) | x64 | ✔️ Yes | +| OSX | x64 | ✔️ Yes | +| OSX | ARM64 (M1/M2) | ✔️ Yes | ### Pact Specification diff --git a/build/PactNet.targets b/build/PactNet.targets index 0b3218e5..f475bbc2 100644 --- a/build/PactNet.targets +++ b/build/PactNet.targets @@ -1,7 +1,19 @@ - - + + + + pact_ffi.dll + PreserveNewest + false + + + pact_ffi.dll PreserveNewest diff --git a/build/download-native-libs.sh b/build/download-native-libs.sh index c3ace891..79a0a60b 100755 --- a/build/download-native-libs.sh +++ b/build/download-native-libs.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -FFI_VERSION="0.4.27" -FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION" +FFI_VERSION="0.5.13" +FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/pact_ffi-v$FFI_VERSION" GREEN="\e[32m" YELLOW="\e[33m" @@ -12,60 +12,83 @@ CLEAR="\e[0m" base_path=$(dirname "$0") download_native() { - file="$1" - os="$2" - platform="$3" - extension="$4" + os="$1" + platform="$2" + target="$3" + archive_ext="$4" + lib="$5" # e.g. - # pact_ffi-windows-x86_64.dll.gz - # libpact_ffi-linux-x86_64.so.gz - # libpact_ffi-macos-x86_64.dylib.gz - src_file="$file-$os-$platform.$extension" - src_archive="$src_file.gz" + # pact_ffi-x86_64-pc-windows-msvc.zip (pact_ffi.dll at the archive root) + # pact_ffi-x86_64-unknown-linux-gnu.tar.xz (pact_ffi-/libpact_ffi.so) + # pact_ffi-aarch64-apple-darwin.tar.xz (pact_ffi-/libpact_ffi.dylib) + src_archive="pact_ffi-$target.$archive_ext" src_sha="$src_archive.sha256" - dest_file="$file.$extension" url="$FFI_BASE_URL/$src_archive" sha="$url.sha256" path="$base_path/$os/$platform" mkdir -p "$path" - pushd $path > /dev/null + pushd "$path" > /dev/null echo -e "Downloading FFI library for ${YELLOW}$os/$platform${CLEAR}" - echo -e " Destination: ${BLUE}$path/$src_archive${CLEAR}" + echo -e " Destination: ${BLUE}$path/$lib${CLEAR}" echo -e " URL: ${BLUE}$url${CLEAR}" echo -n " Downloading... " - curl --silent -L "$url" -o "$src_archive" - curl --silent -L "$sha" -o "$src_archive.sha256" + curl --silent --show-error --fail -L "$url" -o "$src_archive" + curl --silent --show-error --fail -L "$sha" -o "$src_sha" echo -e "${GREEN}OK${CLEAR}" echo -n " Verifying... " if [[ "$OSTYPE" == "darwin"* ]]; then - shasum -a 256 --check --quiet "$src_sha" + sed '/^$/d' "$src_sha" | shasum -a 256 --check --quiet - else - sha256sum --check --quiet "$src_sha" + # GNU coreutils and BusyBox (Alpine) both accept plain -c on a file + sed -i '/^$/d' "$src_sha" + sha256sum -c "$src_sha" > /dev/null fi echo -e "${GREEN}OK${CLEAR}" echo -n " Extracting... " - gunzip -f "$src_archive" + extract_dir=$(mktemp -d) + if [[ "$archive_ext" == "zip" ]]; then + extract_zip "$src_archive" "$extract_dir" + extracted="$extract_dir/$lib" + else + tar -xJf "$src_archive" -C "$extract_dir" + extracted="$extract_dir/pact_ffi-$target/$lib" + fi + mv -f "$extracted" "$lib" + rm -rf "$extract_dir" "$src_archive" "$src_sha" echo -e "${GREEN}OK${CLEAR}" echo "" - mv "$src_file" "$dest_file" - rm "$src_sha" - popd > /dev/null } -download_native "pact_ffi" "windows" "x86_64" "dll" -download_native "libpact_ffi" "linux" "x86_64" "so" -download_native "libpact_ffi" "linux" "aarch64" "so" -download_native "libpact_ffi" "macos" "x86_64" "dylib" -download_native "libpact_ffi" "macos" "aarch64" "dylib" +extract_zip() { + if command -v unzip > /dev/null; then + unzip -q -o "$1" -d "$2" + elif command -v 7z > /dev/null; then + 7z x -y -o"$2" "$1" > /dev/null + elif tar --version 2>/dev/null | grep -q bsdtar; then + tar -xf "$1" -C "$2" + else + echo "error: unzip (or 7z/bsdtar) is required to extract $1" >&2 + exit 1 + fi +} + +download_native "windows" "x86_64" "x86_64-pc-windows-msvc" "zip" "pact_ffi.dll" +download_native "windows" "aarch64" "aarch64-pc-windows-msvc" "zip" "pact_ffi.dll" +download_native "linux" "x86_64" "x86_64-unknown-linux-gnu" "tar.xz" "libpact_ffi.so" +download_native "linux" "aarch64" "aarch64-unknown-linux-gnu" "tar.xz" "libpact_ffi.so" +download_native "macos" "x86_64" "x86_64-apple-darwin" "tar.xz" "libpact_ffi.dylib" +download_native "macos" "aarch64" "aarch64-apple-darwin" "tar.xz" "libpact_ffi.dylib" +download_native "linux" "x86_64-musl" "x86_64-unknown-linux-musl" "tar.xz" "libpact_ffi.so" +download_native "linux" "aarch64-musl" "aarch64-unknown-linux-musl" "tar.xz" "libpact_ffi.so" -echo "Successfully downloaded FFI libraries" \ No newline at end of file +echo "Successfully downloaded FFI libraries" diff --git a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json index b6f1a702..70cb05f7 100644 --- a/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json +++ b/samples/OrdersApi/Consumer.Tests/pacts/Fulfilment API-Orders API.json @@ -158,8 +158,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "4.0" diff --git a/samples/OrdersApi/Provider.Tests/Provider.Tests.csproj b/samples/OrdersApi/Provider.Tests/Provider.Tests.csproj index 1517e0f4..dbae7d98 100644 --- a/samples/OrdersApi/Provider.Tests/Provider.Tests.csproj +++ b/samples/OrdersApi/Provider.Tests/Provider.Tests.csproj @@ -2,6 +2,9 @@ net8.0 false + + false diff --git a/src/PactNet/PactNet.csproj b/src/PactNet/PactNet.csproj index 3cb10197..908dfa7d 100644 --- a/src/PactNet/PactNet.csproj +++ b/src/PactNet/PactNet.csproj @@ -10,15 +10,18 @@ + - False - False - False - False - True - True - True - True + $(NETCoreSdkPortableRuntimeIdentifier) + $(NETCoreSdkRuntimeIdentifier) + $([System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier) @@ -26,35 +29,56 @@ pact_ffi.dll runtimes/win-x64/native true - PreserveNewest + PreserveNewest + false + + + pact_ffi.dll + runtimes/win-arm64/native + true + PreserveNewest false libpact_ffi.so runtimes/linux-x64/native true - PreserveNewest + PreserveNewest false libpact_ffi.so runtimes/linux-arm64/native true - PreserveNewest + PreserveNewest + false + + + libpact_ffi.so + runtimes/linux-musl-x64/native + true + PreserveNewest + false + + + libpact_ffi.so + runtimes/linux-musl-arm64/native + true + PreserveNewest false libpact_ffi.dylib runtimes/osx-x64/native true - PreserveNewest + PreserveNewest false libpact_ffi.dylib runtimes/osx-arm64/native true - PreserveNewest + PreserveNewest false diff --git a/src/PactNet/Verifier/Messaging/MessagingProvider.cs b/src/PactNet/Verifier/Messaging/MessagingProvider.cs index 5b70cef5..d531cf75 100644 --- a/src/PactNet/Verifier/Messaging/MessagingProvider.cs +++ b/src/PactNet/Verifier/Messaging/MessagingProvider.cs @@ -74,9 +74,9 @@ public Uri Start(JsonSerializerOptions settings) this.server.Prefixes.Add(uri.AbsoluteUri); this.server.Start(); } - catch (HttpListenerException e) when (e.Message == "Address already in use") + catch (HttpListenerException e) when (IsAddressInUse(e)) { - // handle intermittent race condition, mostly on MacOS, where a port says it's unused but still throws when you try to use it + // handle intermittent race condition, where a port says it's unused but still throws when you try to use it this.config.WriteLine("Failed to start messaging provider as the port is already in use, retrying..."); continue; } @@ -90,6 +90,27 @@ public Uri Start(JsonSerializerOptions settings) } } + /// + /// Check if the listener failed to start because the port is already bound + /// + /// + /// The error code is the platform errno for EADDRINUSE. The message text differs by libc + /// (glibc: "Address already in use", musl: "Address in use"), so it is only a fallback. + /// + /// Listener exception + /// Port was already in use + private static bool IsAddressInUse(HttpListenerException e) + { + const int LinuxAddressInUse = 98; + const int MacAddressInUse = 48; + const int WindowsSocketAddressInUse = 10048; + + return e.ErrorCode == LinuxAddressInUse + || e.ErrorCode == MacAddressInUse + || e.ErrorCode == WindowsSocketAddressInUse + || e.Message.IndexOf("in use", StringComparison.OrdinalIgnoreCase) >= 0; + } + /// /// Find an unused port on which to host the messaging server /// diff --git a/tests/PactNet.Tests/data/v2-consumer-integration.json b/tests/PactNet.Tests/data/v2-consumer-integration.json index 9484eef4..83b46b98 100644 --- a/tests/PactNet.Tests/data/v2-consumer-integration.json +++ b/tests/PactNet.Tests/data/v2-consumer-integration.json @@ -74,8 +74,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "2.0.0" diff --git a/tests/PactNet.Tests/data/v3-consumer-integration.json b/tests/PactNet.Tests/data/v3-consumer-integration.json index b220eb49..7244aa1b 100644 --- a/tests/PactNet.Tests/data/v3-consumer-integration.json +++ b/tests/PactNet.Tests/data/v3-consumer-integration.json @@ -130,8 +130,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-message-consumer-integration.json b/tests/PactNet.Tests/data/v3-message-consumer-integration.json index 494ea225..5e44b239 100644 --- a/tests/PactNet.Tests/data/v3-message-consumer-integration.json +++ b/tests/PactNet.Tests/data/v3-message-consumer-integration.json @@ -36,8 +36,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-message-integration.json b/tests/PactNet.Tests/data/v3-message-integration.json index 4a3ace22..07786942 100644 --- a/tests/PactNet.Tests/data/v3-message-integration.json +++ b/tests/PactNet.Tests/data/v3-message-integration.json @@ -16,8 +16,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v3-server-integration.json b/tests/PactNet.Tests/data/v3-server-integration.json index c5050bd5..10db5b91 100644 --- a/tests/PactNet.Tests/data/v3-server-integration.json +++ b/tests/PactNet.Tests/data/v3-server-integration.json @@ -46,8 +46,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "3.0.0" diff --git a/tests/PactNet.Tests/data/v4-combined-integration.json b/tests/PactNet.Tests/data/v4-combined-integration.json index 61808511..4739dcf1 100644 --- a/tests/PactNet.Tests/data/v4-combined-integration.json +++ b/tests/PactNet.Tests/data/v4-combined-integration.json @@ -185,8 +185,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "4.0" diff --git a/tests/PactNet.Tests/data/v4-consumer-integration.json b/tests/PactNet.Tests/data/v4-consumer-integration.json index 87ef562b..409bc40c 100644 --- a/tests/PactNet.Tests/data/v4-consumer-integration.json +++ b/tests/PactNet.Tests/data/v4-consumer-integration.json @@ -150,8 +150,8 @@ ], "metadata": { "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "4.0" diff --git a/tests/PactNet.Tests/data/v4-message-consumer-integration.json b/tests/PactNet.Tests/data/v4-message-consumer-integration.json index 8861180b..ddd378f1 100644 --- a/tests/PactNet.Tests/data/v4-message-consumer-integration.json +++ b/tests/PactNet.Tests/data/v4-message-consumer-integration.json @@ -41,8 +41,8 @@ "language": "C#" }, "pactRust": { - "ffi": "0.4.27", - "models": "1.2.8" + "ffi": "0.5.13", + "models": "1.3.18" }, "pactSpecification": { "version": "4.0"