Skip to content

Commit 772f3af

Browse files
committed
chore: make install-plugins POSIX
Instead of relying on `bash` (which may not be installed, such as in alpine images), use POSIX bash. Signed-off-by: JP-Ellis <josh@jpellis.me>
1 parent fc04239 commit 772f3af

File tree

3 files changed

+98
-60
lines changed

3 files changed

+98
-60
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"release": "commit-and-tag-version",
1818
"test": "mocha",
1919
"coverage": "nyc npm run test",
20-
"pretest": "bash scripts/install-plugins.sh",
20+
"pretest": "./scripts/install-plugins",
2121
"docker:alpine:build": "docker build --build-arg NODE_VERSION=${NODE_VERSION:-current} -f Dockerfile.alpine -t pact-js:alpine .",
2222
"docker:debian:build": "docker build --build-arg NODE_VERSION=${NODE_VERSION:-current} -f Dockerfile.debian -t pact-js:debian .",
2323
"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",

scripts/install-plugins

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/sh
2+
#
3+
# Usage:
4+
# $ curl -fsSL https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh | bash
5+
# or
6+
# $ wget -q https://raw.githubusercontent.com/pact-foundation/pact-plugins/master/install-cli.sh -O- | bash
7+
8+
# While most shells support `local`, it technically isn't POSIX. This will check
9+
# for `local` and alias it to `typeset` if it doesn't exist.
10+
# shellcheck disable=SC3043
11+
# If a shell does not support `local`, it will be aliased to
12+
# `typeset`, so this check is not needed.
13+
has_local() {
14+
local _has_local
15+
}
16+
has_local 2>/dev/null || alias local=typeset
17+
18+
set -o errexit # Exit on error
19+
set -o nounset # Treat unset variables as an error
20+
21+
# Colours
22+
WHITE_BOLD='\033[1;37m'
23+
RESET='\033[0m'
24+
25+
detect_osarch() {
26+
case $(uname -sm) in
27+
'Linux x86_64')
28+
os='linux'
29+
arch='x86_64'
30+
ext=''
31+
;;
32+
'Linux aarch64')
33+
os='linux'
34+
arch='aarch64'
35+
ext=''
36+
;;
37+
'Darwin x86' | 'Darwin x86_64')
38+
os='osx'
39+
arch='x86_64'
40+
ext=''
41+
;;
42+
'Darwin arm64')
43+
os='osx'
44+
arch='aarch64'
45+
ext=''
46+
;;
47+
CYGWIN* | MINGW32* | MSYS* | MINGW*)
48+
os="windows"
49+
arch='x86_64'
50+
ext='.exe'
51+
;;
52+
*)
53+
echo "Sorry, you'll need to install the plugin CLI manually."
54+
exit 1
55+
;;
56+
esac
57+
}
58+
59+
install_pact_plugin_cli() {
60+
[ -f ~/.pact/bin/pact-plugin-cli ] && \
61+
echo "${WHITE_BOLD}=> Plugin CLI already installed${RESET}" && \
62+
return
63+
64+
local version="0.1.2"
65+
detect_osarch
66+
local url="https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz"
67+
68+
URL=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz
69+
echo "${WHITE_BOLD}=> Installing plugins CLI version '${version}'${RESET}"
70+
echo " - OS: ${os}"
71+
echo " - Arch: ${arch}"
72+
echo " - Version: ${version}"
73+
echo " - URL: ${url}"
74+
echo " - Downloading into: ~/.pact/bin/"
75+
76+
mkdir -p ~/.pact/bin
77+
curl -sSL $URL | gunzip -c >~/.pact/bin/pact-plugin-cli
78+
chmod +x ~/.pact/bin/pact-plugin-cli
79+
}
80+
81+
install_matt_plugin() {
82+
[ -d ~/.pact/plugins/matt-0.1.1 ] && \
83+
echo -e "${WHITE_BOLD}=> MATT plugin already installed${RESET}" && \
84+
return
85+
86+
local version="0.1.1"
87+
88+
echo "${WHITE_BOLD}=> Installing MATT plugin version '${version}'${RESET}"
89+
~/.pact/bin/pact-plugin-cli install
90+
}
91+
92+
main() {
93+
install_pact_plugin_cli
94+
install_matt_plugin
95+
}
96+
97+
main

scripts/install-plugins.sh

-59
This file was deleted.

0 commit comments

Comments
 (0)