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
2 changes: 1 addition & 1 deletion .github/workflows/build-ffi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
rust: [ stable ]
env:
pact_do_not_track: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
env:
pact_do_not_track: true
steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/compatability-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -53,7 +53,7 @@ jobs:
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-13, macos-14 ]
operating-system: [ ubuntu-latest, windows-latest, macos-15, macos-15-intel ]
steps:
- uses: actions/checkout@v2
- uses: dtolnay/rust-toolchain@stable
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ jobs:
targets: x86_64-pc-windows-msvc
- operating-system: windows-2022
targets: aarch64-pc-windows-msvc
- operating-system: macos-13
- operating-system: macos-15-intel
targets: x86_64-apple-darwin
- operating-system: macos-14
- operating-system: macos-15
targets: aarch64-apple-darwin
fail-fast: false

Expand Down
10 changes: 5 additions & 5 deletions rust/pact_verifier_cli/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ FROM --platform=$BUILDPLATFORM rust:1-alpine3.21 AS builder
ARG BIN_ARCH=x86_64
ARG VERSION=1.1.1

RUN wget -O pact_verifier_cli.gz https://github.com/pact-foundation/pact-reference/releases/download/pact_verifier_cli-v${VERSION}/pact_verifier_cli-linux-${BIN_ARCH}.gz
RUN gunzip pact_verifier_cli.gz
RUN chmod +x pact_verifier_cli
RUN wget -O pact-verifier.gz https://github.com/pact-foundation/pact-reference/releases/download/pact_verifier_cli-v${VERSION}/pact-verifier-linux-${BIN_ARCH}.gz
RUN gunzip pact-verifier.gz
RUN chmod +x pact-verifier

# Now, we need to build our _real_ Docker container, copying in the executable.
FROM --platform=$BUILDPLATFORM alpine:3.21
RUN apk --no-cache add ca-certificates
COPY --from=builder \
/pact_verifier_cli \
/pact-verifier \
/usr/local/bin/

ENTRYPOINT ["/usr/local/bin/pact_verifier_cli"]
ENTRYPOINT ["/usr/local/bin/pact-verifier"]
8 changes: 4 additions & 4 deletions rust/pact_verifier_cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ back against the one defined in the pact file. All mismatches will then be repor

## Command line interface

The pact verifier is bundled as a single binary executable `pact_verifier_cli`. Running this without any options
The pact verifier is bundled as a single binary executable `pact-verifier`. Running this without any options
displays the standard help.

```console
$ pact_verifier_cli,ignore
$ pact-verifier,ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the ,ignore meant to be there?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is there to prevent trycmd from failing, as pact-verifier with no args, prints help but with an exit code of 2

Updating to be --help would probably be better, as it will allow to auto testing and updating with TRYCMD_OVERWRITE=true cargo test

Standalone pact verifier for provider pact verification

Usage: pact_verifier_cli [OPTIONS]
Usage: pact-verifier [OPTIONS]

Options:
--help Print help and exit
Expand Down Expand Up @@ -253,7 +253,7 @@ The `--last-failed` option will only execute interactions that have previously f
This will verify all the pacts for the `happy_provider` found in the pact broker (running on localhost) against the provider running on localhost port 5050. Only the pacts for the consumers `Consumer` and `Consumer2` will be verified.

```console,ignore
$ pact_verifier_cli -b http://localhost -n 'happy_provider' -p 5050 --filter-consumer Consumer --filter-consumer Consumer2
$ pact-verifier -b http://localhost -n 'happy_provider' -p 5050 --filter-consumer Consumer --filter-consumer Consumer2
21:59:28 [WARN] pact_matching::models: No metadata found in pact file "http://localhost/pacts/provider/happy_provider/consumer/Consumer/version/1.0.0", assuming V1.1 specification
21:59:28 [WARN] pact_matching::models: No metadata found in pact file "http://localhost/pacts/provider/happy_provider/consumer/Consumer2/version/1.0.0", assuming V1.1 specification

Expand Down
24 changes: 12 additions & 12 deletions rust/pact_verifier_cli/release-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ if [ "" = "$1" ]; then
fi

# AMD64
docker build . -t pactfoundation/pact-ref-verifier:$1-amd64 --platform linux/amd64 \
docker build . -t pactfoundation/pact-verifier:$1-amd64 --platform linux/amd64 \
--build-arg ARCH=amd64/ --build-arg BIN_ARCH=x86_64 --build-arg VERSION=$1
docker push pactfoundation/pact-ref-verifier:$1-amd64
docker push pactfoundation/pact-verifier:$1-amd64

