Skip to content

Commit

Permalink
Merge pull request #444 from YOU54F/master-pf
Browse files Browse the repository at this point in the history
CI: Test across Node 16/18/20 + arm64 MacOS test
  • Loading branch information
YOU54F authored May 12, 2023
2 parents 0783bd0 + 8554780 commit dac0e46
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 58 deletions.
58 changes: 58 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
env:
PACT_BROKER_FEATURES: publish_pacts_using_old_api

BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
arch_check_script:
- uname -am
test_script:
- 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_amd64_task:
env:
matrix:
- IMAGE: node:16-slim
- IMAGE: node:18-slim
- IMAGE: node:20-slim
container:
image: $IMAGE
install_script:
- apt update --yes && apt install --yes curl python3 make build-essential g++ unzip zip
<< : *BUILD_TEST_TASK_TEMPLATE


mac_task:
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
env:
PACT_BROKER_FEATURES: publish_pacts_using_old_api
NVS_HOME: ${HOME}/.nvs
PATH: ${NVS_HOME}:${PATH}
matrix:
- 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
- brew install nvm
- source $(brew --prefix nvm)/nvm.sh
- nvm install $NODE_VERSION
- nvm use $NODE_VERSION
<< : *BUILD_TEST_TASK_TEMPLATE
56 changes: 11 additions & 45 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,64 +8,30 @@ on:

jobs:
build-and-test-osx:
runs-on: macos-latest
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
node-version: [16.x]
node-version: [16,18,20]
os: [macos-latest,ubuntu-latest,windows-latest]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: script/ci/build-and-test.sh
if: runner.os != 'Windows'
env:
NODE_VERSION: ${{ matrix.node-version }}
PACT_BROKER_FEATURES: publish_pacts_using_old_api

build-and-test-ubuntu:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Set MSVS version
run: npm config set msvs_version 2017
- run: script/ci/build-and-test.sh
if: runner.os == 'Windows'
env:
NODE_VERSION: ${{ matrix.node-version }}
PACT_BROKER_FEATURES: publish_pacts_using_old_api

build-and-test-windows:
runs-on: windows-latest
strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Fix node-gyp
run: |-
npm install --global node-gyp@latest
npm prefix -g | % {npm config set node_gyp "$_\node_modules\node-gyp\bin\node-gyp.js"}
shell: pwsh
- run: bash script/ci/build-and-test.sh
shell: bash
env:
NODE_VERSION: ${{ matrix.node-version }}
# The windows build agent has trouble unpacking the tar for
# linux, so we only download windows binaries. This means
# we cannot release from Windows in CI.
ONLY_DOWNLOAD_PACT_FOR_WINDOWS: true
PACT_BROKER_FEATURES: publish_pacts_using_old_api
8 changes: 7 additions & 1 deletion DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Do this and you should be 👌👌👌:

