From 9f7be846ef343362c8610ee18261de6861eab683 Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Tue, 20 Oct 2026 16:09:57 +1100 Subject: [PATCH] chore: download pact_ffi from the dist-built release pact-reference publishes pact_ffi through cargo-dist from 0.5.12 as `pact_ffi-v`, with one `pact_ffi-.{tar.xz,zip}` archive per Rust target triple. The legacy `libpact_ffi-v` release with single-file .gz assets stops on 2027-06-30. - platforms.rb maps each native lib directory to its target triple. - download_libs.rb fetches the archive and its .sha256, verifies the digest, and extracts only the shared library (tar for tar.xz, unzip for the Windows zip) into the same ffi// path. Headers come from the new release. - release.rb selects the newest `pact_ffi-v` release. - version.rb moves from 0.5.8.1 to 0.5.12.0, because the archive layout exists from pact_ffi 0.5.12 onwards. - DEVELOPING.md names the new tag. Assisted-by: Claude Code:claude-opus-5-5 --- DEVELOPING.md | 4 ++-- lib/pact/ffi/version.rb | 2 +- script/download_libs.rb | 53 +++++++++++++++++++++++++++++++---------- script/lib/platforms.rb | 21 ++++++++-------- script/release.rb | 2 +- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index b4fa263..58257f6 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -19,9 +19,9 @@ make grpc # gRPC plugin demo (see examples/area_calculator/DEVE Releases are fully automated via the PR-driven flow in `.github/workflows/release.yml`. -The gem version is `{ffi}.{N}`, where the first three components mirror the latest [`libpact_ffi`](https://github.com/pact-foundation/pact-reference/releases) release that the gem wraps, and `{N}` is a wrapper-only revision. `{N}` resets to `0` when a new upstream `libpact_ffi` is released and increments otherwise. This keeps the gem tracking upstream FFI releases automatically. The native library version downloaded at build time is derived from these first three components (see `script/download_libs.rb`), so the version in `lib/pact/ffi/version.rb` is the single source of truth. +The gem version is `{ffi}.{N}`, where the first three components mirror the latest [`pact_ffi`](https://github.com/pact-foundation/pact-reference/releases?q=pact_ffi-v) release (tag `pact_ffi-v`) that the gem wraps, and `{N}` is a wrapper-only revision. `{N}` resets to `0` when a new upstream `pact_ffi` is released and increments otherwise. This keeps the gem tracking upstream FFI releases automatically. The native library version downloaded at build time is derived from these first three components (see `script/download_libs.rb`), so the version in `lib/pact/ffi/version.rb` is the single source of truth. -1. **On every push to `main`**, the `prepare` job runs `script/release.rb prepare`, which looks up the latest upstream `libpact_ffi` release, computes the next version from it, updates `lib/pact/ffi/version.rb` and `CHANGELOG.md` (changelog body via git-cliff), force-pushes to `release/pact-ffi`, and creates or updates a **draft** release PR. +1. **On every push to `main`**, the `prepare` job runs `script/release.rb prepare`, which looks up the latest upstream `pact_ffi-v*` release, computes the next version from it, updates `lib/pact/ffi/version.rb` and `CHANGELOG.md` (changelog body via git-cliff), force-pushes to `release/pact-ffi`, and creates or updates a **draft** release PR. 2. **When ready to release**, promote the PR from draft → ready-for-review. This triggers CI including a full multi-platform gem build dry-run. You can edit `version.rb` or `CHANGELOG.md` directly on the `release/pact-ffi` branch to make manual adjustments — those files are the source of truth. **Caution:** any new push to `main` while the PR is open will re-run `prepare` and force-push the computed version/changelog over any manual edits. diff --git a/lib/pact/ffi/version.rb b/lib/pact/ffi/version.rb index b4c8551..74a5b63 100644 --- a/lib/pact/ffi/version.rb +++ b/lib/pact/ffi/version.rb @@ -1,5 +1,5 @@ module Pact module Version - VERSION = '0.5.8.1' + VERSION = '0.5.12.0' end end diff --git a/script/download_libs.rb b/script/download_libs.rb index db99e3f..63ac2d8 100644 --- a/script/download_libs.rb +++ b/script/download_libs.rb @@ -12,7 +12,8 @@ # tracks its own upstream and is pinned here. require 'fileutils' -require 'zlib' +require 'digest' +require 'tmpdir' require_relative 'lib/platforms' require_relative '../lib/pact/ffi/version' @@ -58,17 +59,44 @@ def fetch(url, dest) system('curl', '--silent', '--show-error', '--fail', '--location', '--output', dest, url) end -def fetch_gz(url, dest) - gz = "#{dest}.gz" - fetch(url, gz) - File.open(dest, 'wb') do |out| - Zlib::GzipReader.open(gz) do |reader| - while (chunk = reader.read(65_536)) - out.write(chunk) +# Downloads the `pact_ffi-` archive, checks it against its published +# .sha256 and extracts only the shared library to `dest`. Windows archives are +# zips with the files at the root; the others are tar.xz with a top-level +# `pact_ffi-/` directory. +def fetch_ffi_lib(native, dest) + target = native[:target] + windows = target.include?('windows') + name = "pact_ffi-#{target}.#{windows ? 'zip' : 'tar.xz'}" + url = "#{FFI_BASE_URL}/pact_ffi-#{ffi_version}/#{name}" + + Dir.mktmpdir('pact_ffi') do |tmp| + archive = File.join(tmp, name) + fetch(url, archive) + fetch("#{url}.sha256", "#{archive}.sha256") + verify_sha256(archive) + + extracted = + if windows + system('unzip', '-qo', archive, native[:lib], '-d', tmp) + else + system('tar', '-xf', archive, '-C', tmp) end - end + abort "❌ Failed to extract #{archive}" unless extracted + + src = windows ? File.join(tmp, native[:lib]) : File.join(tmp, "pact_ffi-#{target}", native[:lib]) + abort "❌ #{native[:lib]} not found in #{name}" unless File.file?(src) + + FileUtils.mkdir_p(File.dirname(dest)) + FileUtils.cp(src, dest) end - File.delete(gz) +end + +# The .sha256 file holds ` *`. +def verify_sha256(archive) + expected = File.read("#{archive}.sha256").split.first + actual = Digest::SHA256.file(archive).hexdigest + abort "❌ Checksum mismatch for #{File.basename(archive)}: expected #{expected}, got #{actual}" unless + expected == actual end def download_ffi(all:) @@ -78,12 +106,11 @@ def download_ffi(all:) libs = all ? Pact::Ffi::NATIVE_LIBS : [Pact::Ffi.native_lib(current_dir)] libs.each do |native| - fetch_gz("#{FFI_BASE_URL}/libpact_ffi-#{ffi_version}/#{native[:asset]}", - File.join(ffi_dir, native[:dir], native[:lib])) + fetch_ffi_lib(native, File.join(ffi_dir, native[:dir], native[:lib])) end %w[pact.h pact-cpp.h].each do |header| - fetch("#{FFI_BASE_URL}/libpact_ffi-#{ffi_version}/#{header}", File.join(ffi_dir, header)) + fetch("#{FFI_BASE_URL}/pact_ffi-#{ffi_version}/#{header}", File.join(ffi_dir, header)) end File.write(File.join(ffi_dir, 'README.md'), diff --git a/script/lib/platforms.rb b/script/lib/platforms.rb index 7920977..7ebfdb0 100644 --- a/script/lib/platforms.rb +++ b/script/lib/platforms.rb @@ -2,17 +2,18 @@ module Pact module Ffi - # The native libpact_ffi libraries shipped with the gem. `asset` is the - # upstream pact-reference release asset (minus the version); once - # downloaded and gunzipped it lands at `ffi//`. + # The native libpact_ffi libraries shipped with the gem. `target` is the + # Rust target triple naming the upstream `pact_ffi-` archive + # (.zip for Windows, .tar.xz otherwise); `lib` is extracted from it to + # `ffi//`. NATIVE_LIBS = [ - { dir: 'linux-x64', lib: 'libpact_ffi.so', asset: 'libpact_ffi-linux-x86_64.so.gz' }, - { dir: 'linux-arm64', lib: 'libpact_ffi.so', asset: 'libpact_ffi-linux-aarch64.so.gz' }, - { dir: 'linux-x64-musl', lib: 'libpact_ffi.so', asset: 'libpact_ffi-linux-x86_64-musl.so.gz' }, - { dir: 'linux-arm64-musl', lib: 'libpact_ffi.so', asset: 'libpact_ffi-linux-aarch64-musl.so.gz' }, - { dir: 'macos-x64', lib: 'libpact_ffi.dylib', asset: 'libpact_ffi-macos-x86_64.dylib.gz' }, - { dir: 'macos-arm64', lib: 'libpact_ffi.dylib', asset: 'libpact_ffi-macos-aarch64.dylib.gz' }, - { dir: 'windows-x64', lib: 'pact_ffi.dll', asset: 'pact_ffi-windows-x86_64.dll.gz' } + { dir: 'linux-x64', lib: 'libpact_ffi.so', target: 'x86_64-unknown-linux-gnu' }, + { dir: 'linux-arm64', lib: 'libpact_ffi.so', target: 'aarch64-unknown-linux-gnu' }, + { dir: 'linux-x64-musl', lib: 'libpact_ffi.so', target: 'x86_64-unknown-linux-musl' }, + { dir: 'linux-arm64-musl', lib: 'libpact_ffi.so', target: 'aarch64-unknown-linux-musl' }, + { dir: 'macos-x64', lib: 'libpact_ffi.dylib', target: 'x86_64-apple-darwin' }, + { dir: 'macos-arm64', lib: 'libpact_ffi.dylib', target: 'aarch64-apple-darwin' }, + { dir: 'windows-x64', lib: 'pact_ffi.dll', target: 'x86_64-pc-windows-msvc' } ].freeze # Gem platforms built and published, each mapped to its native lib diff --git a/script/release.rb b/script/release.rb index 43917d4..400b14a 100644 --- a/script/release.rb +++ b/script/release.rb @@ -6,7 +6,7 @@ RELEASE_BRANCH = 'release/pact-ffi' VERSION_FILE = 'lib/pact/ffi/version.rb' UPSTREAM_REPO = 'pact-foundation/pact-reference' -UPSTREAM_TAG_PREFIX = 'libpact_ffi-v' +UPSTREAM_TAG_PREFIX = 'pact_ffi-v' def run!(*cmd) out, status = Open3.capture2e(*cmd)