Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHP 8.4 deprecation #230

Merged
merged 36 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5ea3b1c
Bump DI52 to ^4. Do a composer update
Luc45 Dec 14, 2024
8e83dc0
Run PHPUnit on multiple versions
Luc45 Dec 14, 2024
d5846b5
Only install xdebug in 8+
Luc45 Dec 14, 2024
ce4f870
Tweak test so that it's PHP 7 compatible
Luc45 Dec 14, 2024
aa103b0
Add command to run or check all phpunit versions as convenience
Luc45 Dec 14, 2024
8cef3a4
Move file
Luc45 Dec 14, 2024
8565697
Remove make phpunit from code-tests.yml
Luc45 Dec 14, 2024
4b12723
Merge branch 'trunk' into 24-12/php-84-deprecation
Luc45 Dec 14, 2024
d861a5d
Re-add phpunit workflow
Luc45 Dec 14, 2024
f27ba54
Run locally in CI and Dockerized locally
Luc45 Dec 14, 2024
5492304
Fix paths
Luc45 Dec 14, 2024
8e91b83
Revert "Fix paths"
Luc45 Dec 14, 2024
daf648f
Revert "Run locally in CI and Dockerized locally"
Luc45 Dec 14, 2024
4c57356
Cache built image
Luc45 Dec 14, 2024
d73ed76
Test cached run
Luc45 Dec 14, 2024
ad593a9
Test cache burst if needed
Luc45 Dec 14, 2024
ffa870b
Revert cache burst check
Luc45 Dec 14, 2024
f1be510
Merge branch 'trunk' into 24-12/php-84-deprecation
Luc45 Dec 14, 2024
5ac8120
Also run Phan on multiple PHP versions
Luc45 Dec 14, 2024
0692aca
Debug CI
Luc45 Dec 14, 2024
dcb763c
Also use the docker cache in"code tests" workflow
Luc45 Dec 14, 2024
810d487
Reuse docker cache logic
Luc45 Dec 14, 2024
93647f3
Checkout before reuse
Luc45 Dec 14, 2024
5c9dd27
Tweak syntax
Luc45 Dec 14, 2024
1dd4a2c
Fix syntax
Luc45 Dec 14, 2024
04cbea7
Trigger CI
Luc45 Dec 14, 2024
266f382
Trigger CI
Luc45 Dec 14, 2024
8ee4b07
Typo
Luc45 Dec 14, 2024
5809f63
Trigger CI
Luc45 Dec 14, 2024
4e83112
Restore docker cache at the right place in the matrix
Luc45 Dec 14, 2024
8409358
Try to use composite action
Luc45 Dec 14, 2024
2673062
Checkout first
Luc45 Dec 14, 2024
38ded55
Add missing shell properties
Luc45 Dec 14, 2024
fa5bbe8
build
Luc45 Dec 16, 2024
598bca7
Merge branch 'trunk' into 24-12/php-84-deprecation
Luc45 Dec 16, 2024
ff2f0bc
build
Luc45 Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/actions/restore-docker-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Restore Docker Image Cache
description: Restores or builds docker image cache for a given PHP version
inputs:
php-version:
description: "PHP version to build/load the docker image for"
required: true
runs:
using: composite
steps:
- name: Check out code
uses: actions/checkout@v4

- name: Restore Docker image cache
uses: actions/cache@v3
id: cache-docker
with:
path: qit-cli-tests-${{ inputs.php-version }}.tar
key: ${{ runner.os }}-qit-cli-tests-${{ inputs.php-version }}-${{ hashFiles('_build/docker/php/**') }}

- name: Build Docker image if needed
if: steps.cache-docker.outputs.cache-hit != 'true'
run: |
docker build --build-arg CI=true --build-arg PHP_VERSION=${{ inputs.php-version }} -t qit-cli-tests:${{ inputs.php-version }} ./_build/docker/php
docker save qit-cli-tests:${{ inputs.php-version }} -o qit-cli-tests-${{ inputs.php-version }}.tar
shell: bash

