diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9baa25b..dcd8ea5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,12 +27,18 @@ jobs: - name: Cache Composer dependencies uses: actions/cache@v4 with: - path: vendor + path: ./vendor-${{ matrix.php-version }} key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-php-${{ matrix.php-version }}- - - name: Install dependencies - run: docker compose run --rm -v ${{ github.workspace }}/test-output:/app/test-output ${{ matrix.php-version }}composer composer install --prefer-dist + - name: Install dependencies (if needed) + run: | + if [ ! -d ./vendor-${{ matrix.php-version }} ] || [ -z "$(ls -A ./vendor-${{ matrix.php-version }})" ]; then + echo "Dependencies not found or vendor directory is empty. Installing dependencies..." + docker compose run --rm -v ${{ github.workspace }}/vendor-${{ matrix.php-version }}:/app/vendor ${{ matrix.php-version }}composer composer install --prefer-dist + else + echo "Dependencies already installed for ${{ matrix.php-version }}. Skipping composer install." + fi - name: Run tests - run: docker compose run --rm -v ${{ github.workspace }}/test-output:/app/test-output ${{ matrix.php-version }} vendor/bin/phpunit \ No newline at end of file + run: docker compose run --rm -v ${{ github.workspace }}/vendor-${{ matrix.php-version }}:/app/vendor ${{ matrix.php-version }} vendor/bin/phpunit \ No newline at end of file diff --git a/.gitignore b/.gitignore index a000178..6be6918 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,6 @@ composer.lock .phpunit.result.cache .php-cs-fixer.cache /.phpunit.cache/ +/vendor-php81/ +/vendor-php82/ +/vendor-php83/ diff --git a/docker-compose.yml b/docker-compose.yml index e694c29..ecba499 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: target: base volumes: - ./:/app + - ./vendor-php81:/app/vendor php81debug: build: @@ -13,6 +14,7 @@ services: volumes: - ./:/app - ./docker/php81:/usr/local/etc/php + - ./vendor-php81:/app/vendor php81composer: build: @@ -20,6 +22,7 @@ services: target: composer volumes: - ./:/app + - ./vendor-php81:/app/vendor php82: build: @@ -27,6 +30,7 @@ services: target: base volumes: - ./:/app + - ./vendor-php82:/app/vendor php82debug: build: @@ -35,6 +39,7 @@ services: volumes: - ./:/app - ./docker/php82:/usr/local/etc/php + - ./vendor-php82:/app/vendor php82composer: build: @@ -42,6 +47,7 @@ services: target: composer volumes: - ./:/app + - ./vendor-php82:/app/vendor php83: build: @@ -49,6 +55,7 @@ services: target: base volumes: - ./:/app + - ./vendor-php83:/app/vendor php83debug: build: @@ -56,11 +63,13 @@ services: target: debug volumes: - ./:/app - - ./docker/php82:/usr/local/etc/php + - ./docker/php83:/usr/local/etc/php + - ./vendor-php83:/app/vendor php83composer: build: context: docker/php83 target: composer volumes: - - ./:/app \ No newline at end of file + - ./:/app + - ./vendor-php83:/app/vendor \ No newline at end of file diff --git a/test.sh b/test.sh index bfe3e7e..72cbe54 100755 --- a/test.sh +++ b/test.sh @@ -1,21 +1,18 @@ -# run-tests.sh +#!/bin/bash set -e php_versions=("php83" "php82" "php81") for version in "${php_versions[@]}"; do - if [ -f composer.lock ]; then - echo "removing composer.lock" - rm composer.lock - fi + vendor_dir="./vendor-${version}" - docker compose run --rm "$version"composer composer install + if [ ! -d "$vendor_dir" ] || [ -z "$(ls -A "$vendor_dir")" ]; then + echo "Dependencies not found or vendor directory is empty for $version. Installing dependencies..." + docker compose run --rm "${version}composer" composer install --no-cache + fi - echo "Running tests on $version..." if ! docker compose run --rm "$version" vendor/bin/phpunit; then echo "Tests failed on $version." exit 1 fi -done - -echo "All tests passed!" \ No newline at end of file +done \ No newline at end of file