From e06314e8022539704a087b9408022d6a0ac122d5 Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Sun, 9 Feb 2020 23:54:04 +0100 Subject: [PATCH] replace travis with github actions (#1452) --- .github/workflows/coverage.yaml | 35 ++++++++ .github/workflows/linting.yaml | 28 ++++++ .github/workflows/testing.yaml | 58 +++++++++++++ .travis.yml | 96 --------------------- tests/.env.dist.mysql | 14 --- tests/.env.dist.sqlite | 14 --- tests/Invoice/Renderer/CsvRendererTest.php | 3 +- tests/Invoice/Renderer/DocxRendererTest.php | 3 +- tests/Invoice/Renderer/OdsRendererTest.php | 3 +- tests/Invoice/Renderer/TwigRendererTest.php | 3 +- tests/Invoice/Renderer/XlsxRendererTest.php | 3 +- 11 files changed, 131 insertions(+), 129 deletions(-) create mode 100644 .github/workflows/coverage.yaml create mode 100644 .github/workflows/linting.yaml create mode 100644 .github/workflows/testing.yaml delete mode 100644 .travis.yml delete mode 100644 tests/.env.dist.mysql delete mode 100644 tests/.env.dist.sqlite diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml new file mode 100644 index 00000000..dc63e89e --- /dev/null +++ b/.github/workflows/coverage.yaml @@ -0,0 +1,35 @@ +name: Code coverage +on: + pull_request: null + push: + branches: + - master +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.4'] + + name: PHP ${{ matrix.php }} + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + coverage: pcov + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite + - run: | + composer install --no-progress + composer require zendframework/zend-ldap + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Run tests + run: vendor/bin/phpunit tests/ --coverage-clover=coverage.xml + env: + TEST_WITH_BUNDLES: 1 + - name: Upload code coverage + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml new file mode 100644 index 00000000..a2b2c23a --- /dev/null +++ b/.github/workflows/linting.yaml @@ -0,0 +1,28 @@ +name: Code Styles +on: + pull_request: null + push: + branches: + - master +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + php: ['7.4'] + + name: PHP ${{ matrix.php }} + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + coverage: none + extensions: intl + tools: cs2pr:1.0.1 + - run: composer install --no-progress + - run: composer validate --no-check-all --strict + - run: vendor/bin/php-cs-fixer fix --dry-run --verbose --config=.php_cs.dist --using-cache=no --show-progress=none --format=checkstyle | cs2pr + - run: vendor/bin/phpstan analyse src -c phpstan.neon --level=3 --no-progress --error-format=checkstyle | cs2pr + - run: vendor/bin/phpstan analyse tests -c tests/phpstan.neon --level=4 --no-progress --error-format=checkstyle | cs2pr + - run: composer kimai:code-lint diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml new file mode 100644 index 00000000..9b8dffec --- /dev/null +++ b/.github/workflows/testing.yaml @@ -0,0 +1,58 @@ +name: Tests & Migrations +on: + pull_request: null + push: + branches: + - master +jobs: + tests: + runs-on: ubuntu-latest + services: + mysql: + image: mysql:5.7 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: false + MYSQL_ROOT_PASSWORD: kimai + MYSQL_DATABASE: kimai + ports: + - 3306/tcp + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + strategy: + matrix: + php: ['7.2', '7.3', '7.4'] + + name: PHP ${{ matrix.php }} + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php }} + coverage: none + extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, mysql + - run: | + composer install --no-progress + composer require zendframework/zend-ldap + - name: Setup problem matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Run unit tests + run: composer kimai:tests-unit + - name: Run migrations on MySQL + run: | + bin/console doctrine:database:create --if-not-exists -n + bin/console doctrine:migrations:migrate -n + bin/console doctrine:migrations:migrate first -n + env: + DATABASE_URL: mysql://root:kimai@127.0.0.1:${{ job.services.mysql.ports['3306'] }}/kimai + APP_ENV: dev + MAILER_URL: null://localhost + - name: Run migrations on SQLite + run: | + bin/console doctrine:database:create -n + bin/console doctrine:migrations:migrate -n + bin/console doctrine:migrations:migrate first -n + env: + DATABASE_URL: sqlite:///%kernel.project_dir%/var/data/kimai_migrations.sqlite + APP_ENV: dev + MAILER_URL: null://localhost + - name: Run integration tests + run: composer kimai:tests-integration diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a25489c9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,96 +0,0 @@ -dist: xenial -language: php - -cache: - directories: - - $HOME/.composer/cache/files - -matrix: - include: - - stage: Code quality - env: CODECOVERAGE=0 DB=sqlite - php: '7.3' - script: - - composer validate --no-check-all --strict - - composer kimai:codestyle - - composer kimai:phpstan - - composer kimai:code-lint - - stage: Test - php: '7.2' - env: CODECOVERAGE=0 DB=mysql - sudo: required - services: - - mysql - - stage: Test - php: '7.3' - env: CODECOVERAGE=0 DB=mysql - sudo: required - services: - - mysql - - stage: Test - php: '7.4' - env: CODECOVERAGE=0 DB=mysql - sudo: required - services: - - mysql - - stage: Test - php: '7.2' - env: CODECOVERAGE=0 DB=sqlite - - stage: Test - php: '7.3' - env: CODECOVERAGE=0 DB=sqlite - - stage: Test - php: '7.4' - env: CODECOVERAGE=0 DB=sqlite - - stage: Test - php: '7.2' - env: CODECOVERAGE=0 DB=mariadb - addons: - mariadb: '10.2' - services: - - mysql - before_script: - - mysql -u root -e 'CREATE USER IF NOT EXISTS travis@localhost; GRANT ALL ON *.* TO travis@localhost;' - - stage: Test - php: '7.3' - env: CODECOVERAGE=0 DB=mariadb - addons: - mariadb: '10.2' - services: - - mysql - before_script: - - mysql -u root -e 'CREATE USER IF NOT EXISTS travis@localhost; GRANT ALL ON *.* TO travis@localhost;' - - stage: Test - php: '7.4' - env: CODECOVERAGE=0 DB=mariadb - addons: - mariadb: '10.2' - services: - - mysql - before_script: - - mysql -u root -e 'CREATE USER IF NOT EXISTS travis@localhost; GRANT ALL ON *.* TO travis@localhost;' - - stage: Code coverage - php: '7.3' - env: CODECOVERAGE=1 DB=sqlite - after_success: - - if [[ $CODECOVERAGE == 1 ]]; then bash <(curl -s https://codecov.io/bash); fi - -before_install: - - if [[ $CODECOVERAGE == 0 ]]; then phpenv config-rm xdebug.ini; fi; - - composer self-update - - php -i - - php -m - -install: - - composer install - - composer require zendframework/zend-ldap - -script: - - if [[ $CODECOVERAGE == 1 ]]; then TEST_WITH_BUNDLES=1 vendor/bin/phpunit tests/ --coverage-clover=coverage.xml; fi; - - if [[ $CODECOVERAGE == 0 ]]; then vendor/bin/phpunit tests/; fi; - - if [[ $DB == 'sqlite' ]]; then cp tests/.env.dist.sqlite .env; fi; - - if [[ $DB == "mysql" || $DB == "mariadb" ]]; then cp tests/.env.dist.mysql .env; fi; - - bin/console doctrine:database:create -n - - bin/console doctrine:migrations:migrate -n - - bin/console doctrine:migrations:migrate first -n - diff --git a/tests/.env.dist.mysql b/tests/.env.dist.mysql deleted file mode 100644 index ebc1363a..00000000 --- a/tests/.env.dist.mysql +++ /dev/null @@ -1,14 +0,0 @@ -MAILER_FROM=kimai@example.com - -###> symfony/framework-bundle ### -APP_ENV=dev -APP_SECRET=c88c14fa70a424e7a12d459b9dd9df7f -###< symfony/framework-bundle ### - -###> doctrine/doctrine-bundle ### -DATABASE_URL=mysql://travis@127.0.0.1:3306/kimai_migrations -###< doctrine/doctrine-bundle ### - -###> symfony/swiftmailer-bundle ### -MAILER_URL=null://localhost -###< symfony/swiftmailer-bundle ### diff --git a/tests/.env.dist.sqlite b/tests/.env.dist.sqlite deleted file mode 100644 index 608a07cc..00000000 --- a/tests/.env.dist.sqlite +++ /dev/null @@ -1,14 +0,0 @@ -MAILER_FROM=kimai@example.com - -###> symfony/framework-bundle ### -APP_ENV=dev -APP_SECRET=c88c14fa70a424e7a12d459b9dd9df7f -###< symfony/framework-bundle ### - -###> doctrine/doctrine-bundle ### -DATABASE_URL=sqlite:///%kernel.project_dir%/var/data/kimai_migrations.sqlite -###< doctrine/doctrine-bundle ### - -###> symfony/swiftmailer-bundle ### -MAILER_URL=null://localhost -###< symfony/swiftmailer-bundle ### diff --git a/tests/Invoice/Renderer/CsvRendererTest.php b/tests/Invoice/Renderer/CsvRendererTest.php index 28831295..9f5fa849 100644 --- a/tests/Invoice/Renderer/CsvRendererTest.php +++ b/tests/Invoice/Renderer/CsvRendererTest.php @@ -57,7 +57,8 @@ class CsvRendererTest extends TestCase $file = $response->getFile(); $this->assertEquals('text/csv', $response->headers->get('Content-Type')); - $this->assertEquals('attachment; filename=200204-customer_with_special_name.csv', $response->headers->get('Content-Disposition')); + $filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.csv'; + $this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition')); $this->assertTrue(file_exists($file->getRealPath())); $content = file_get_contents($file->getRealPath()); diff --git a/tests/Invoice/Renderer/DocxRendererTest.php b/tests/Invoice/Renderer/DocxRendererTest.php index 22d462c4..7914fe35 100644 --- a/tests/Invoice/Renderer/DocxRendererTest.php +++ b/tests/Invoice/Renderer/DocxRendererTest.php @@ -45,9 +45,10 @@ class DocxRendererTest extends TestCase /** @var BinaryFileResponse $response */ $response = $sut->render($document, $model); + $filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.docx'; $file = $response->getFile(); $this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', $response->headers->get('Content-Type')); - $this->assertEquals('attachment; filename=200204-customer_with_special_name.docx', $response->headers->get('Content-Disposition')); + $this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition')); $this->assertTrue(file_exists($file->getRealPath())); diff --git a/tests/Invoice/Renderer/OdsRendererTest.php b/tests/Invoice/Renderer/OdsRendererTest.php index 9b6c8362..bdc25b49 100644 --- a/tests/Invoice/Renderer/OdsRendererTest.php +++ b/tests/Invoice/Renderer/OdsRendererTest.php @@ -56,9 +56,10 @@ class OdsRendererTest extends TestCase /** @var BinaryFileResponse $response */ $response = $sut->render($document, $model); + $filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.ods'; $file = $response->getFile(); $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type')); - $this->assertEquals('attachment; filename=200204-customer_with_special_name.ods', $response->headers->get('Content-Disposition')); + $this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition')); $this->assertTrue(file_exists($file->getRealPath())); diff --git a/tests/Invoice/Renderer/TwigRendererTest.php b/tests/Invoice/Renderer/TwigRendererTest.php index d4a8e16d..e83a993a 100644 --- a/tests/Invoice/Renderer/TwigRendererTest.php +++ b/tests/Invoice/Renderer/TwigRendererTest.php @@ -62,7 +62,8 @@ class TwigRendererTest extends KernelTestCase $content = $response->getContent(); - $this->assertStringContainsString('200204-customer_with_special_name', $content); + $filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name'; + $this->assertStringContainsString('' . $filename . '', $content); $this->assertStringContainsString('', $content); diff --git a/tests/Invoice/Renderer/XlsxRendererTest.php b/tests/Invoice/Renderer/XlsxRendererTest.php index 0bb57b95..7fe21a72 100644 --- a/tests/Invoice/Renderer/XlsxRendererTest.php +++ b/tests/Invoice/Renderer/XlsxRendererTest.php @@ -56,9 +56,10 @@ class XlsxRendererTest extends TestCase /** @var BinaryFileResponse $response */ $response = $sut->render($document, $model); + $filename = $model->getNumberGenerator()->getInvoiceNumber() . '-customer_with_special_name.xlsx'; $file = $response->getFile(); $this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type')); - $this->assertEquals('attachment; filename=200204-customer_with_special_name.xlsx', $response->headers->get('Content-Disposition')); + $this->assertEquals('attachment; filename=' . $filename, $response->headers->get('Content-Disposition')); $this->assertTrue(file_exists($file->getRealPath()));