# ARM64V8
docker build . -t pactfoundation/pact-ref-verifier:$1-arm64v8 --platform linux/arm64 \
docker build . -t pactfoundation/pact-verifier:$1-arm64v8 --platform linux/arm64 \
--build-arg ARCH=arm64v8/ --build-arg BIN_ARCH=aarch64 --build-arg VERSION=$1
docker push pactfoundation/pact-ref-verifier:$1-arm64v8
docker push pactfoundation/pact-verifier:$1-arm64v8

# Create Manifest
docker manifest create pactfoundation/pact-ref-verifier:$1 \
--amend pactfoundation/pact-ref-verifier:$1-amd64 \
--amend pactfoundation/pact-ref-verifier:$1-arm64v8
docker manifest push pactfoundation/pact-ref-verifier:$1
docker manifest create pactfoundation/pact-ref-verifier:latest \
--amend pactfoundation/pact-ref-verifier:$1-amd64 \
--amend pactfoundation/pact-ref-verifier:$1-arm64v8
docker manifest push pactfoundation/pact-ref-verifier:latest
docker manifest create pactfoundation/pact-verifier:$1 \
--amend pactfoundation/pact-verifier:$1-amd64 \
--amend pactfoundation/pact-verifier:$1-arm64v8
docker manifest push pactfoundation/pact-verifier:$1
docker manifest create pactfoundation/pact-verifier:latest \
--amend pactfoundation/pact-verifier:$1-amd64 \
--amend pactfoundation/pact-verifier:$1-arm64v8
docker manifest push pactfoundation/pact-verifier:latest
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/release-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
set -x

RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP_NAME=pact_verifier_cli
APP_NAME=pact-verifier

source "$RUST_DIR/scripts/gzip-and-sum.sh"
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"}
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/release-macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
set -x

RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP_NAME=pact_verifier_cli
APP_NAME=pact-verifier

source "$RUST_DIR/scripts/gzip-and-sum.sh"
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"}
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/release-win.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e
set -x

RUST_DIR="$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
APP_NAME=pact_verifier_cli
APP_NAME=pact-verifier

source "$RUST_DIR/scripts/gzip-and-sum.sh"
ARTIFACTS_DIR=${ARTIFACTS_DIR:-"$RUST_DIR/release_artifacts"}
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn transport_value(v: &str) -> Result<(String, u16, Option<String>), String> {
}
}

