Skip to content

Commit

Permalink
feat: add pactflow command (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque authored Jun 9, 2022
1 parent fd5d746 commit 2ea87bd
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packaging/README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ To connect to a Pact Broker that uses custom SSL cerificates, set the environmen
```

<a name="pact"></a>

<a name="pactflow-client"></a>
### pactflow client

#### publish-provider-contract

```
<%= pactflow_publish_provider_contract_usage %>
```

### pact

<a name="pact-docs"></a>
Expand Down
1 change: 1 addition & 0 deletions packaging/generate_readme_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 20 additions & 0 deletions packaging/pactflow.bat
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions packaging/pactflow.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions packaging/pactflow.sh
Original file line number Diff line number Diff line change
@@ -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" "$@"

0 comments on commit 2ea87bd

Please sign in to comment.