diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e56a83..f704829 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,32 +19,44 @@ jobs: coverage: xdebug steps: - - uses: actions/checkout@v4 - - run: echo "IMAGE=${{ env.REGISTRY }}/${{ github.repository }}/php${{ matrix.php }}" >> $GITHUB_ENV - - run: echo "TAG=${{ hashFiles(format('.docker/php{0}.Dockerfile', matrix.php)) }}" >> $GITHUB_ENV - - uses: docker/login-action@v3 + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ~/.cache/composer/files + key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + - name: Check out code + uses: actions/checkout@v4 + - name: Set environment variables + run: | + echo "CONTAINER=php${{ matrix.php }}" >> $GITHUB_ENV + echo "IMAGE=${{ env.REGISTRY }}/${{ github.repository }}/php${{ matrix.php }}" >> $GITHUB_ENV + echo "TAG=${{ hashFiles(format('.docker/php{0}.Dockerfile', matrix.php)) }}" >> $GITHUB_ENV + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - run: | - docker pull ${{ env.IMAGE }}:${{ env.TAG }} + - name: Pull image + run: docker pull ${{ env.IMAGE }}:${{ env.TAG }} continue-on-error: true id: pull - - run: | - docker compose build php${{ matrix.php }} - docker tag ${{ github.event.repository.name }}-php${{ matrix.php }} ${{ env.IMAGE }}:${{ env.TAG }} + - name: Build and push image if not pulled + run: | + docker compose build ${{ env.CONTAINER }} + docker tag ${{ github.event.repository.name }}-${{ env.CONTAINER }} ${{ env.IMAGE }}:${{ env.TAG }} docker push ${{ env.IMAGE }}:${{ env.TAG }} if: steps.pull.outcome != 'success' - - uses: actions/cache@v4 - with: - path: ~/.cache/composer/files - key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - run: docker compose -f docker-compose.ci.yml run --rm php${{ matrix.php }} composer update --no-interaction --no-progress --prefer-dist --prefer-${{ matrix.release }} - - run: docker compose -f docker-compose.ci.yml run --rm php${{ matrix.php }} vendor/bin/phpunit ${{ env.COVERAGE }} + - name: Install dependencies + run: | + docker compose -f docker-compose.ci.yml run --rm ${{ env.CONTAINER }} composer update --no-interaction \ + --no-progress --prefer-dist --prefer-${{ matrix.release }} + - name: Run tests + run: docker compose -f docker-compose.ci.yml run --rm ${{ env.CONTAINER }} vendor/bin/phpunit ${{ env.COVERAGE }} env: COVERAGE: ${{ matrix.coverage == 'xdebug' && '--coverage-clover=coverage.xml' || '' }} - - uses: codecov/codecov-action@v3 + - name: Upload code coverage + uses: codecov/codecov-action@v3 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} if: matrix.coverage == 'xdebug' && env.CODECOV_TOKEN