From 2ea87bd4e3aa93044166ea296bfdfe5c28e2a86d Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 9 Jun 2022 14:08:24 +1000 Subject: [PATCH] feat: add pactflow command (#78) --- packaging/README.md.template | 10 ++++++++++ packaging/generate_readme_contents.rb | 1 + packaging/pactflow.bat | 20 +++++++++++++++++++ packaging/pactflow.rb | 28 +++++++++++++++++++++++++++ packaging/pactflow.sh | 28 +++++++++++++++++++++++++++ 5 files changed, 87 insertions(+) create mode 100644 packaging/pactflow.bat create mode 100644 packaging/pactflow.rb create mode 100755 packaging/pactflow.sh diff --git a/packaging/README.md.template b/packaging/README.md.template index 6b73908..2c0c45a 100644 --- a/packaging/README.md.template +++ b/packaging/README.md.template @@ -61,6 +61,16 @@ To connect to a Pact Broker that uses custom SSL cerificates, set the environmen ``` + + +### pactflow client + +#### publish-provider-contract + +``` +<%= pactflow_publish_provider_contract_usage %> +``` + ### pact diff --git a/packaging/generate_readme_contents.rb b/packaging/generate_readme_contents.rb index a36fb36..48e40d6 100644 --- a/packaging/generate_readme_contents.rb +++ b/packaging/generate_readme_contents.rb @@ -13,4 +13,5 @@ pact_broker_can_i_deploy_usage = `bundle exec pact-broker help can-i-deploy` pact_docs_usage = `bundle exec pact help docs` pact_message_usage = `bundle exec pact-message help` +pactflow_publish_provider_contract_usage = `bundle exec pactflow publish-provider-contract help` puts ERB.new(ARGF.read).result(binding) diff --git a/packaging/pactflow.bat b/packaging/pactflow.bat new file mode 100644 index 0000000..f872097 --- /dev/null +++ b/packaging/pactflow.bat @@ -0,0 +1,20 @@ +@echo off + +SET RUNNING_PATH=%~dp0 +CALL :RESOLVE "%RUNNING_PATH%\.." ROOT_PATH + +:: Tell Bundler where the Gemfile and gems are. +set "BUNDLE_GEMFILE=%ROOT_PATH%\lib\vendor\Gemfile" +set BUNDLE_IGNORE_CONFIG= +set RUBYGEMS_GEMDEPS= +set BUNDLE_APP_CONFIG= +set BUNDLE_FROZEN=1 + +:: Run the actual app using the bundled Ruby interpreter, with Bundler activated. +@"%ROOT_PATH%\lib\ruby\bin\ruby.bat" -E UTF-8 -rbundler/setup -I "%ROOT_PATH%\lib\app\lib" "%ROOT_PATH%\lib\app\pactflow.rb" %* + +GOTO :EOF + +:RESOLVE +SET %2=%~f1 +GOTO :EOF diff --git a/packaging/pactflow.rb b/packaging/pactflow.rb new file mode 100644 index 0000000..a2d2a9e --- /dev/null +++ b/packaging/pactflow.rb @@ -0,0 +1,28 @@ +require 'pactflow/client/cli/pactflow' + +class Thor + module Base + module ClassMethods + + def basename + # chomps the trailing .rb so it doesn't show in the help text + File.basename($PROGRAM_NAME).split(" ").first.chomp(".rb") + end + end + end +end + +# Travelling Ruby sets its own CA cert bundle in lib/ruby/bin/ruby_environment +# and creates backup environment variables for the original SSL_CERT values. +# Restore the original values here *if they are present* so that we can connect to +# a broker with a custom SSL certificate. + +if ENV['ORIG_SSL_CERT_DIR'] && ENV['ORIG_SSL_CERT_DIR'] != '' + ENV['SSL_CERT_DIR'] = ENV['ORIG_SSL_CERT_DIR'] +end + +if ENV['ORIG_SSL_CERT_FILE'] && ENV['ORIG_SSL_CERT_FILE'] != '' + ENV['SSL_CERT_FILE'] = ENV['ORIG_SSL_CERT_FILE'] +end + +Pactflow::Client::CLI::Pactflow.start diff --git a/packaging/pactflow.sh b/packaging/pactflow.sh new file mode 100755 index 0000000..e62cf17 --- /dev/null +++ b/packaging/pactflow.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e + +SOURCE="$0" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + TARGET="$(readlink "$SOURCE")" + START="$( echo "$TARGET" | cut -c 1 )" + if [ "$START" = "/" ]; then + SOURCE="$TARGET" + else + DIR="$( dirname "$SOURCE" )" + SOURCE="$DIR/$TARGET" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + fi +done +RDIR="$( dirname "$SOURCE" )" +DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + +# Figure out where this script is located. +LIBDIR="`cd \"$DIR\" && cd ../lib && pwd`" + +# Tell Bundler where the Gemfile and gems are. +export BUNDLE_GEMFILE="$LIBDIR/vendor/Gemfile" +unset BUNDLE_IGNORE_CONFIG +unset RUBYGEMS_GEMDEPS +export BUNDLE_FROZEN=1 + +# Run the actual app using the bundled Ruby interpreter, with Bundler activated. +exec "$LIBDIR/ruby/bin/ruby" -E UTF-8 -rreadline -rbundler/setup -I "$LIBDIR/app/lib" "$LIBDIR/app/pactflow.rb" "$@"