pub(crate) fn setup_app() -> Command {
pub fn setup_app() -> Command {
command!()
.disable_version_flag(true)
.disable_help_flag(true)
Expand Down
28 changes: 28 additions & 0 deletions rust/pact_verifier_cli/src/bin/pact-verifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::time::Duration;
use tokio::time::sleep;

use pact_verifier_cli::{handle_cli, init_windows};

fn main() {
init_windows();

let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("Could not start a Tokio runtime for running async tasks");

let result = runtime.block_on(async {
let result = handle_cli().await;

// Add a small delay to let asynchronous tasks to complete
sleep(Duration::from_millis(200)).await;

result
});

runtime.shutdown_timeout(Duration::from_millis(500));

if let Err(err) = result {
std::process::exit(err);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
//!
//! ## Command line interface
//!
//! The pact verifier is bundled as a single binary executable `pact_verifier_cli`. Running this without any options
//! The pact verifier is bundled as a single binary executable `pact-verifier`. Running this without any options
//! displays the standard help.
//!
//! ```console
//! $ pact_verifier_cli,ignore
//! $ pact-verifier,ignore
//! Standalone pact verifier for provider pact verification
//!
//! Usage: pact_verifier_cli [OPTIONS]
//! Usage: pact-verifier [OPTIONS]
//!
//! Options:
//! --help Print help and exit
Expand Down Expand Up @@ -249,7 +249,7 @@
//! This will verify all the pacts for the `happy_provider` found in the pact broker (running on localhost) against the provider running on localhost port 5050. Only the pacts for the consumers `Consumer` and `Consumer2` will be verified.
//!
//! ```console,ignore
//! $ pact_verifier_cli -b http://localhost -n 'happy_provider' -p 5050 --filter-consumer Consumer --filter-consumer Consumer2
//! $ pact-verifier -b http://localhost -n 'happy_provider' -p 5050 --filter-consumer Consumer --filter-consumer Consumer2
//! 21:59:28 [WARN] pact_matching::models: No metadata found in pact file "http://localhost/pacts/provider/happy_provider/consumer/Consumer/version/1.0.0", assuming V1.1 specification
//! 21:59:28 [WARN] pact_matching::models: No metadata found in pact file "http://localhost/pacts/provider/happy_provider/consumer/Consumer2/version/1.0.0", assuming V1.1 specification
//!
Expand Down Expand Up @@ -410,17 +410,16 @@
use std::env;
use std::fs::File;
use std::io::Read;
use std::process::ExitCode;
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use anyhow::anyhow;
use clap::ArgMatches;
use clap::error::ErrorKind;
use log::LevelFilter;
use maplit::hashmap;
use serde_json::Value;
use tokio::time::sleep;
use tracing::{debug, debug_span, error, Instrument, warn};
use tracing_log::LogTracer;
use tracing_subscriber::FmtSubscriber;
Expand All @@ -432,11 +431,11 @@ use pact_verifier::callback_executors::HttpRequestProviderStateExecutor;
use pact_verifier::metrics::VerificationMetrics;
use pact_verifier::selectors::{consumer_tags_to_selectors, json_to_selectors};

mod args;
pub mod args;
mod reports;

/// Handles the command line arguments from the running process
pub async fn handle_cli(version: &'static str) -> Result<(), i32> {
pub async fn handle_cli() -> Result<(), i32> {
let app = args::setup_app();
let matches = app
.arg_required_else_help(true)
Expand All @@ -451,7 +450,7 @@ pub async fn handle_cli(version: &'static str) -> Result<(), i32> {
Ok(())
},
ErrorKind::DisplayVersion => {
print_version(version);
print_version();
println!();
Ok(())
},
Expand All @@ -463,7 +462,17 @@ pub async fn handle_cli(version: &'static str) -> Result<(), i32> {
}
}

async fn handle_matches(matches: &ArgMatches) -> Result<(), i32> {
pub fn process_verifier_command(args: &ArgMatches) -> Result<(), ExitCode> {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let res = handle_matches(args).await;
match res {
Ok(()) => Ok(()),
Err(code) => Err(ExitCode::from(code as u8)),
}
})
}

pub async fn handle_matches(matches: &ArgMatches) -> Result<(), i32> {
let coloured_output = setup_output(matches);

let provider = configure_provider(matches);
Expand Down Expand Up @@ -683,8 +692,8 @@ pub(crate) fn configure_provider(matches: &ArgMatches) -> ProviderInfo {
}
}

fn print_version(version: &str) {
println!("pact verifier version : v{}", version);
pub fn print_version() {
println!("pact verifier version : v{}", clap::crate_version!());
println!("pact specification : v{}", PactSpecification::V4.version_str());
println!("models version : v{}", PACT_RUST_VERSION.unwrap_or_default());
}
Expand Down Expand Up @@ -809,39 +818,17 @@ fn interaction_filter(matches: &ArgMatches) -> FilterInfo {
}
}

fn main() {
init_windows();

let runtime = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.expect("Could not start a Tokio runtime for running async tasks");

let result = runtime.block_on(async {
let result = handle_cli(clap::crate_version!()).await;

// Add a small delay to let asynchronous tasks to complete
sleep(Duration::from_millis(200)).await;

result
});

runtime.shutdown_timeout(Duration::from_millis(500));

if let Err(err) = result {
std::process::exit(err);
}
}

#[cfg(windows)]
fn init_windows() {
pub fn init_windows() {
if let Err(err) = ansi_term::enable_ansi_support() {
warn!("Could not enable ANSI console support - {err}");
}
}

#[cfg(not(windows))]
fn init_windows() { }
pub fn init_windows() { }

#[cfg(test)]
mod tests {
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/tests/cmd/main.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Standalone pact verifier for provider pact verification

Usage: pact_verifier_cli [OPTIONS]
Usage: pact-verifier [OPTIONS]

Options:
--help Print help and exit
Expand Down
2 changes: 1 addition & 1 deletion rust/pact_verifier_cli/tests/cmd/main.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin.name = "pact_verifier_cli"
bin.name = "pact-verifier"
status.code = 2
Loading