From 564bac3f638e90d4d2bad8579e26c831fe111d82 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 25 Feb 2023 17:23:59 +0000 Subject: [PATCH 1/4] Fixed broken CI (#44) --- .github/workflows/static.yml | 33 +++++++++++++++++++++++++++++++-- .github/workflows/tests.yml | 4 +++- composer.json | 13 ++++++++----- hack/8.1.Dockerfile | 2 +- phpunit.xml.dist | 31 +++++++++++-------------------- src/Http/Unmarshaller.php | 8 ++++++-- src/Utilities/TimeFormatter.php | 1 + src/V1/CloudEventTrait.php | 2 ++ 8 files changed, 63 insertions(+), 31 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e02e209..2b254da 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -2,10 +2,37 @@ name: Static Analysis on: push: - branches: [ master ] + branches: [ main ] pull_request: jobs: + codesniffer: + name: PHP CodeSniffer + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + tools: composer:v2 + coverage: none + env: + update: true + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHP CodeSniffer + run: vendor/bin/phpcs -n -q --standard=PSR12 ./src ./tests + psalm: name: Psalm runs-on: ubuntu-20.04 @@ -17,9 +44,11 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '7.4' tools: composer:v2 coverage: none + env: + update: true - name: Install Dependencies uses: nick-invision/retry@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index eaa353a..4e21981 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,7 +2,7 @@ name: Tests on: push: - branches: [ master ] + branches: [ main ] pull_request: jobs: @@ -24,6 +24,8 @@ jobs: php-version: ${{ matrix.php }} tools: composer:v2 coverage: none + env: + update: true - name: Setup Problem Matchers run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" diff --git a/composer.json b/composer.json index 5e22f18..655cf79 100644 --- a/composer.json +++ b/composer.json @@ -27,10 +27,10 @@ "guzzlehttp/psr7": "^2.0", "php-http/discovery": "^1.14", "phpunit/phpunit": "^9.5 || ^10.0", - "psalm/phar": "4.15.0", + "psalm/phar": "5.7.6", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", - "squizlabs/php_codesniffer": "3.6.0" + "squizlabs/php_codesniffer": "3.7.2" }, "suggest": { "php-http/discovery": "Required for automatic discovery of HTTP message factories in the HTTP Marshaller.", @@ -40,8 +40,8 @@ "psr/http-message-implementation": "Required for use of the HTTP Marshaller and Unmarshaller." }, "scripts": { - "lint": "./vendor/bin/phpcs --standard=PSR12 ./src ./tests", - "lint-fix": "./vendor/bin/phpcbf --standard=PSR12 ./src ./tests", + "lint": "./vendor/bin/phpcs -n --standard=PSR12 ./src ./tests", + "lint-fix": "./vendor/bin/phpcbf -n --standard=PSR12 ./src ./tests", "tests": "./vendor/bin/phpunit", "sa": "./vendor/bin/psalm.phar", "tests-build": [ @@ -65,7 +65,10 @@ }, "config": { "preferred-install": "dist", - "sort-packages": true + "sort-packages": true, + "allow-plugins": { + "php-http/discovery": true + } }, "extra": { "branch-alias": { diff --git a/hack/8.1.Dockerfile b/hack/8.1.Dockerfile index a9f6b0f..09a6230 100644 --- a/hack/8.1.Dockerfile +++ b/hack/8.1.Dockerfile @@ -1,4 +1,4 @@ -FROM php:8.1.0beta1-alpine +FROM php:8.1-alpine LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/8.1.Dockerfile" \ org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c5f8f8e..39df3df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,13 @@ - - - - tests/Unit - - - - - src - - + + + + tests/Unit + + + + + src + + diff --git a/src/Http/Unmarshaller.php b/src/Http/Unmarshaller.php index 89e2977..95c4885 100644 --- a/src/Http/Unmarshaller.php +++ b/src/Http/Unmarshaller.php @@ -92,18 +92,21 @@ private static function unmarshalBinary( MessageInterface $message, DeserializerInterface $deserializer ): array { + /** @var array> */ + $headers = $message->getHeaders(); + /** @psalm-suppress MixedArgumentTypeCoercion */ $cloudEvent = $deserializer->deserializeBinary( (string) $message->getBody(), implode(', ', $message->getHeader('Content-Type')), - self::decodeAttributes($message->getHeaders()) + self::decodeAttributes($headers) ); return [$cloudEvent]; } /** - * @param array> $headers + * @param array> $headers * * @return array */ @@ -112,6 +115,7 @@ private static function decodeAttributes(array $headers): array $attributes = []; foreach ($headers as $key => $values) { + $key = (string) $key; /** @psalm-suppress UndefinedFunction */ if (\str_starts_with($key, 'ce-')) { $attributes[substr($key, 3)] = implode(', ', $values); diff --git a/src/Utilities/TimeFormatter.php b/src/Utilities/TimeFormatter.php index 0bee483..b166608 100644 --- a/src/Utilities/TimeFormatter.php +++ b/src/Utilities/TimeFormatter.php @@ -34,6 +34,7 @@ public static function decode(?string $time): ?DateTimeImmutable return null; } + /** @psalm-suppress UndefinedFunction */ $decoded = DateTimeImmutable::createFromFormat( \str_contains($time, '.') ? self::RFC3339_EXTENDED_FORMAT : self::RFC3339_FORMAT, \strtoupper($time), diff --git a/src/V1/CloudEventTrait.php b/src/V1/CloudEventTrait.php index 23d11cd..b2fb3b4 100644 --- a/src/V1/CloudEventTrait.php +++ b/src/V1/CloudEventTrait.php @@ -273,10 +273,12 @@ private function setExtension(string $attribute, $value): self ); } + /** @psalm-suppress UndefinedFunction */ $type = \get_debug_type($value); $types = ['bool', 'int', 'string', 'null']; if (!in_array($type, $types, true)) { + /** @psalm-suppress MixedArgument */ throw new TypeError( \sprintf('%s(): Argument #2 ($value) must be of type %s, %s given', __METHOD__, implode('|', $types), $type) ); From 3dfd9249abca707307e46e35e7d70002170ffecf Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 25 Feb 2023 17:29:43 +0000 Subject: [PATCH 2/4] Link to v1.0.2 spec (#41) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86734de..fc7a1d3 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ This SDK currently supports the following versions of CloudEvents: -- [v1.0](https://github.com/cloudevents/spec/blob/v1.0.1/spec.md) +- [v1.0](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md) ## Installation From d13515ea1fc9b48032da3cb12a3705dd5f06c9bb Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 25 Feb 2023 17:30:19 +0000 Subject: [PATCH 3/4] Fixed everything that broke after master was renamed to main (#42) --- README.md | 8 ++++---- composer.json | 2 +- hack/7.4.Dockerfile | 4 ++-- hack/8.0.Dockerfile | 4 ++-- hack/8.1.Dockerfile | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index fc7a1d3..35fae23 100644 --- a/README.md +++ b/README.md @@ -109,11 +109,11 @@ scripts: Each SDK may have its own unique processes, tooling and guidelines, common governance related material can be found in the -[CloudEvents `community`](https://github.com/cloudevents/spec/tree/master/community) +[CloudEvents `community`](https://github.com/cloudevents/spec#community-and-docs) directory. In particular, in there you will find information concerning how SDK projects are -[managed](https://github.com/cloudevents/spec/blob/master/community/SDK-GOVERNANCE.md), -[guidelines](https://github.com/cloudevents/spec/blob/master/community/SDK-maintainer-guidelines.md) +[managed](https://github.com/cloudevents/spec/blob/main/docs/SDK-GOVERNANCE.md), +[guidelines](https://github.com/cloudevents/spec/blob/main/docs/SDK-maintainer-guidelines.md) for how PR reviews and approval, and our -[Code of Conduct](https://github.com/cloudevents/spec/blob/master/community/GOVERNANCE.md#additional-information) +[Code of Conduct](https://github.com/cncf/foundation/blob/main/code-of-conduct.md) information. diff --git a/composer.json b/composer.json index 655cf79..9c90b04 100644 --- a/composer.json +++ b/composer.json @@ -72,7 +72,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-main": "1.0-dev" } }, "minimum-stability": "dev", diff --git a/hack/7.4.Dockerfile b/hack/7.4.Dockerfile index 56e0ad3..87941f9 100644 --- a/hack/7.4.Dockerfile +++ b/hack/7.4.Dockerfile @@ -1,7 +1,7 @@ FROM php:7.4-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/7.4.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/7.4.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 7.4" \ diff --git a/hack/8.0.Dockerfile b/hack/8.0.Dockerfile index 8285996..8e7e0d1 100644 --- a/hack/8.0.Dockerfile +++ b/hack/8.0.Dockerfile @@ -1,7 +1,7 @@ FROM php:8.0-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/8.0.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.0.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 8.0" \ diff --git a/hack/8.1.Dockerfile b/hack/8.1.Dockerfile index 09a6230..3913014 100644 --- a/hack/8.1.Dockerfile +++ b/hack/8.1.Dockerfile @@ -1,7 +1,7 @@ FROM php:8.1-alpine -LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/master/hack/8.1.Dockerfile" \ - org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/master/hack/README.md" \ +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.1.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ org.opencontainers.image.vendor="CloudEvent" \ org.opencontainers.image.title="PHP 8.1" \ From f2e22c624bd1380e50b6a5c1a9526e29bcce6317 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 25 Feb 2023 17:31:59 +0000 Subject: [PATCH 4/4] Support PHP 8.2 (#43) --- .github/workflows/static.yml | 2 +- .github/workflows/tests.yml | 4 ++-- composer.json | 16 +++++++++------- hack/8.2.Dockerfile | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 hack/8.2.Dockerfile diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 2b254da..cb5e2d0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -35,7 +35,7 @@ jobs: psalm: name: Psalm - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout code diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4e21981..38b1a4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,11 +8,11 @@ on: jobs: tests: name: PHP ${{ matrix.php }} - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 strategy: matrix: - php: ['7.4', '8.0', '8.1'] + php: ['7.4', '8.0', '8.1', '8.2'] steps: - name: Checkout Code diff --git a/composer.json b/composer.json index 9c90b04..dbcd84b 100644 --- a/composer.json +++ b/composer.json @@ -18,15 +18,15 @@ } }, "require": { - "php": "^7.4 || ^8.0", + "php": "^7.4.15 || ^8.0.2", "ext-json": "*", "ext-pcre": "*", - "symfony/polyfill-php80": "^1.17" + "symfony/polyfill-php80": "^1.26" }, "require-dev": { - "guzzlehttp/psr7": "^2.0", - "php-http/discovery": "^1.14", - "phpunit/phpunit": "^9.5 || ^10.0", + "guzzlehttp/psr7": "^2.4.3", + "php-http/discovery": "^1.15.2", + "phpunit/phpunit": "^9.6.3 || ^10.0.12", "psalm/phar": "5.7.6", "psr/http-factory": "^1.0.1", "psr/http-message": "^1.0.1", @@ -47,12 +47,14 @@ "tests-build": [ "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:7.4-tests -f hack/7.4.Dockerfile hack", "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.0-tests -f hack/8.0.Dockerfile hack", - "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.1-tests -f hack/8.1.Dockerfile hack" + "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.1-tests -f hack/8.1.Dockerfile hack", + "DOCKER_BUILDKIT=1 docker build -t cloudevents/sdk-php:8.2-tests -f hack/8.1.Dockerfile hack" ], "tests-docker": [ "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:7.4-tests --coverage-html=coverage", "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.0-tests", - "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.1-tests" + "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.1-tests", + "docker run -it -v $(pwd):/var/www cloudevents/sdk-php:8.2-tests" ] }, "scripts-descriptions": { diff --git a/hack/8.2.Dockerfile b/hack/8.2.Dockerfile new file mode 100644 index 0000000..22027fb --- /dev/null +++ b/hack/8.2.Dockerfile @@ -0,0 +1,22 @@ +FROM php:8.2-alpine + +LABEL org.opencontainers.image.url="https://github.com/cloudevents/sdk-php/tree/main/hack/8.2.Dockerfile" \ + org.opencontainers.image.documentation="https://github.com/cloudevents/sdk-php/tree/main/hack/README.md" \ + org.opencontainers.image.source="https://github.com/cloudevents/sdk-php" \ + org.opencontainers.image.vendor="CloudEvent" \ + org.opencontainers.image.title="PHP 8.2" \ + org.opencontainers.image.description="PHP 8.2 test environment for cloudevents/sdk-php" + +COPY --chown=www-data:www-data install-composer /usr/local/bin/install-composer +RUN chmod +x /usr/local/bin/install-composer \ + && /usr/local/bin/install-composer \ + && rm /usr/local/bin/install-composer + +RUN apk update \ + && apk --no-cache upgrade \ + && apk add --no-cache bash ca-certificates git libzip-dev \ + && rm -rf /var/www/html /tmp/pear \ + && chown -R www-data:www-data /var/www + +WORKDIR /var/www +ENTRYPOINT ["/var/www/vendor/bin/phpunit"]