Skip to content

Commit 6973eb5

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 6973eb5

File tree

3 files changed

+97
-60
lines changed

3 files changed

+97
-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

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
22+
detect_osarch() {
23+
case $(uname -sm) in
24+
'Linux x86_64')
25+
os='linux'
26+
arch='x86_64'
27+
ext=''
28+
;;
29+
'Linux aarch64')
30+
os='linux'
31+
arch='aarch64'
32+
ext=''
33+
;;
34+
'Darwin x86' | 'Darwin x86_64')
35+
os='osx'
36+
arch='x86_64'
37+
ext=''
38+
;;
39+
'Darwin arm64')
40+
os='osx'
41+
arch='aarch64'
42+
ext=''
43+
;;
44+
CYGWIN* | MINGW32* | MSYS* | MINGW*)
45+
os="windows"
46+
arch='x86_64'
47+
ext='.exe'
48+
;;
49+
*)
50+
echo "Sorry, you'll need to install the plugin CLI manually."
51+
exit 1
52+
;;
53+
esac
54+
}
55+
GREEN='\033[0;32m'
56+
RESET='\033[0m'
57+
58+
install_pact_plugin_cli() {
59+
[ -f ~/.pact/bin/pact-plugin-cli ] && \
60+
echo "${GREEN}=> Plugin CLI already installed${RESET}" && \
61+
return
62+
63+
local version="0.1.2"
64+
detect_osarch
65+
local url="https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz"
66+
67+
URL=https://github.com/pact-foundation/pact-plugins/releases/download/pact-plugin-cli-v${version}/pact-plugin-cli-${os}-${arch}${ext}.gz
68+
echo "${GREEN}=> Installing plugins CLI version '${version}'${RESET}"
69+
echo " - OS: ${os}"
70+
echo " - Arch: ${arch}"
71+
echo " - Version: ${version}"
72+
echo " - URL: ${url}"
73+
echo " - Downloading into: ~/.pact/bin/"
74+
75+
mkdir -p ~/.pact/bin
76+
curl -sSL $URL | gunzip -c >~/.pact/bin/pact-plugin-cli
77+
chmod +x ~/.pact/bin/pact-plugin-cli
78+
}
79+
80+
install_matt_plugin() {
81+
[ -d ~/.pact/plugins/matt-0.1.1 ] && \
82+
echo -e "${GREEN}=> MATT plugin already installed${RESET}" && \
83+
return
84+
85+
local version="0.1.1"
86+
87+
echo "${GREEN}=> Installing MATT plugin version '${version}'${RESET}"
88+
~/.pact/bin/pact-plugin-cli install
89+
}
90+
91+
main() {
92+
install_pact_plugin_cli
93+
install_matt_plugin
94+
}
95+
96+
main

scripts/install-plugins.sh

-59
This file was deleted.

0 commit comments

Comments
 (0)