Skip to content

Commit ed6b65c

Browse files
authored
build(cli): build nix binaries for both x64 and arm64 (stoplightio#2492)
1 parent 890d88c commit ed6b65c

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ jobs:
219219
- checkout
220220
- install-and-build
221221
- build-binary:
222-
targets: linux,macos,alpine
222+
targets: linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64
223223
- persist_to_workspace:
224224
root: ./packages/cli/
225225
paths:

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"scripts": {
2727
"build.binary": "pkg . --output ./binaries/spectral",
2828
"build.windows": "pkg . --targets windows --out-path ./binaries",
29-
"build.nix": "pkg . --targets linux,macos,alpine --out-path ./binaries",
29+
"build.nix": "pkg . --targets linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64 --out-path ./binaries",
3030
"cli": "node -r ts-node/register/transpile-only -r tsconfig-paths/register src/index.ts",
3131
"cli:debug": "node -r ts-node/register/transpile-only -r tsconfig-paths/register --inspect-brk src/index.ts"
3232
},

scripts/install.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,40 @@ install () {
77

88
set -eu
99

10-
UNAME=$(uname)
11-
if [ "$UNAME" != "Linux" ] && [ "$UNAME" != "Darwin" ] ; then
12-
echo "Sorry, OS/Architecture not supported: ${UNAME}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases"
10+
KERNEL=$(uname -s)
11+
ARCH=$(uname -m)
12+
if [ "$KERNEL" != "Linux" ] && [ "$KERNEL" != "Darwin" ] ; then
13+
echo "Sorry, KERNEL/Architecture not supported: ${KERNEL}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases"
1314
exit 1
1415
fi
1516

16-
if [ "$UNAME" = "Darwin" ] ; then
17-
FILENAME="spectral-macos"
18-
elif [ "$UNAME" = "Linux" ] ; then
19-
FILENAME="spectral-linux"
17+
if [ "$ARCH" != "aarch64" ] && [ "$ARCH" != "arm64" ] && [ "$ARCH" != "x86_64" ] ; then
18+
echo "Sorry, KERNEL/Architecture not supported: ${KERNEL}/${ARCH}. Download binary from https://github.com/stoplightio/spectral/releases"
19+
exit 1
20+
fi
21+
22+
if [ "$ARCH" = "x86_64" ] ; then
23+
ARCH="x64"
24+
fi
25+
26+
if [ "$ARCH" = "aarch64" ] ; then
27+
ARCH="arm64"
28+
fi
29+
30+
OS="macos"
31+
if [ "$KERNEL" = "Linux" ] ; then
32+
OS="linux"
2033
if [ -f /etc/os-release ]; then
2134
# extract the value for KEY named "NAME"
2235
DISTRO=$(sed -n -e 's/^NAME="\?\([^"]*\)"\?$/\1/p' /etc/os-release)
2336
if [ "$DISTRO" = "Alpine Linux" ]; then
2437
echo "Installing on Alpine Linux."
25-
FILENAME="spectral-alpine"
38+
OS="alpine"
2639
fi
2740
fi
2841
fi
2942

43+
FILENAME="spectral-${OS}-${ARCH}"
3044
if [ "$VERSION" = "latest" ] ; then
3145
URL="https://github.com/stoplightio/spectral/releases/latest/download/${FILENAME}"
3246
else
@@ -36,13 +50,13 @@ fi
3650
SRC="$(pwd)/${FILENAME}"
3751
DEST=/usr/local/bin/spectral
3852

39-
STATUS=$(curl -sL -w %{http_code} -o $SRC $URL)
53+
STATUS=$(curl -sL -w %{http_code} -o "$SRC" "$URL")
4054
if [ $STATUS -ge 200 ] & [ $STATUS -le 308 ]; then
41-
mv $SRC $DEST
42-
chmod +x $DEST
55+
mv "$SRC" "$DEST"
56+
chmod +x "$DEST"
4357
echo "Spectral was installed to: ${DEST}"
4458
else
45-
rm $SRC
59+
rm "$SRC"
4660
echo "Error requesting. Download binary from ${URL}"
4761
exit 1
4862
fi

0 commit comments

Comments
 (0)