Skip to content

Commit

Permalink
build(repo): fix arm64 builds (#2569)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Jan 8, 2024
1 parent ec4b3e3 commit 8d31c1a
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 132 deletions.
73 changes: 69 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
executors:
linux:
docker:
- image: cimg/base:2021.07
- image: cimg/base:2024.01

defaults:
default-branch: &default-branch develop
Expand All @@ -26,6 +26,7 @@ defaults:
- &node-active-lts "18.17"
- &node-current "20.5"
pkg-cache-path: &pkg-cache-path /tmp/pkg-node-binaries
ldid-version: &ldid-version 2.1.5-procursus7 # https://github.com/ProcursusTeam/ldid

commands:
compute-hashes:
Expand Down Expand Up @@ -64,12 +65,39 @@ commands:
parameters:
targets:
type: string
node-version:
type: string
default: *node-active-lts
bytecode:
type: boolean
default: true
steps:
- restore_cache:
name: Restore pkg cache
keys:
- &pkg-cache-key pkg-cache-<< parameters.targets >>-<< parameters.node-version >>
- run:
name: Create the Spectral Binary
environment:
PKG_CACHE_PATH: *pkg-cache-path
command: yarn workspace @stoplight/spectral-cli pkg . --public --targets << parameters.targets >> --output binaries/spectral
command: |
NODE_VERSION=$(echo "<< parameters.node-version >>" | awk -F "." '{ print $1 }')
TARGETS=$(echo "<< parameters.targets >>" | awk -v node_version="$NODE_VERSION" -F "," '{for (i=1;i<=NF;i++) printf "node" node_version "-" $i "," }' | sed "s/,$/\n/")
export ARCH=$(echo << parameters.targets >> | awk 'match($0, /-(arm64|x64)/){ print substr($0, RSTART+1, RLENGTH-1) }')
if [ "<< parameters.bytecode >>" = true ]
then
yarn workspace @stoplight/spectral-cli pkg . --public --public-packages "*" --targets $TARGETS --output binaries/spectral
else
yarn workspace @stoplight/spectral-cli pkg . --no-bytecode --public --public-packages "*" --targets $TARGETS --output binaries/spectral
fi
(cd packages/cli/binaries && ls . | sed -n -E 's/^(spectral)-(alpine|linux|macos)$/mv "\1-\2" "\1-\2"-$ARCH/p' | sh)
- save_cache:
name: Retain pkg cache
key: *pkg-cache-key
paths:
- *pkg-cache-path

install-and-build:
description: >-
Expand All @@ -78,6 +106,39 @@ commands:
- cached-dependencies
- build

install-ldid:
description: Install ldid
parameters:
version:
type: string
default: *ldid-version
steps:
- restore_cache:
name: Restore built ldid binary
keys:
- ldid-binary-<< parameters.version >>-{{ arch }}
- run:
name: Build ldid
working_directory: /tmp
command: |
sudo apt-get update -y
sudo apt-get -y install libplist-dev
if [ ! -d ldid ]
then
curl -L https://github.com/ProcursusTeam/ldid/archive/refs/tags/v<< parameters.version >>.tar.gz | tar -xz
mv ldid-<< parameters.version >> ldid
make -C ldid
fi
- save_cache:
name: Retain ldid binary
key: ldid-binary-<< parameters.version >>-{{ arch }}
paths:
- /tmp/ldid
- run:
name: Install ldid
working_directory: /tmp/ldid
command: make install

lint-code:
steps:
- run:
Expand Down Expand Up @@ -130,6 +191,7 @@ commands:
- test-harness-{{ checksum "/tmp/previous-commit-sha" }}-<< parameters.os >>-<< parameters.node-version >>
- build-binary:
targets: << parameters.os >>
node-version: << parameters.node-version >>
- run:
name: Run harness tests
command: yarn test.harness --maxWorkers=<< parameters.max-workers >>
Expand All @@ -138,7 +200,6 @@ commands:
key: test-harness-{{ checksum "/tmp/current-commit-sha" }}-<< parameters.os >>-<< parameters.node-version >>
paths:
- ./.cache/spectral-test-harness
- *pkg-cache-path
- ./test-harness/tests/
when: always

Expand Down Expand Up @@ -217,9 +278,13 @@ jobs:
- image: cimg/node:lts
steps:
- checkout
- install-ldid
- install-and-build
- build-binary:
targets: linux-x64,linux-arm64,macos-x64,macos-arm64,alpine-x64,alpine-arm64
targets: linux-x64,macos-x64,alpine-x64
- build-binary:
targets: macos-arm64,linux-arm64,alpine-arm64
bytecode: false
- 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 @@ -58,9 +58,9 @@
"@types/es-aggregate-error": "^1.0.2",
"@types/xml2js": "^0.4.9",
"@types/yargs": "^17.0.8",
"@yao-pkg/pkg": "^5.11.1",
"es-aggregate-error": "^1.0.7",
"nock": "^13.1.3",
"pkg": "^5.8.0",
"xml2js": "^0.5.0"
},
"pkg": {
Expand Down
Loading

0 comments on commit 8d31c1a

Please sign in to comment.