Skip to content

Commit

Permalink
feat!: Adopt gRPC (#41)
Browse files Browse the repository at this point in the history
PHP SDK utilized HTTP API due to some limitations related to code
generation. Now, using `buf` and some newly discovered tricks, it is
possible to generate php code from the gRPC protobuf definitions.

This PR re-designs the SDK to use `gRPC` with some changes breaking
backward compatibility.

### Supported [PHP versions](https://www.php.net/supported-versions.php)
- `8.1`
- `8.2`

resolves #38

---------

Signed-off-by: Oğuzhan Durgun <[email protected]>
Co-authored-by: Charith Ellawala <[email protected]>
  • Loading branch information
oguzhand95 and charithe authored Jun 19, 2023
1 parent 1a2a6eb commit 05a422b
Show file tree
Hide file tree
Showing 334 changed files with 47,957 additions and 3,749 deletions.
50 changes: 38 additions & 12 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ jobs:
lint:
name: Run linters
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [ '8.1', '8.2' ]
experimental: [ false ]

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
extensions: "grpc"

- name: Install dependencies
run: composer install --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress --no-suggest

- name: Lint
shell: bash
Expand All @@ -25,12 +38,24 @@ jobs:
static-analysis:
name: Run static analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version: [ '8.1', '8.2' ]
experimental: [ false ]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
extensions: "grpc"

- name: Install dependencies
run: composer install --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress --no-suggest

- name: Statically analyze code
shell: bash
Expand All @@ -50,24 +75,25 @@ jobs:
unit-tests:
name: Run unit tests
needs: [ "lint" ]
runs-on: ${{ matrix.operating-system }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-version:
- "7.4"
- "8.1"
operating-system:
- "ubuntu-latest"
dependencies:
- "lowest"
- "highest"
php-version: [ '8.1', '8.2' ]
experimental: [ false ]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug
extensions: "grpc"

- name: Install dependencies
run: composer install --prefer-dist --no-progress
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run docker-compose
run: docker-compose up -d
Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
SRC_DIR := "src"
TESTS_DIR := "tests"
PROTOS_DIR := "protos"

.PHONY: all
all: lint static-analysis validate-composer test
all: generate lint static-analysis validate-composer test

.PHONY: generate
generate: generate-proto-code

.PHONY: lint
lint:
vendor/bin/parallel-lint --exclude .git --exclude .github --exclude build --exclude vendor .
vendor/bin/parallel-lint ${SRC_DIR}/Sdk ${TESTS_DIR}/Sdk

.PHONY: static-analysis
static-analysis:
vendor/bin/psalm
vendor/bin/phpstan analyse src tests
vendor/bin/phpstan analyse ${SRC_DIR}/Sdk ${TESTS_DIR}/Sdk

.PHONY: validate-composer
validate-composer:
Expand All @@ -18,4 +25,13 @@ validate-composer:
test:
docker-compose up -d
vendor/bin/phpunit --no-coverage
docker-compose down
docker-compose down

.PHONY: generate-proto-code
generate-proto-code:
./fetch_protos.sh
sed -i.bak 's/syntax = "proto2"/syntax = "proto3"/' ${PROTOS_DIR}/validate/validate.proto
sed -i.bak 's/ \[default = true\];/;/' ${PROTOS_DIR}/validate/validate.proto
rm ${PROTOS_DIR}/validate/validate.proto.bak
rm -rf ${SRC_DIR}/Cerbos ${SRC_DIR}/GPBMetadata
buf generate ${PROTOS_DIR}
Loading

0 comments on commit 05a422b

Please sign in to comment.