diff --git a/package.json b/package.json index 2af6dc256..d1499ce43 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "release": "commit-and-tag-version", "test": "mocha", "coverage": "nyc npm run test", - "pretest": "bash scripts/install-plugins.sh", + "pretest": "./scripts/install-plugins", "docker:alpine:build": "docker build --build-arg NODE_VERSION=${NODE_VERSION:-current} -f Dockerfile.alpine -t pact-js:alpine .", "docker:debian:build": "docker build --build-arg NODE_VERSION=${NODE_VERSION:-current} -f Dockerfile.debian -t pact-js:debian .", "docker:alpine:run": "docker run -e LOG_LEVEL=${LOG_LEVEL:-info} -e GIT_REF=${GIT_REF:-test} -e GITHUB_ACTIONS=${GITHUB_ACTIONS:-false} -e SKIP_EXAMPLES=${SKIP_EXAMPLES:-''} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN -w /home -v $(pwd):/home --rm pact-js:alpine", diff --git a/scripts/install-plugins b/scripts/install-plugins new file mode 100755 index 000000000..1aeb04d7b --- /dev/null +++ b/scripts/install-plugins @@ -0,0 +1,94 @@ +#!/bin/sh +# +# Usage: +# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh | bash +# or +# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh -O- | bash + +# While most shells support `local`, it technically isn't POSIX. This will check +# for `local` and alias it to `typeset` if it doesn't exist. +# shellcheck disable=SC3043 +# If a shell does not support `local`, it will be aliased to +# `typeset`, so this check is not needed. +has_local() { + local _has_local +} +has_local 2>/dev/null || alias local=typeset + +set -o errexit # Exit on error +set -o nounset # Treat unset variables as an error + + +detect_osarch() { + case $(uname -sm) in + 'Linux x86_64') + os='linux' + arch='x86_64' + ext='' + ;; + 'Linux aarch64') + os='linux' + arch='aarch64' + ext='' + ;; + 'Darwin x86' | 'Darwin x86_64') + os='osx' + arch='x86_64' + ext='' + ;; + 'Darwin arm64') + os='osx' + arch='aarch64' + ext='' + ;; + CYGWIN* | MINGW32* | MSYS* | MINGW*) + os="windows" + arch='x86_64' + ext='.exe' + ;; + *) + echo "Sorry, you'll need to install the plugin CLI manually." + exit 1 + ;; + esac +} + +install_pact_plugin_cli() { + [ -f ~/.pact/bin/pact-plugin-cli ] && \ + echo "$(tput setaf 2)=> Plugin CLI already installed$(tput sgr0)" && \ + return + + local version="0.1.2" + detect_osarch + local url="https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz" + + URL=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz + echo "$(tput setaf 2)=> Installing plugins CLI version '${version}'$(tput sgr0)" + echo " - OS: ${os}" + echo " - Arch: ${arch}" + echo " - Version: ${version}" + echo " - URL: ${url}" + echo " - Downloading into: ~/.pact/bin/" + + mkdir -p ~/.pact/bin + curl -sSL $URL | gunzip -c >~/.pact/bin/pact-plugin-cli + chmod +x ~/.pact/bin/pact-plugin-cli +} + +install_matt_plugin() { + [ -d ~/.pact/plugins/matt-0.1.1 ] && \ + echo "$(tput setaf 2)=> MATT plugin already installed$(tput sgr0)" && \ + return + + local version="0.1.1" + + echo "$(tput setaf 2)=> Installing MATT plugin version '${version}'$(tput sgr0)" + ~/.pact/bin/pact-plugin-cli install +} + +main() { + install_pact_plugin_cli + install_matt_plugin +} + +main diff --git a/scripts/install-plugins.sh b/scripts/install-plugins.sh deleted file mode 100755 index 5e3027f2b..000000000 --- a/scripts/install-plugins.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -e -# -# Usage: -# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh | bash -# or -# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh -O- | bash -# -set -e # Needed for Windows bash, which doesn't read the shebang - -function detect_osarch() { - case $(uname -sm) in - 'Linux x86_64') - os='linux' - arch='x86_64' - ;; - 'Linux aarch64') - os='linux' - arch='aarch64' - ;; - 'Darwin x86' | 'Darwin x86_64') - os='osx' - arch='x86_64' - ;; - 'Darwin arm64') - os='osx' - arch='aarch64' - ;; - CYGWIN*|MINGW32*|MSYS*|MINGW*) - os="windows" - arch='x86_64' - ext='.exe' - ;; - *) - echo "Sorry, you'll need to install the plugin CLI manually." - exit 1 - ;; - esac -} - - -VERSION="0.1.2" -detect_osarch - -if [ ! -f ~/.pact/bin/pact-plugin-cli ]; then - echo "--- 🐿 Installing plugins CLI version '${VERSION}' (from tag ${TAG})" - mkdir -p ~/.pact/bin - DOWNLOAD_LOCATION=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${VERSION}/pact-plugin-cli-${os}-${arch}${ext}.gz - echo " Downloading from: ${DOWNLOAD_LOCATION}" - curl -L -o ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz "${DOWNLOAD_LOCATION}" - echo " Downloaded $(file ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz)" - gunzip -f ~/.pact/bin/pact-plugin-cli-${os}-${arch}.gz - mv ~/.pact/bin/pact-plugin-cli-${os}-${arch} ~/.pact/bin/pact-plugin-cli - chmod +x ~/.pact/bin/pact-plugin-cli -fi - -if [ ! -d ~/.pact/plugins/matt-0.1.1 ]; then - echo "--- 🐿 Installing MATT plugin" - ~/.pact/bin/pact-plugin-cli install https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.1.1 -fi \ No newline at end of file