- name: Load Docker image from cache
if: steps.cache-docker.outputs.cache-hit == 'true'
run: |
docker load -i qit-cli-tests-${{ inputs.php-version }}.tar
shell: bash
25 changes: 19 additions & 6 deletions .github/workflows/code-tests.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,43 @@
name: QIT CLI Code tests
on:
workflow_call:
push:
pull_request:
paths:
- 'src/**.php'
workflow_dispatch:

concurrency:
group: code-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
code_tests:
name: Code tests
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/cache@v3

- name: Restore Docker Cache (default PHP 8.3)
uses: ./.github/actions/restore-docker-cache
with:
php-version: "8.3"

- name: Cache composer dependencies
uses: actions/cache@v3
id: cache-composer
with:
path: src/vendor
key: ${{ runner.os }}-${{ hashFiles('src/composer.lock') }}

- name: Composer install
if: steps.cache-composer.outputs.cache-hit != 'true'
working-directory: src
run: composer install

- name: Run PHPCS
run: make phpcs

- name: Run PHPStan
run: make phpstan

- name: Run Phan
run: make phan
- name: Run PHPUnit
run: make phpunit
36 changes: 34 additions & 2 deletions .github/workflows/phan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,42 @@ on:
pull_request:
paths:
- 'src/**.php'
workflow_dispatch:

concurrency:
group: phan-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
phan_tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

steps:
- name: Echo Bogus
run: echo "Bogus workflow to allow PR-based testing."
- name: Checkout code
uses: actions/checkout@v4

- name: Restore Docker Cache
uses: ./.github/actions/restore-docker-cache
with:
php-version: ${{ matrix.php }}

- name: Cache composer dependencies
uses: actions/cache@v3
id: cache-composer
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('src/composer.lock') }}

- name: Composer install
if: steps.cache-composer.outputs.cache-hit != 'true'
run: |
cd src
composer install --no-interaction --no-suggest --prefer-dist

- name: Run Phan
env:
PHP_VERSION: ${{ matrix.php }}
run: make phan
36 changes: 34 additions & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,42 @@ on:
pull_request:
paths:
- 'src/**.php'
workflow_dispatch:

concurrency:
group: phpunit-tests-${{ github.ref }}
cancel-in-progress: true

jobs:
phpunit_tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4' ]

steps:
- name: Echo Bogus
run: echo "Bogus workflow to allow PR-based testing."
- name: Checkout code
uses: actions/checkout@v4

- name: Restore Docker Cache
uses: ./.github/actions/restore-docker-cache
with:
php-version: ${{ matrix.php }}

- name: Cache composer dependencies
uses: actions/cache@v3
id: cache-composer
with:
path: src/vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('src/composer.lock') }}

- name: Composer install
if: steps.cache-composer.outputs.cache-hit != 'true'
run: |
cd src
composer install --no-interaction --no-suggest --prefer-dist

- name: Run PHPUnit tests
env:
PHP_VERSION: ${{ matrix.php }}
run: make phpunit
32 changes: 32 additions & 0 deletions .github/workflows/restore-docker-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Restore Docker Image Cache
on:
workflow_call:
inputs:
php-version:
required: true
type: string

jobs:
restore-docker-cache:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Restore Docker image cache
uses: actions/cache@v3
id: cache-docker
with:
path: qit-cli-tests-${{ inputs.php-version }}.tar
key: ${{ runner.os }}-qit-cli-tests-${{ inputs.php-version }}-${{ hashFiles('_build/docker/php/**') }}

- name: Build Docker image if needed
if: steps.cache-docker.outputs.cache-hit != 'true'
run: |
docker build --build-arg CI=true --build-arg PHP_VERSION=${{ inputs.php-version }} -t qit-cli-tests:${{ inputs.php-version }} ./_build/docker/php
docker save qit-cli-tests:${{ inputs.php-version }} -o qit-cli-tests-${{ inputs.php-version }}.tar

- name: Load Docker image from cache
if: steps.cache-docker.outputs.cache-hit == 'true'
run: |
docker load -i qit-cli-tests-${{ inputs.php-version }}.tar
87 changes: 62 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,37 @@ DEBUG ?= 0
ARGS ?=
VERSION ?= qit_dev_build

# List all PHP versions you want to test/build images for:
PHP_VERSIONS = 7.2 7.3 7.4 8.0 8.1 8.2 8.3 8.4
# Default PHP version used if none specified
PHP_VERSION ?= 8.3

