Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(cli): build nix binaries for both x64 and arm64 #2492

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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