Skip to content

Commit

Permalink
feat: ARM64 Linux/MacOS Pact Ruby Standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed May 12, 2023
1 parent dac0e46 commit ea9f86f
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 147 deletions.
57 changes: 36 additions & 21 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
<< : *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
10 changes: 7 additions & 3 deletions script/lib/download-standalone.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
192 changes: 76 additions & 116 deletions src/pact-standalone.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});
}
Expand Down
29 changes: 22 additions & 7 deletions standalone/install.ts
Original file line number Diff line number Diff line change
@@ -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}`));
Expand All @@ -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',
Expand All @@ -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}`,
},
],
};
}
Expand Down

0 comments on commit ea9f86f

Please sign in to comment.