Skip to content

Commit

Permalink
Feat: Prebuild pact_ffi pact.node -
Browse files Browse the repository at this point in the history
This change pre-builds the pact node bindings with prebuildify

Supported node versions are node LTS versions 16, 18, 20.

Supported Platforms + Arches are now

* Linux ARM64/X64
* MacOS ARM64/X64
* Windows X64

For the Pact FFI.

This change additional includes the Pact-Ruby-Standalone updated to v2.x

This brings is support for

* Linux/MacOS ARM64

for the pact cli and api

## Requirements

Users are no longer required to

* Install a node-gyp build chain
  - Not limited to
   - Python
   - MSVS for Windows

* Ensure `--ignore-scripts` is not set to true
  - This is because pact-js-core and the npm package pact-core will now come
    batteries included, which means the ffi and standalone come packaged in the
    npm package. This increases size, however all files have to be downloaded currently
    even if all are not used, so we might as well do this once for the user, rather than
    every user needing to, and possibly struggling due to various build system reasons related
    to node-gyp.
  • Loading branch information
YOU54F committed May 30, 2023
1 parent ea9f86f commit 6a38cf7
Show file tree
Hide file tree
Showing 28 changed files with 911 additions and 264 deletions.
102 changes: 39 additions & 63 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,49 @@
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
INSTALL_GH_CLI: &INSTALL_GH_CLI
install_gh_cli_script: |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& apt update \
&& apt install gh -y
linux_arm64_task:
RELEASE: &RELEASE
release_script: ./script/ci/release.sh
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
GITHUB_TOKEN: ENCRYPTED[636f316600928de28b5c36027cc39d9796bc0d0eca2a181368f255ad61540f13bb38cdce09b6428774f315bbf45e0ada]
GH_PRE_RELEASE_UPLOAD: true

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
PREBUILD_AND_TEST: &PREBUILD_AND_TEST
prebuild_script: NODE_VERSION=20 script/ci/prebuild.sh
<<: *RELEASE
test_20_script: NODE_VERSION=20 script/ci/build-and-test.sh && script/ci/clean.sh
test_18_script: NODE_VERSION=18 script/ci/build-and-test.sh && script/ci/clean.sh
test_16_script: NODE_VERSION=16 script/ci/build-and-test.sh && script/ci/clean.sh

mac_arm64_task:
macos_instance:
image: ghcr.io/cirruslabs/macos-ventura-base:latest
linux_arm_task:
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:
- brew install nvm
- source $(brew --prefix nvm)/nvm.sh
- nvm install $NODE_VERSION
- nvm use $NODE_VERSION
<< : *BUILD_TEST_TASK_TEMPLATE
SET_NVM: "true"
arm_container:
# container:
image: node:20-slim
cirrus_setup_script: chmod +x script/**/* && chmod +x script/**
setup_script: apt update --yes && apt install --yes curl python3 make build-essential g++ unzip zip libyaml-dev git
dry_run_check_script: npx --yes commit-and-tag-version --dry-run && git remote -v
pre_req_script: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.39.3/install.sh | bash
<<: *INSTALL_GH_CLI
<<: *PREBUILD_AND_TEST
artifacts:
path: prebuilds/*.tar.gz

mac_rosetta_task:
macos_arm_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
SET_NVM: "true"
cirrus_setup_script: chmod +x script/**/* && chmod +x script/**
dry_run_check_script: |
npx --yes commit-and-tag-version --dry-run && git remote -v
pre_req_script: brew install nvm
<<: *PREBUILD_AND_TEST
artifacts:
path: prebuilds/*.tar.gz
102 changes: 89 additions & 13 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,107 @@ on:
workflow_dispatch:

jobs:
build-and-test-osx:

create_pre_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: GH_CREATE_PRE_RELEASE=true ./script/ci/release.sh
if: github.ref == 'refs/heads/master' && env.ACT != 'true' && runner.os == 'Linux'
env:
GITHUB_TOKEN: ${{ github.token }}

prebuild:
needs: [ create_pre_release ]
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
node-version: [16,18,20]
node-version: [20]
os: [macos-latest,ubuntu-latest,windows-latest]

env:
NODE_VERSION: ${{ matrix.node-version }}

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}


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

- if: runner.os == 'Windows'
run: echo "ONLY_DOWNLOAD_PACT_FOR_WINDOWS=true" >> $GITHUB_ENV

- run: ./script/ci/prebuild.sh

- name: Upload prebuild for ${{ runner.os }}-${{ runner.arch }}
uses: actions/upload-artifact@v3
with:
path: prebuilds/*.tar.gz

- run: GH_PRE_RELEASE_UPLOAD=true ./script/ci/release.sh
if: github.ref == 'refs/heads/master' && env.ACT != 'true'
env:
NODE_VERSION: ${{ matrix.node-version }}
PACT_BROKER_FEATURES: publish_pacts_using_old_api
- run: script/ci/build-and-test.sh
if: runner.os == 'Windows'
GITHUB_TOKEN: ${{ github.token }}

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

env:
NODE_VERSION: ${{ matrix.node-version }}

steps:
- uses: actions/checkout@v3

- name: Download prebuilds
uses: actions/download-artifact@v3

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- if: runner.os == 'Windows'
run: echo "ONLY_DOWNLOAD_PACT_FOR_WINDOWS=true" >> $GITHUB_ENV
- run: ./script/ci/unpack-and-test.sh

release_dry_run:
runs-on: ubuntu-latest
needs: [ create_pre_release, prebuild ]
if: github.ref == 'refs/heads/master'

env:
NODE_VERSION: 20

steps:
- uses: actions/checkout@v3

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'

- name: "release - dry run: ${{ env.DRY_RUN }}"
id: publish
run: script/ci/release.sh
env:
NODE_VERSION: ${{ matrix.node-version }}
PACT_BROKER_FEATURES: publish_pacts_using_old_api
ONLY_DOWNLOAD_PACT_FOR_WINDOWS: true
GITHUB_TOKEN: ${{ github.token }}
DRY_RUN: true

- run: echo "New Release will be v${{ steps.publish.outputs.version }}"
30 changes: 13 additions & 17 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@ on:
jobs:
release:
runs-on: ubuntu-latest

env:
NODE_VERSION: 20

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v1
- uses: actions/checkout@v3

- name: Use Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v3
with:
node-version: 16
node-version: ${{ env.NODE_VERSION }}
registry-url: 'https://registry.npmjs.org'
- id: publish
run: script/ci/release.sh
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_AUTOMATION_TOKEN}}
- name: Create Release
id: create_release
uses: actions/create-release@v1
- name: "release"
id: publish
run: script/ci/release.sh
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: v${{ steps.publish.outputs.version }}
release_name: Release v${{ steps.publish.outputs.version }}
body: ${{steps.publish.outputs.notes}}
draft: false
prerelease: false
GITHUB_TOKEN: ${{ github.token }}
44 changes: 25 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ coverage
# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build


# Redis database dump
dump.rdb
Expand All @@ -44,35 +43,42 @@ src/**/**.d.ts
test/**/**.d.ts
bin/**/**.d.ts
**/*.d.ts
*.js
!test.js
src/**/**.js
test/**/**.js
bin/**/**.js
# *.js
# !test.js

