From a00d74ff1c3f429239ef93787065c4376c54fabd Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Wed, 21 Jan 2026 15:57:44 +0800 Subject: matrix test --- .gitattributes | 1 + composer.json | 8 +++++++- docker-compose.yml | 20 ++++++++++++++++++++ scripts/test.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yml create mode 100644 scripts/test.sh diff --git a/.gitattributes b/.gitattributes index f83bef1..6b51cf8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,3 +5,4 @@ tests/ export-ignore .gitignore export-ignore phpunit.xml.dist export-ignore src/Build/ export-ignore +docker-compose.yml export-ignore diff --git a/composer.json b/composer.json index 0b244f0..d413ca9 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,12 @@ "phpunit/phpunit": "^12" }, "scripts": { - "test": "phpunit" + "test": "phpunit", + "matrix": [ + "COMPOSER_FLAGS=--prefer-lowest docker compose run --rm php84", + "COMPOSER_FLAGS=--prefer-stable docker compose run --rm php84", + "COMPOSER_FLAGS=--prefer-lowest docker compose run --rm php85", + "COMPOSER_FLAGS=--prefer-stable docker compose run --rm php85" + ] } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4a8aea4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +x-test: &test + environment: + - COMPOSER_FLAGS=${COMPOSER_FLAGS:-} + volumes: + - .:/app:ro + - composer-cache:/root/.composer + working_dir: /app + command: sh scripts/test.sh + +services: + php84: + <<: *test + image: php:8.4-cli-alpine + + php85: + <<: *test + image: php:8.5-cli-alpine + +volumes: + composer-cache: diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100644 index 0000000..70554be --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,28 @@ +#!/bin/sh +set -e + +COMPOSER_PHAR="/root/.composer/composer.phar" +WORKDIR="/tmp/app" + +# Copy project to isolated working directory +rm -rf "$WORKDIR" +cp -r /app "$WORKDIR" +cd "$WORKDIR" + +# Remove lock file and vendor for fresh install +rm -f composer.lock +rm -rf vendor/ + +# Download Composer if not cached +if [ ! -f "$COMPOSER_PHAR" ]; then + echo "Downloading Composer..." + mkdir -p /root/.composer + curl -sS https://getcomposer.org/installer | php -- --install-dir=/root/.composer --filename=composer.phar +fi + +# Install dependencies +echo "COMPOSER_FLAGS: ${COMPOSER_FLAGS:-}" +php "$COMPOSER_PHAR" update --no-interaction ${COMPOSER_FLAGS:-} + +# Run tests +php "$COMPOSER_PHAR" test -- cgit v1.2.3