Skip to content

Commit

Permalink
build(cli): build nix binaries for both x64 and arm64 (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
klaude authored Jul 24, 2023
1 parent 890d88c commit ed6b65c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
38 changes: 26 additions & 12 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ed6b65c

Please sign in to comment.