ifeq (1, $(ROOT))
DOCKER_USER ?= "0:0"
else
DOCKER_USER ?= "$(shell id -u):$(shell id -g)"
endif

## Run a command inside an alpine PHP 8 CLI image.
## 1. Command to execute, eg: "./vendor/bin/phpcs" 2. Working dir (optional)
## Run a command inside a PHP CLI Docker image built for a specific PHP_VERSION.
## 1. Command to execute, e.g.: "php /app/src/vendor/bin/phpcs"
## 2. Working dir (optional)
define execPhpAlpine
@docker image inspect qit-cli-php-xdebug-pcntl > /dev/null 2>&1 || docker build --build-arg CI=${CI} -t qit-cli-php-xdebug-pcntl ./_build/docker/php83
docker run --rm \
--user $(DOCKER_USER) \
-v "${PWD}:/app" \
-v "${PWD}/_build/docker/php83/ini/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini" \
--env QIT_HOME=/tmp \
--env PHP_IDE_CONFIG=serverName=qit_cli \
--workdir "$(2:=/)" \
--add-host host.docker.internal:host-gateway \
qit-cli-php-xdebug-pcntl \
bash -c "php -d xdebug.start_with_request=$(if $(filter 1,$(DEBUG)),yes,no) -d memory_limit=1G $(1)"
@docker image inspect qit-cli-tests:$(PHP_VERSION) > /dev/null 2>&1 || \
(echo "Docker image not found. Building qit-cli-tests:$(PHP_VERSION)..." && \
docker build --build-arg CI=${CI} --build-arg PHP_VERSION=$(PHP_VERSION) -t qit-cli-tests:$(PHP_VERSION) ./_build/docker/php)

@docker run --rm \
--user $(DOCKER_USER) \
-v "${PWD}:/app" \
-v "${PWD}/_build/docker/php/ini/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini" \
--env QIT_HOME=/tmp \
--env PHP_IDE_CONFIG=serverName=qit_cli \
--env TARGET_PHP_VERSION=$(PHP_VERSION) \
--env PHAN_DISABLE_XDEBUG_WARN=1 \
--env PHAN_ALLOW_XDEBUG=1 \
--workdir "$(2:=/)" \
qit-cli-tests:$(PHP_VERSION) \
bash -c "$(1)"
endef

watch:
Expand All @@ -44,14 +55,11 @@ build:
composer \
install --no-dev --quiet --optimize-autoloader --ignore-platform-reqs

# Create a temporary configuration file with the specified VERSION
@sed "s/QIT_VERSION_REPLACE/$(VERSION)/g" ./_build/box.json.dist > ./_build/box.json

# Ensure the Docker image is built and run Box with the temporary configuration file
@docker images -q | grep qit-cli-box || docker build -t qit-cli-box ./_build/docker/box
@docker run --rm -v ${PWD}:${PWD} -w ${PWD} -u "$(shell id -u):$(shell id -g)" qit-cli-box ./_build/box.phar compile -c ./_build/box.json --no-parallel || rm -rf src-tmp

# Clean up the temporary directory and configuration file
@rm -rf src-tmp
@rm -f ./_build/box.json

Expand All @@ -61,22 +69,51 @@ tests:
$(MAKE) phpunit
$(MAKE) phan

tests-all:
$(MAKE) phpcs
$(MAKE) phpstan
$(MAKE) phpunit-all
$(MAKE) phan-all

phpcbf:
$(call execPhpAlpine,/app/src/vendor/bin/phpcbf /app/src/qit-cli.php /app/src/src -s --standard=/app/src/.phpcs.xml.dist)
$(call execPhpAlpine,php /app/src/vendor/bin/phpcbf /app/src/qit-cli.php /app/src/src -s --standard=/app/src/.phpcs.xml.dist)

phpcs:
$(MAKE) phpcbf || true
$(call execPhpAlpine,/app/src/vendor/bin/phpcs /app/src/qit-cli.php /app/src/src -s --standard=/app/src/.phpcs.xml.dist)
$(call execPhpAlpine,php /app/src/vendor/bin/phpcs /app/src/qit-cli.php /app/src/src -s --standard=/app/src/.phpcs.xml.dist)