```
bash script/download-libs.sh
npm ci
npm test
```
```


_notes_ - As a developer, you need to run `bash script/download-libs.sh` to download the FFI libraries prior to running `npm install` / `npm ci` as the libraries will be expected to be there, and you won't have any `node_modules` installed yet.

For end users, the `ffi` folder is populated, as part of the npm publishing step.
3 changes: 2 additions & 1 deletion script/ci/build-and-test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash -eu
set -eu # This needs to be here for windows bash, which doesn't read the #! line above
set -e # This needs to be here for windows bash, which doesn't read the #! line above
set -u

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"; pwd)" # Figure out where the script is running
. "$SCRIPT_DIR"/../lib/robust-bash.sh
Expand Down
2 changes: 1 addition & 1 deletion script/lib/download-ffi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if [[ $(find "${FFI_DIR}" -name "${FFI_VERSION}*") ]]; then
fi

warn "Cleaning ffi directory $FFI_DIR"
rm -rf "${FFI_DIR:?}/*"
rm -rf "${FFI_DIR:?}"
mkdir -p "$FFI_DIR/osxaarch64"
mkdir -p "$FFI_DIR/linuxaarch64"

Expand Down
20 changes: 15 additions & 5 deletions test/consumer.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const { expect } = chai;
const HOST = '127.0.0.1';

const isWin = process.platform === 'win32';
const isLinux = process.platform === 'linux';
const isDarwinArm64 = process.platform === 'darwin' && process.arch === 'arm64';
const isLinuxArm64 = process.platform === 'linux' && process.arch === 'arm64';
const isCirrusCi = process.env['CIRRUS_CI'] === 'true';
const usesOctetStream =
isLinuxArm64 || isWin || isDarwinArm64 || (isCirrusCi && isLinux);

describe('FFI integration test for the HTTP Consumer API', () => {
setLogLevel('trace');
Expand Down Expand Up @@ -73,7 +79,9 @@ describe('FFI integration test for the HTTP Consumer API', () => {
.request({
baseURL: `http://${HOST}:${port}`,
headers: {
'content-type': 'application/octet-stream',
'content-type': usesOctetStream
? 'application/octet-stream'
: 'application/gzip',
Accept: 'application/json',
'x-special-header': 'header',
},
Expand Down Expand Up @@ -168,9 +176,11 @@ describe('FFI integration test for the HTTP Consumer API', () => {

// See https://github.com/pact-foundation/pact-reference/issues/171 for why we have an OS switch here
// Windows: does not have magic mime matcher, uses content-type
// OSX on CI: does not magic mime matcher, uses content-type
// OSX: has magic mime matcher, sniffs content
// OSX arm64: does not magic mime matcher, uses content-type
// OSX x86_64: has magic mime matcher, sniffs content
// OSX x86_64 - CI GitHub Actions: has magic mime matcher, sniffs content
// Linux: has magic mime matcher, sniffs content
// Linux - CI Cirrus: does not have magic mime matcher, uses content-type
describe('with binary data', () => {
beforeEach(() => {
pact = makeConsumerPact(
Expand All @@ -188,7 +198,7 @@ describe('FFI integration test for the HTTP Consumer API', () => {
interaction.withQuery('someParam', 0, 'someValue');
interaction.withRequestBinaryBody(
bytes,
isWin ? 'application/octet-stream' : 'application/gzip'
usesOctetStream ? 'application/octet-stream' : 'application/gzip'
);
interaction.withResponseBody(
JSON.stringify({
Expand All @@ -211,7 +221,7 @@ describe('FFI integration test for the HTTP Consumer API', () => {
.request({
baseURL: `http://${HOST}:${port}`,
headers: {
'content-type': isWin
'content-type': usesOctetStream
? 'application/octet-stream'
: 'application/gzip',
Accept: 'application/json',
Expand Down
12 changes: 7 additions & 5 deletions test/message.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ chai.use(chaiAsPromised);
const { expect } = chai;

const isWin = process.platform === 'win32';
const isOSX = process.platform === 'darwin';
const isCI = process.env['CI'] === 'true';
const isLinux = process.platform === 'linux';
const isDarwinArm64 = process.platform === 'darwin' && process.arch === 'arm64';
const isLinuxArm64 = process.platform === 'linux' && process.arch === 'arm64';
const isCirrusCi = process.env['CIRRUS_CI'] === 'true';
const usesOctetStream =
isLinuxArm64 || isWin || isDarwinArm64 || (isCirrusCi && isLinux);

const getFeature = async (address: string, protoFile: string) => {
const def = await load(protoFile);
Expand Down Expand Up @@ -100,9 +104,7 @@ describe('FFI integration test for the Message Consumer API', () => {
message.givenWithParam('some state 2', 'state2 key', 'state2 val');
message.withBinaryContents(
bytes,
isWin || (isOSX && isCI)
? 'application/octet-stream'
: 'application/gzip'
usesOctetStream ? 'application/octet-stream' : 'application/gzip'
);
message.withMetadata('meta-key', 'meta-val');

Expand Down

0 comments on commit dac0e46

Please sign in to comment.