Skip to content

Commit

Permalink
Merge pull request #326 from pact-foundation/ffi
Browse files Browse the repository at this point in the history
Pact PHP - Support for V3 / V4 + Plugins Via FFI
  • Loading branch information
tienvx authored Mar 26, 2024
2 parents 939ab8d + d3eea2a commit 5ca7280
Show file tree
Hide file tree
Showing 602 changed files with 23,623 additions and 6,189 deletions.
116 changes: 102 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: pact-php
name: Code Analysis & Test

on:
push:
push:
pull_request:
# Once on the first of the month at 06:00 UTC
schedule:
Expand All @@ -16,8 +16,6 @@ jobs:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '8.2' ]

steps:
- uses: actions/checkout@v4
Expand All @@ -26,7 +24,8 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: 8.1
coverage: none

- uses: ramsey/composer-install@v3
with:
Expand All @@ -38,18 +37,104 @@ jobs:
- name: Static Code Analysis
run: composer run static-code-analysis

test:
runs-on: ${{ matrix.operating-system }}
examples:
runs-on: ${{ matrix.os }}
needs:
- php-cs
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-latest, macos-latest, windows-latest ]
php: [ '8.0', '8.1', '8.2' ]
dependencies: [ 'lowest', 'locked' ]
include:
- os: ubuntu-latest
php: 8.1
- os: macos-12
php: 8.3
- os: macos-14
php: 8.2
- os: windows-latest
example: 'json'
php: 8.2
- os: windows-latest
example: 'binary'
php: 8.2
- os: windows-latest
example: 'multipart'
php: 8.2
- os: windows-latest
example: 'xml'
php: 8.2
- os: windows-latest
example: 'message'
php: 8.2
- os: windows-latest
example: 'matchers'
php: 8.2
- os: windows-latest
example: 'generators'
php: 8.2
- os: windows-latest
example: 'csv'
php: 8.2
- os: windows-latest
example: 'protobuf-sync-message'
php: 8.1
- os: windows-latest
example: 'protobuf-async-message'
php: 8.2
- os: windows-latest
example: 'stub-server'
php: 8.2
timeout-minutes: 5

steps:
- uses: actions/checkout@v4
name: Checkout repository

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
extensions: sockets, curl, zip, ffi ${{ (!matrix.example || matrix.example == 'protobuf-sync-message') && ', grpc' || '' }}
php-version: ${{ matrix.php }}
coverage: none
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Composer install
uses: ramsey/composer-install@v3
with:
dependency-versions: 'locked'

- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
if: ${{ !matrix.example || contains(matrix.example, 'protobuf') }}

- name: Generate Library
run: composer gen-lib
if: ${{ !matrix.example || contains(matrix.example, 'protobuf') }}

- name: Cache Pact Plugins
uses: actions/cache@v4
with:
path: ~/.pact/plugins
key: ${{ matrix.os }}-pact-plugins
if: ${{ !matrix.example || matrix.example == 'csv' || contains(matrix.example, 'protobuf') }}

- name: Run example(s)
run: composer test -- --exclude-testsuite unit ${{ matrix.example && format('--testsuite {0}-example', matrix.example) || '' }}
env:
PACT_DO_NOT_TRACK: true

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies
unit:
runs-on: ubuntu-latest
needs:
- php-cs
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
dependencies: [ 'lowest', 'locked' ]

steps:
- uses: actions/checkout@v4
Expand All @@ -58,13 +143,16 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
extensions: openssl, sockets, curl, zip
extensions: 'sockets, curl, zip, ffi'
php-version: ${{ matrix.php }}
coverage: pcov

- name: Composer install
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Composer test
run: composer test
- name: Test Unit
run: vendor/bin/phpunit --testsuite unit
env:
PACT_DO_NOT_TRACK: true
72 changes: 72 additions & 0 deletions .github/workflows/compatibility-suite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Compatibility Suite

on: [push, pull_request]

env:
PACT_DO_NOT_TRACK: true

jobs:
v1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- uses: ramsey/composer-install@v3

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V1 --colors
v2:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- uses: ramsey/composer-install@v3

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V2 --colors
v3:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- uses: ramsey/composer-install@v3

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V3 --name '/^((?!binary body \(negative|Message provider).)*$/' --colors
v4:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none

- uses: ramsey/composer-install@v3

- name: Run Behat
run: vendor/bin/behat compatibility-suite/pact-compatibility-suite/features/V4 --colors
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,4 @@ vendor/*
test_results
pact
example/output/*
.phpunit.cache/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "compatibility-suite/pact-compatibility-suite"]
path = compatibility-suite/pact-compatibility-suite
url = https://github.com/pact-foundation/pact-compatibility-suite.git
5 changes: 4 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->in(__DIR__ . '/example')
->in(__DIR__ . '/compatibility-suite/tests')
->exclude('library/src')
->name('*.php');

$config = new PhpCsFixer\Config();
$config->setRules(['@PSR12' => true,
$config->setRules([
'@PSR12' => true,
'strict_param' => false,
'array_syntax' => ['syntax' => 'short'],
])
Expand Down
57 changes: 57 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Pact-PHP

## Pre Reqs

- PHP 8.x or greater
- FFI and Sockets extensions enabled in your php.ini

## Steps

1. Run `composer install`
1. This will install php dependencies to `vendor`
2. This will install pact libraries to `bin`
2. Run `composer test`
1. This will run our unit tests
3. Run `composer lint`
1. This will run the phpcs-lint
4. Run `composer fix`
1. This will correct any auto fixable linter errors
5. Run `composer static-code-analysis`
1. Run static code analysis

## CI Locally

### MacOS ARM

#### Pre Reqs

- MacOS ARM
- Tart.run
- Cirrus-CLI

#### Steps

Run all versions of PHP

- `cirrus run --output github-actions macos_arm64 -e CIRRUS_CLI=true`

Run a specified version of PHP

- `cirrus run --output github-actions 'macos_arm64 VERSION:8.2' -e CIRRUS_CLI=true`

### Linux ARM

#### Pre Reqs

- Docker
- x86_64 or arm64/aarch64 host

#### Steps

Run all versions of PHP

- `cirrus run --output github-actions linux_arm64`

Run a specified version of PHP

- `cirrus run --output github-actions 'macos_arm64 VERSION:8.2'`
Loading

0 comments on commit 5ca7280

Please sign in to comment.