From ea9f86f75a287425dfc1aa9b2124b9c892ec7672 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Fri, 12 May 2023 14:59:38 +0100 Subject: [PATCH] feat: ARM64 Linux/MacOS Pact Ruby Standalone --- .cirrus.yml | 57 +++++---- script/lib/download-standalone.sh | 10 +- src/pact-standalone.spec.ts | 192 ++++++++++++------------------ standalone/install.ts | 29 +++-- 4 files changed, 141 insertions(+), 147 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index a9a02372..843b7d0c 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -8,22 +8,17 @@ BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE - node --version - script/ci/build-and-test.sh -# These are probably expected to fail in the post install script -# until we are packing v2.0.0 of pact-ruby-standalone that supports -# arm64 linux - as per https://github.com/pact-foundation/pact-js-core/issues/416 -# Error: Error while locating pact binary: Cannot find binary for platform 'linux' with architecture 'arm64'. -# linux_arm64_task: -# skip: "changesInclude('.github/**')" -# env: -# matrix: -# - IMAGE: node:16-slim -# - IMAGE: node:18-slim -# - IMAGE: node:20-slim -# arm_container: -# image: $IMAGE -# install_script: -# - apt update --yes && apt install --yes curl python3 make build-essential g++ unzip zip -# << : *BUILD_TEST_TASK_TEMPLATE +linux_arm64_task: + env: + matrix: + - IMAGE: node:16-slim + - IMAGE: node:18-slim + - IMAGE: node:20-slim + arm_container: + image: $IMAGE + install_script: + - apt update --yes && apt install --yes curl python3 make build-essential g++ unzip zip + << : *BUILD_TEST_TASK_TEMPLATE linux_amd64_task: env: @@ -37,8 +32,7 @@ linux_amd64_task: - apt update --yes && apt install --yes curl python3 make build-essential g++ unzip zip << : *BUILD_TEST_TASK_TEMPLATE - -mac_task: +mac_arm64_task: macos_instance: image: ghcr.io/cirruslabs/macos-ventura-base:latest env: @@ -49,10 +43,31 @@ mac_task: - NODE_VERSION: 16 - NODE_VERSION: 18 - NODE_VERSION: 20 - install_script: # we need to install rosetta as v1.x of pact-ruby-standalone doesn't support arm64 - - softwareupdate --install-rosetta --agree-to-license + install_script: - brew install nvm - source $(brew --prefix nvm)/nvm.sh - nvm install $NODE_VERSION - nvm use $NODE_VERSION - << : *BUILD_TEST_TASK_TEMPLATE \ No newline at end of file + << : *BUILD_TEST_TASK_TEMPLATE + +mac_rosetta_task: + macos_instance: + image: ghcr.io/cirruslabs/macos-ventura-base:latest + env: + NVS_HOME: ${HOME}/.nvs + PATH: ${NVS_HOME}:${PATH} + matrix: + - NODE_VERSION: 16 + - NODE_VERSION: 18 + - NODE_VERSION: 20 + install nvs_script: | + git clone https://github.com/jasongin/nvs "$NVS_HOME" + . "$NVS_HOME/nvs.sh" install + install_rosetta_script: softwareupdate --install-rosetta --agree-to-license + install_x64_script: | + . "$NVS_HOME/nvs.sh" + nvs add $NODE_VERSION/x64 + nvs use $NODE_VERSION/x64 + file $(which node) | grep -e 'x64' + node --version + << : *BUILD_TEST_TASK_TEMPLATE diff --git a/script/lib/download-standalone.sh b/script/lib/download-standalone.sh index aa81df37..0c8ee251 100755 --- a/script/lib/download-standalone.sh +++ b/script/lib/download-standalone.sh @@ -1,4 +1,6 @@ #!/bin/bash -eu +set -e +set -u LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running . "${LIB_DIR}/robust-bash.sh" . "${LIB_DIR}/download-file.sh" @@ -7,7 +9,7 @@ require_binary curl require_binary unzip require_env_var STANDALONE_VERSION -BASEURL=https://github.com/pact-foundation/pact-ruby-standalone/releases/download +BASEURL=https://github.com/you54f/pact-ruby-standalone/releases/download STANDALONE_DIR="${LIB_DIR}/../../standalone" function download_standalone { @@ -45,11 +47,13 @@ if [[ $(find "${STANDALONE_DIR}" -name "*${STANDALONE_VERSION}") ]]; then exit 0 fi -download_standalone "pact-${STANDALONE_VERSION}-win32.zip" "win32-${STANDALONE_VERSION}.zip" +download_standalone "pact-${STANDALONE_VERSION}-windows-x86_64.zip" "windows-x64-${STANDALONE_VERSION}.zip" if [ -z "${ONLY_DOWNLOAD_PACT_FOR_WINDOWS:-}" ]; then - download_standalone "pact-${STANDALONE_VERSION}-osx.tar.gz" "darwin-${STANDALONE_VERSION}.tar.gz" + download_standalone "pact-${STANDALONE_VERSION}-osx-x86_64.tar.gz" "darwin-x64-${STANDALONE_VERSION}.tar.gz" + download_standalone "pact-${STANDALONE_VERSION}-osx-arm64.tar.gz" "darwin-arm64-${STANDALONE_VERSION}.tar.gz" download_standalone "pact-${STANDALONE_VERSION}-linux-x86_64.tar.gz" "linux-x64-${STANDALONE_VERSION}.tar.gz" + download_standalone "pact-${STANDALONE_VERSION}-linux-arm64.tar.gz" "linux-arm64-${STANDALONE_VERSION}.tar.gz" fi # Write readme in the ffi folder diff --git a/src/pact-standalone.spec.ts b/src/pact-standalone.spec.ts index 4d46437f..64ce6b97 100644 --- a/src/pact-standalone.spec.ts +++ b/src/pact-standalone.spec.ts @@ -38,122 +38,82 @@ describe('Pact Standalone', function forMocha() { describe('Check if OS specific files are there', () => { if (!process.env['ONLY_DOWNLOAD_PACT_FOR_WINDOWS']) { - describe('OSX', () => { - beforeEach(() => { - pact = standalone('darwin'); - }); - - it('broker relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.brokerPath))).to.be - .true; - }); - - it('broker full path', () => { - expect(fs.existsSync(pact.brokerFullPath)).to.be.true; - }); - - it('mock service relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.mockServicePath))).to - .be.true; - }); - - it('mock service full path', () => { - expect(fs.existsSync(pact.mockServiceFullPath)).to.be.true; - }); - - it('stub relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.stubPath))).to.be - .true; - }); - - it('stub full path', () => { - expect(fs.existsSync(pact.stubFullPath)).to.be.true; - }); - - it('provider verifier relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.verifierPath))).to.be - .true; - }); - - it('provider verifier full path', () => { - expect(fs.existsSync(pact.verifierFullPath)).to.be.true; - }); - - it('pact relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.pactPath))).to.be - .true; - }); - - it('pact full path', () => { - expect(fs.existsSync(pact.pactFullPath)).to.be.true; - }); - it('pactflow relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.pactflowPath))).to.be - .true; - }); - - it('pactflow full path', () => { - expect(fs.existsSync(pact.pactflowFullPath)).to.be.true; - }); - }); - - describe('Linux X64', () => { - beforeEach(() => { - pact = standalone('linux', 'x64'); - }); - - it('broker relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.brokerPath))).to.be - .true; - }); - - it('broker full path', () => { - expect(fs.existsSync(pact.brokerFullPath)).to.be.true; - }); - - it('mock service relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.mockServicePath))).to - .be.true; - }); - - it('mock service full path', () => { - expect(fs.existsSync(pact.mockServiceFullPath)).to.be.true; - }); - - it('stub relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.stubPath))).to.be - .true; - }); - - it('stub full path', () => { - expect(fs.existsSync(pact.stubFullPath)).to.be.true; - }); - - it('provider verifier relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.verifierPath))).to.be - .true; - }); - - it('provider verifier full path', () => { - expect(fs.existsSync(pact.verifierFullPath)).to.be.true; - }); - - it('pact relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.pactPath))).to.be - .true; - }); - - it('pact full path', () => { - expect(fs.existsSync(pact.pactFullPath)).to.be.true; - }); - - it('pactflow relative path', () => { - expect(fs.existsSync(path.resolve(basePath, pact.pactflowPath))).to.be - .true; - }); - - it('pactflow full path', () => { - expect(fs.existsSync(pact.pactflowFullPath)).to.be.true; + const binaries = [ + { + platform: 'darwin', + arch: 'x64', + }, + { + platform: 'darwin', + arch: 'arm64', + }, + { + platform: 'linux', + arch: 'x64', + }, + { + platform: 'linux', + arch: 'arm64', + }, + ]; + binaries.forEach((binary) => { + describe(`Testing binary for ${binary.arch} ${binary.platform}`, () => { + beforeEach(() => { + pact = standalone(binary.platform, binary.arch); + }); + + it('broker relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.brokerPath))).to.be + .true; + }); + + it('broker full path', () => { + expect(fs.existsSync(pact.brokerFullPath)).to.be.true; + }); + + it('mock service relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.mockServicePath))) + .to.be.true; + }); + + it('mock service full path', () => { + expect(fs.existsSync(pact.mockServiceFullPath)).to.be.true; + }); + + it('stub relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.stubPath))).to.be + .true; + }); + + it('stub full path', () => { + expect(fs.existsSync(pact.stubFullPath)).to.be.true; + }); + + it('provider verifier relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.verifierPath))).to + .be.true; + }); + + it('provider verifier full path', () => { + expect(fs.existsSync(pact.verifierFullPath)).to.be.true; + }); + + it('pact relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.pactPath))).to.be + .true; + }); + + it('pact full path', () => { + expect(fs.existsSync(pact.pactFullPath)).to.be.true; + }); + it('pactflow relative path', () => { + expect(fs.existsSync(path.resolve(basePath, pact.pactflowPath))).to + .be.true; + }); + + it('pactflow full path', () => { + expect(fs.existsSync(pact.pactflowFullPath)).to.be.true; + }); }); }); } diff --git a/standalone/install.ts b/standalone/install.ts index 0ff4d95f..5f13eb88 100644 --- a/standalone/install.ts +++ b/standalone/install.ts @@ -1,7 +1,7 @@ import chalk = require('chalk'); // Get latest version from https://github.com/pact-foundation/pact-ruby-standalone/releases -export const PACT_STANDALONE_VERSION = '1.92.0'; +export const PACT_STANDALONE_VERSION = '2.2.1'; function makeError(msg: string): Error { return new Error(chalk.red(`Error while locating pact binary: ${msg}`)); @@ -14,15 +14,23 @@ export function createConfig(): Config { binaries: [ { platform: 'win32', - binary: `pact-${PACT_STANDALONE_VERSION}-win32.zip`, - binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-win32.zip${CHECKSUM_SUFFIX}`, - folderName: `win32-${PACT_STANDALONE_VERSION}`, + binary: `pact-${PACT_STANDALONE_VERSION}-windows-x86_64.zip`, + binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-windows-x86_64.zip${CHECKSUM_SUFFIX}`, + folderName: `windows-x64-${PACT_STANDALONE_VERSION}`, }, { platform: 'darwin', - binary: `pact-${PACT_STANDALONE_VERSION}-osx.tar.gz`, - binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-osx.tar.gz${CHECKSUM_SUFFIX}`, - folderName: `darwin-${PACT_STANDALONE_VERSION}`, + arch: 'x64', + binary: `pact-${PACT_STANDALONE_VERSION}-osx-x86_64.tar.gz`, + binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-osx-x86_64.tar.gz${CHECKSUM_SUFFIX}`, + folderName: `darwin-x64-${PACT_STANDALONE_VERSION}`, + }, + { + platform: 'darwin', + arch: 'arm64', + binary: `pact-${PACT_STANDALONE_VERSION}-osx-arm64.tar.gz`, + binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-osx-arm64.tar.gz${CHECKSUM_SUFFIX}`, + folderName: `darwin-arm64-${PACT_STANDALONE_VERSION}`, }, { platform: 'linux', @@ -31,6 +39,13 @@ export function createConfig(): Config { binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-linux-x86_64.tar.gz${CHECKSUM_SUFFIX}`, folderName: `linux-x64-${PACT_STANDALONE_VERSION}`, }, + { + platform: 'linux', + arch: 'arm64', + binary: `pact-${PACT_STANDALONE_VERSION}-linux-arm64.tar.gz`, + binaryChecksum: `pact-${PACT_STANDALONE_VERSION}-linux-arm64.tar.gz${CHECKSUM_SUFFIX}`, + folderName: `linux-arm64-${PACT_STANDALONE_VERSION}`, + }, ], }; }