diff --git a/.circleci/config.yml b/.circleci/config.yml index b4fec0d1f..a1023cf1f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -219,7 +219,7 @@ jobs: - checkout - install-and-build - build-binary: - targets: linux,macos,alpine + targets: linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64 - persist_to_workspace: root: ./packages/cli/ paths: diff --git a/packages/cli/package.json b/packages/cli/package.json index ee9e17154..d57b263d2 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -26,7 +26,7 @@ "scripts": { "build.binary": "pkg . --output ./binaries/spectral", "build.windows": "pkg . --targets windows --out-path ./binaries", - "build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries", + "build.nix": "pkg . --targets linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64 --out-path ./binaries", "cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts", "cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts" }, diff --git a/scripts/install.sh b/scripts/install.sh index c60f8d5a2..d97accb47 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -7,26 +7,40 @@ install () { set -eu -UNAME=$(uname) -if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] ; then - echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases" +KERNEL=$(uname -s) +ARCH=$(uname -m) +if [ "$KERNEL" != "Linux" ] && [ "$KERNEL" != "Darwin" ] ; then + echo "Sorry, KERNEL/Architecture not supported: ${KERNEL}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases" exit 1 fi -if [ "$UNAME" = "Darwin" ] ; then - FILENAME="spectral-macos" -elif [ "$UNAME" = "Linux" ] ; then - FILENAME="spectral-linux" +if [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86_64" ] ; then + echo "Sorry, KERNEL/Architecture not supported: ${KERNEL}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases" + exit 1 +fi + +if [ "$ARCH" = "x86_64" ] ; then + ARCH="x64" +fi + +if [ "$ARCH" = "aarch64" ] ; then + ARCH="arm64" +fi + +OS="macos" +if [ "$KERNEL" = "Linux" ] ; then + OS="linux" if [ -f /etc/os-release ]; then # extract the value for KEY named "NAME" DISTRO=$(sed -n -e 's/^NAME="\?\([^"]*\)"\?$/\1/p' /etc/os-release) if [ "$DISTRO" = "Alpine Linux" ]; then echo "Installing on Alpine Linux." - FILENAME="spectral-alpine" + OS="alpine" fi fi fi +FILENAME="spectral-${OS}-${ARCH}" if [ "$VERSION" = "latest" ] ; then URL="https://github.com/stoplightio/spectral/releases/latest/download/${FILENAME}" else @@ -36,13 +50,13 @@ fi SRC="$(pwd)/${FILENAME}" DEST=/usr/local/bin/spectral -STATUS=$(curl -sL -w %{http_code} -o $SRC $URL) +STATUS=$(curl -sL -w %{http_code} -o "$SRC" "$URL") if [ $STATUS -ge 200 ] & [ $STATUS -le 308 ]; then - mv $SRC $DEST - chmod +x $DEST + mv "$SRC" "$DEST" + chmod +x "$DEST" echo "Spectral was installed to: ${DEST}" else - rm $SRC + rm "$SRC" echo "Error requesting. Download binary from ${URL}" exit 1 fi