Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>`) 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.

Expand Down
2 changes: 1 addition & 1 deletion lib/pact/ffi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Pact
module Version
VERSION = '0.5.8.1'
VERSION = '0.5.12.0'
end
end
53 changes: 40 additions & 13 deletions script/download_libs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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-<target>` 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-<target>/` 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 `<hex> *<archive name>`.
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:)
Expand 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'),
Expand Down
21 changes: 11 additions & 10 deletions script/lib/platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/<dir>/<lib>`.
# The native libpact_ffi libraries shipped with the gem. `target` is the
# Rust target triple naming the upstream `pact_ffi-<target>` archive
# (.zip for Windows, .tar.xz otherwise); `lib` is extracted from it to
# `ffi/<dir>/<lib>`.
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
Expand Down
2 changes: 1 addition & 1 deletion script/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading