diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 9a56ee7..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,54 +0,0 @@ -version: 2 -jobs: - build: - working_directory: /root/project - docker: - - image: drevops/ci-runner:24.11.0 - environment: - COMPOSER_ALLOW_SUPERUSER: 1 - steps: - - checkout - - setup_remote_docker - - run: - name: Validate Composer configuration - command: composer validate --ansi --strict - - run: - name: Start containers - command: docker compose up -d --build - - run: - name: Copy codebase into container - command: docker cp -L . $(docker compose ps -q phpserver):/app/ - - run: - name: Install dev dependencies - command: docker compose exec phpserver composer install --ansi --no-suggest - - run: - name: Lint code - command: docker compose exec phpserver composer lint - - run: - name: Restart server with Xdebug enabled - command: XDEBUG_ENABLE=true docker compose up -d phpserver - - run: - name: Run tests with PHPUnit - command: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/phpunit - - run: - name: Run tests with Behat - command: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/behat - - run: - name: Process test logs and artifacts - command: | - mkdir -p /tmp/test_results - mkdir -p /tmp/artifacts - if docker compose ps --services --filter "status=running" | grep -q phpserver && docker compose exec phpserver test -d /app/.logs; then - docker compose cp phpserver:/app/.logs/. "/tmp/artifacts/" - if docker compose exec -T phpserver sh -c 'test -d /app/.logs/test_results'; then - docker compose cp phpserver:/app/.logs/test_results/. "/tmp/test_results/" - fi - fi - when: always - - store_test_results: - path: /tmp/test_results - - store_artifacts: - path: /tmp/artifacts - - run: - name: Upload code coverage reports to Codecov - command: if [ -d /tmp/artifacts/coverage ]; then codecov -Z -s /tmp/artifacts/coverage; fi diff --git a/.gitattributes b/.gitattributes index 25ecf3a..0bf0c4c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,5 @@ # Ignore files for distribution archives. -/.circleci export-ignore /.editorconfig export-ignore /.gitattributes export-ignore /.github export-ignore diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2796898 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,94 @@ +name: Test + +on: + push: + branches: + - main + pull_request: + branches: + - main + - 'feature/**' + workflow_dispatch: + inputs: + enable_terminal: + type: boolean + description: 'Enable terminal session.' + required: false + default: false + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Set up Docker Compose + run: docker compose up -d --build + + - name: Copy codebase into container + run: | + container_id="$(docker compose ps -q phpserver)" + docker cp -L . "${container_id}":/app/ + + - name: Install Composer dependencies + run: docker compose exec phpserver composer install --ansi --no-suggest + + - name: Lint code + run: docker compose exec phpserver composer lint + continue-on-error: ${{ vars.CI_LINT_IGNORE_FAILURE == '1' }} + + - name: Restart server with Xdebug enabled + run: XDEBUG_ENABLE=true docker compose up -d phpserver + + - name: Run tests with PHPUnit + run: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/phpunit + continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }} + + - name: Run tests with Behat + run: docker compose exec -T -e XDEBUG_MODE=coverage phpserver vendor/bin/behat + continue-on-error: ${{ vars.CI_TEST_IGNORE_FAILURE == '1' }} + + - name: Process test logs and artifacts + run: | + mkdir -p /tmp/logs + if docker compose ps --services --filter "status=running" | grep -q phpserver && docker compose exec phpserver test -d /app/.logs; then + docker compose cp phpserver:/app/.logs/. "/tmp/logs/" + fi + + - name: Upload artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: artifacts + path: /tmp/logs + + - name: Upload logs as artifacts + if: always() + uses: actions/upload-artifact@v4 + with: + name: logs + path: /tmp/logs + include-hidden-files: true + if-no-files-found: error + + - name: Upload coverage report to Codecov + uses: codecov/codecov-action@v4 + if: ${{ env.CODECOV_TOKEN != '' }} + with: + files: | + /tmp/logs/coverage/behat/cobertura.xml + /tmp/logs/coverage/phpunit/cobertura.xml + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + - name: Setup tmate session + if: ${{ !cancelled() && github.event.inputs.enable_terminal }} + uses: mxschmitt/action-tmate@v3 + timeout-minutes: 5