# Added --memory-limit=1G here
phpstan:
$(call execPhpAlpine,/app/src/vendor/bin/phpstan -vvv analyse -c /app/src/phpstan.neon)
$(call execPhpAlpine,php /app/src/vendor/bin/phpstan -vvv analyse -c /app/src/phpstan.neon --memory-limit=1G)

phpunit:
$(call execPhpAlpine,/app/src/vendor/bin/phpunit -c /app/src/phpunit.xml.dist $(ARGS))
$(call execPhpAlpine,php /app/src/vendor/bin/phpunit -c /app/src/phpunit.xml.dist $(ARGS),/app/src)

phpunit-all:
@for ver in $(PHP_VERSIONS); do \
echo "Running PHPUnit on PHP $$ver..."; \
$(MAKE) phpunit PHP_VERSION=$$ver || exit 1; \
done

phan-all:
@for ver in $(PHP_VERSIONS); do \
echo "Running Phan on PHP $$ver..."; \
$(MAKE) phan PHP_VERSION=$$ver || exit 1; \
done

check-php-versions:
@for ver in $(PHP_VERSIONS); do \
echo "Checking PHP version in qit-cli-tests:$$ver..."; \
docker image inspect qit-cli-tests:$$ver >/dev/null 2>&1 || (echo "Image not found for $$ver, building..." && docker build --build-arg CI=${CI} --build-arg PHP_VERSION=$$ver -t qit-cli-tests:$$ver ./_build/docker/php); \
docker run --rm qit-cli-tests:$$ver php -v; \
echo "-----------------------------------"; \
done

rebuild-images:
@for ver in $(PHP_VERSIONS); do \
echo "Rebuilding qit-cli-tests:$$ver..."; \
docker build --no-cache --build-arg CI=${CI} --build-arg PHP_VERSION=$$ver -t qit-cli-tests:$$ver ./_build/docker/php || exit 1; \
done

phan:
docker run --rm \
-v ${PWD}/src:/mnt/src \
-u "$$(id -u):$$(id -g)" \
phanphp/phan:latest $(ARGS)
# PS: To update Phan, run: docker image pull phanphp/phan:latest
$(call execPhpAlpine,php -d xdebug.mode=off /app/src/vendor/bin/phan $(ARGS),/app/src)
17 changes: 17 additions & 0 deletions _build/docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Use an ARG for the PHP version. Default to 8.3 if not provided.
ARG PHP_VERSION=8.3
FROM php:${PHP_VERSION}-cli

ARG CI
RUN apt-get update \
&& apt-get install -y libzip-dev \
&& docker-php-ext-install zip pcntl \
&& docker-php-ext-enable zip pcntl

# Install php-ast
RUN pecl install ast && docker-php-ext-enable ast

# Install Xdebug only if not in CI environment and PHP major version >= 8
RUN if [ "$CI" != "true" ] && [ "${PHP_VERSION%%.*}" -ge 8 ]; then \
pecl install xdebug && docker-php-ext-enable xdebug; \
fi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.output_dir = /app/_build/docker/php83/xdebug/output
xdebug.log = /app/_build/docker/php83/xdebug/xdebug.log
xdebug.output_dir = /app/_build/docker/php/xdebug/output
xdebug.log = /app/_build/docker/php/xdebug/xdebug.log
# Enabled at runtime with DEBUG=1
xdebug.start_with_request = no

Expand Down
File renamed without changes.
Empty file.
15 changes: 0 additions & 15 deletions _build/docker/php83/Dockerfile

This file was deleted.

Binary file modified qit
Binary file not shown.
2 changes: 1 addition & 1 deletion src/.phan/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// Note that the **only** effect of choosing `'5.6'` is to infer that functions removed in php 7.0 exist.
// (See `backward_compatibility_checks` for additional options)
// Automatically inferred from composer.json requirement for "php" of "^7.2.5 | ^8"
'target_php_version' => '7.2',
'target_php_version' => getenv( 'TARGET_PHP_VERSION' ) ?: '7.2',

// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
Expand Down
Loading
Loading