From 9b6103d1ce1630e016f51472cf671e663e9e774e Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Wed, 25 Dec 2024 06:50:09 +0100 Subject: [PATCH] [PHP] Drop PHP 7 & upgrade dependency versions & GH Actions --- .github/workflows/checks.yml | 128 +++++++++++++++++++++++++++++++++ Dockerfile | 24 ++++--- Makefile | 15 ++-- README.md | 2 +- bin/php | 2 +- build/.gitkeep | 0 composer.json | 4 +- phpunit.xml.dist | 15 ++-- test/AllTests.php | 57 --------------- test/InterOpTest.php | 79 -------------------- test/generate_interop_data.php | 48 ------------- 11 files changed, 162 insertions(+), 212 deletions(-) create mode 100644 .github/workflows/checks.yml delete mode 100644 build/.gitkeep delete mode 100644 test/AllTests.php delete mode 100644 test/InterOpTest.php delete mode 100644 test/generate_interop_data.php diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 0000000..0702ca2 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,128 @@ +name: avro-php +on: + pull_request: + push: + branches: + - master +jobs: + build-source: + runs-on: ubuntu-22.04 + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Install phars + run: | + make install-phars + - + name: Upload source directory + uses: actions/upload-artifact@v4 + with: + name: source + include-hidden-files: true + path: . + php-xdebug-docker: + needs: + - build-source + strategy: + matrix: + php: + - + version: '8.1' + xdebug: '3.4.0' + - + version: '8.2' + xdebug: '3.4.0' + - + version: '8.3' + xdebug: '3.4.0' + - + version: '8.4' + xdebug: '3.4.0' + runs-on: ubuntu-22.04 + steps: + - + name: Download sources + uses: actions/download-artifact@v4 + with: + name: source + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + load: true + tags: avro-php:${{ matrix.php.version }} + build-args: | + PHP_VERSION=${{ matrix.php.version }} + XDEBUG_VERSION=${{ matrix.php.xdebug }} + - + name: Inspect docker image + run: | + docker image inspect avro-php:${{ matrix.php.version }} + - + name: Save docker image + run: | + docker save avro-php:${{ matrix.php.version }} -o php-avro-serde-${{ matrix.php.version }}.tgz + - + name: Upload docker image + uses: actions/upload-artifact@v4 + with: + name: php-avro-serde-${{ matrix.php.version }} + path: php-avro-serde-${{ matrix.php.version }}.tgz + ci-checks: + runs-on: ubuntu-22.04 + needs: + - php-xdebug-docker + strategy: + matrix: + php: + - + version: '8.1' + composer: --prefer-stable + - + version: '8.2' + composer: --prefer-stable + - + version: '8.3' + composer: --prefer-stable + - + version: '8.4' + composer: --prefer-stable + steps: + - + name: Download sources + uses: actions/download-artifact@v4 + with: + name: source + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Download docker image + uses: actions/download-artifact@v4 + with: + name: php-avro-serde-${{ matrix.php.version }} + - + name: Load docker image + run: | + docker load -i php-avro-serde-${{ matrix.php.version }}.tgz + - + name: Install vendors + run: | + docker run -i --rm --net=host --sig-proxy=true --pid=host \ + -v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" avro-php:${{ matrix.php.version }} \ + composer update --no-interaction --no-scripts --no-ansi ${{ matrix.php.composer }} + - + name: Run PHPUnit + run: | + mkdir -p build/tmp build/share/test/schemas build/build/interop/data + chmod -R a+w build + docker run -i --rm --net=host --sig-proxy=true --pid=host \ + -v "${GITHUB_WORKSPACE}":"${GITHUB_WORKSPACE}" -w "${GITHUB_WORKSPACE}" avro-php:${{ matrix.php.version }} \ + vendor/bin/phpunit --exclude-group integration diff --git a/Dockerfile b/Dockerfile index 4cbcf8d..793addf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,22 @@ -ARG PHP_VERSION=8.2 +ARG PHP_VERSION=8.1 FROM php:${PHP_VERSION}-cli-alpine -ARG XDEBUG_VERSION=3.2.0 -RUN apk add --update linux-headers \ - && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \ +ARG XDEBUG_VERSION=3.4.0 + +COPY --from=composer /usr/bin/composer /usr/bin/composer +RUN composer --version + +RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \ && apk add --no-cache --virtual .runtime-deps git libzip-dev gmp-dev \ + && docker-php-source extract \ + && docker-php-ext-configure zip \ && docker-php-ext-install zip gmp \ - && pecl install xdebug-$XDEBUG_VERSION \ + && apk add --update linux-headers \ + && mkdir -p /usr/src/php/ext/xdebug \ + && curl -fsSL https://github.com/xdebug/xdebug/archive/$XDEBUG_VERSION.tar.gz | tar xvz -C /usr/src/php/ext/xdebug --strip 1 \ + && docker-php-ext-install xdebug \ && docker-php-ext-enable xdebug \ - && echo "xdebug.max_nesting_level=15000" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ - && echo "xdebug.client_host=localhost" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ - && echo "xdebug.idekey=PHPSTORM" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ - && echo "xdebug.remote_handler=dbgp" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ - && echo "xdebug.mode=develop" >> "$PHP_INI_DIR/conf.d/docker-php-ext-xdebug.ini" \ && git clone --recursive --depth=1 https://github.com/kjdev/php-ext-snappy.git \ && cd php-ext-snappy \ && phpize \ @@ -21,4 +24,5 @@ RUN apk add --update linux-headers \ && make \ && make install \ && docker-php-ext-enable snappy \ + && docker-php-source delete \ && apk del .build-deps diff --git a/Makefile b/Makefile index 2960abb..b4f8862 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -# no buildin rules and variables +# no builtin rules and variables MAKEFLAGS =+ -rR --warn-undefined-variables .PHONY: composer-install composer-update examples docker run COMPOSER ?= bin/composer.phar -COMPOSER_VERSION ?= 2.5.4 +COMPOSER_VERSION ?= 2.8.4 PHP ?= bin/php -PHP_VERSION ?= 8.2 -XDEBUG_VERSION ?= 3.2.0 +PHP_VERSION ?= 8.3 +XDEBUG_VERSION ?= 3.4.0 export @@ -28,7 +28,12 @@ composer-update: phpunit: @mkdir -p build/tmp build/share/test/schemas build/build/interop/data @chmod -R a+w build - PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit --coverage-text test/AllTests.php + PHP_VERSION=$(PHP_VERSION) $(PHP) vendor/bin/phpunit + +coverage: + @mkdir -p build/tmp build/share/test/schemas build/build/interop/data + @chmod -R a+w build + PHP_VERSION=$(PHP_VERSION) $(PHP) -d xdebug.mode=coverage vendor/bin/phpunit --coverage-text run: PHP_VERSION=$(PHP_VERSION) $(PHP) $(ARGS) diff --git a/README.md b/README.md index d3c1613..bd73054 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A library for using [Avro](http://avro.apache.org/) with PHP. Requirements ============ - * PHP >= 7.1 + * PHP >= 8.1 * On 32-bit platforms, the [GMP PHP extension](http://php.net/gmp) * For testing, [PHPUnit](http://www.phpunit.de/) * For Deflate codec, [Zlib](https://www.php.net/zlib) diff --git a/bin/php b/bin/php index 2c81b97..449ad2c 100755 --- a/bin/php +++ b/bin/php @@ -7,7 +7,7 @@ command -v docker >/dev/null 2>&1 || { echo "docker is required to run this bina USER=${USER:-$( id -un )} GROUP=${GROUP:-$( id -gn )} COMPOSER_HOME=${COMPOSER_HOME:-${HOME}/.composer} -PHP_VERSION=${PHP_VERSION:-7.1} +PHP_VERSION=${PHP_VERSION:-8.1} DOCKER_OPTS=${DOCKER_OPTS:-'-it'} exec docker run ${DOCKER_OPTS} --rm \ diff --git a/build/.gitkeep b/build/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/composer.json b/composer.json index 6e2f5be..4e8eedc 100644 --- a/composer.json +++ b/composer.json @@ -3,10 +3,10 @@ "description": "Avro schema encoder/decoder. Fork of rg/avro-php", "license": "Apache-2.0", "require": { - "php": ">=7.4|>=8.0" + "php": "^8.1" }, "require-dev": { - "phpunit/phpunit": "~8.5" + "phpunit/phpunit": "^10.5" }, "suggest": { "ext-gmp": "Large integer support for 32-bit platforms.", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index fbe988e..3a205c3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -2,20 +2,17 @@ - - - - lib/ - - - + + + lib + + test - diff --git a/test/AllTests.php b/test/AllTests.php deleted file mode 100644 index cdea207..0000000 --- a/test/AllTests.php +++ /dev/null @@ -1,57 +0,0 @@ -addTestSuite('DataFileTest'); - $suite->addTestSuite('SchemaTest'); - $suite->addTestSuite('NameTest'); - $suite->addTestSuite('StringIOTest'); - $suite->addTestSuite('IODatumReaderTest'); - $suite->addTestSuite('LongEncodingTest'); - $suite->addTestSuite('FloatIntEncodingTest'); - $suite->addTestSuite('DatumIOTest'); - $suite->addTestSuite('ProtocolFileTest'); - $suite->addTestSuite('FileIOTest'); - return $suite; - } -} diff --git a/test/InterOpTest.php b/test/InterOpTest.php deleted file mode 100644 index 6b9954f..0000000 --- a/test/InterOpTest.php +++ /dev/null @@ -1,79 +0,0 @@ -projection_json = file_get_contents($interop_schema_file_name); - $this->projection = AvroSchema::parse($this->projection_json); - } - - /** - * @return array - */ - public function file_name_provider() - { - $data_dir = AVRO_BUILD_DATA_DIR; - $data_files = array(); - if (!($dh = opendir($data_dir))) - die("Could not open data dir '$data_dir'\n"); - - while ($file = readdir($dh)) - if (0 < preg_match('/^[a-z]+(_deflate|_snappy)?\.avro$/', $file)) - $data_files []= join(DIRECTORY_SEPARATOR, array($data_dir, $file)); - closedir($dh); - - $ary = array(); - foreach ($data_files as $df) - $ary []= array($df); - return $ary; - } - - /** - * @dataProvider file_name_provider - * @param $file_name - * @throws AvroDataIOException - */ - public function test_read($file_name) - { - - $dr = AvroDataIO::open_file( - $file_name, AvroFile::READ_MODE, $this->projection_json); - - $data = $dr->data(); - - $this->assertNotEquals(0, count($data), - sprintf("no data read from %s", $file_name)); - - foreach ($data as $idx => $datum) - $this->assertNotNull($datum, sprintf("null datum from %s", $file_name)); - - } - -} diff --git a/test/generate_interop_data.php b/test/generate_interop_data.php deleted file mode 100644 index 77971b3..0000000 --- a/test/generate_interop_data.php +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env php - null, - 'boolField' => true, - 'intField' => -42, - 'longField' => (int) 2147483650, - 'floatField' => 1234.0, - 'doubleField' => -5432.6, - 'stringField' => 'hello avro', - 'bytesField' => "\x16\xa6", - 'arrayField' => array(5.0, -6.0, -10.5), - 'mapField' => array('a' => array('label' => 'a'), - 'c' => array('label' => '3P0')), - 'unionField' => 14.5, - 'enumField' => 'C', - 'fixedField' => '1019181716151413', - 'recordField' => array('label' => 'blah', - 'children' => array( - array('label' => 'inner', - 'children' => array())))); - - $schema_json = file_get_contents(AVRO_INTEROP_SCHEMA); - $io_writer = AvroDataIO::open_file($data_file, 'w', $schema_json); - $io_writer->append($datum); - $io_writer->close(); -}