*.js.map

# ts-node cache
ts-node-*

# pact standalone binaries
standalone/*
!standalone/__fixtures__/.keep
!standalone/*.ts
# standalone/*
standalone/darwin*
standalone/linux*
standalone/windows*
standalone/*.d.ts
ffi/*
!ffi/README.md
standalone/*.js
standalone/*.checksum
standalone/*.gz
standalone/README.md
# FFI native bindings
*.so
*.dll*
pact.h
pact-cpp.h
ffi/README.md
*.dylib
# Compiled binary addons (http://nodejs.org/api/addons.html)
build
# Precompiled binary addons
prebuilds

# Folders created during testing
log
reports
tmp
.tmp
test/__testoutput__

# jest config
!jest.config.js

# mocha config
!.mocharc.js
!ts-node.js

# jest mocks
!__mocks__
12 changes: 12 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,15 @@ test

# release scripts
script

## these arent needed in the final bundle
binding.gyp
native

.cirrus
.gitattributes
DEVELOPER.md
RELEASING.md
test.js
tsconfig.build.json
tsconfig.json
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.

## 13.19.0 (2023-05-27)


### Features

* Improved error messaging on path lookups ([b3c80be](https://github.com/pact-foundation/pact-js-core/commit/b3c80be68882cdbbc0801f01e3d0ea1493dccb5e))

## 13.18.2 (2023-05-27)


### Fixes and Improvements

* node-gyp-build for resolution only ([fceb1cf](https://github.com/pact-foundation/pact-js-core/commit/fceb1cf2cd091b0858f73b6184398df392aa061a))

## 13.18.1 (2023-05-27)


### Fixes and Improvements

* ensure ffi not npm ignored ([8092c22](https://github.com/pact-foundation/pact-js-core/commit/8092c22b3a9a8714e85908d16dd0fa531613cb7e))

## 13.18.0 (2023-05-27)


### Features

* Prebuild pact_ffi pact.node + publish in npm pkg - (win-32|linux|darwin)-x64 (linux|darwin)-arm64 ([2cd224d](https://github.com/pact-foundation/pact-js-core/commit/2cd224dbbb49b06ab98f4e1e05d38aa45b497d16))

## [13.13.8](https://github.com/pact-foundation/pact-js-core/compare/v13.13.7...v13.13.8) (2023-04-24)


Expand Down
Loading

0 comments on commit 6a38cf7

Please sign in to comment.