diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..4e5ff5b7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,319 @@ +name: Continuous integration + +on: + pull_request: null + push: + branches: + - main + - develop + +jobs: + lint: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: none + - run: composer install --no-interaction --prefer-dist + - run: composer cs + + static-analysis: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: none + - run: composer install --no-interaction --prefer-dist + - run: composer stan + + unit-tests: + runs-on: ubuntu-20.04 + continue-on-error: ${{ matrix.php-version == '8.0' }} + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: pcov + ini-values: pcov.directory=module + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: composer test:unit:ci + - uses: actions/upload-artifact@v2 + if: ${{ matrix.php-version == '7.4' }} + with: + name: coverage-unit + path: | + build/coverage-unit + build/coverage-unit.cov + + db-tests-sqlite: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: pcov + ini-values: pcov.directory=module + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: composer test:db:sqlite:ci + - uses: actions/upload-artifact@v2 + if: ${{ matrix.php-version == '7.4' }} + with: + name: coverage-db + path: | + build/coverage-db + build/coverage-db.cov + + db-tests-mysql: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: none + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: composer test:db:mysql + + db-tests-maria: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: none + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: composer test:db:maria + + db-tests-postgres: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: none + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: composer test:db:postgres + + db-tests-ms: + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install MSSQL ODBC + run: sudo ./data/infra/ci/install-ms-odbc.sh + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_ms + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9, pdo_sqlsrv-5.9.0beta2 + coverage: none + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - name: Create test database + run: docker-compose exec -T shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;" + - run: composer test:db:ms + + api-tests: + runs-on: ubuntu-20.04 + continue-on-error: ${{ matrix.php-version == '8.0' }} + strategy: + matrix: + php-version: ['7.4', '8.0'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: pcov + ini-values: pcov.directory=module + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - run: bin/test/run-api-tests.sh + - uses: actions/upload-artifact@v2 + if: ${{ matrix.php-version == '7.4' }} + with: + name: coverage-api + path: | + build/coverage-api + build/coverage-api.cov + + mutation-tests: + needs: + - unit-tests + - db-tests-sqlite + - api-tests + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start database server + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: swoole-4.5.9 + coverage: pcov + ini-values: pcov.directory=module + - if: ${{ matrix.php-version == '8.0' }} + run: composer install --no-interaction --prefer-dist --ignore-platform-req=php + - if: ${{ matrix.php-version != '8.0' }} + run: composer install --no-interaction --prefer-dist + - uses: actions/download-artifact@v2 + with: + path: build + - run: composer infect:ci + + upload-coverage: + needs: + - unit-tests + - db-tests-sqlite + - api-tests + runs-on: ubuntu-20.04 + strategy: + matrix: + php-version: ['7.4'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + coverage: pcov + ini-values: pcov.directory=module + - uses: actions/download-artifact@v2 + with: + path: build + - run: mv build/coverage-unit/coverage-unit.cov build/coverage-unit.cov + - run: mv build/coverage-db/coverage-db.cov build/coverage-db.cov + - run: mv build/coverage-api/coverage-api.cov build/coverage-api.cov + - run: wget https://phar.phpunit.de/phpcov-7.0.2.phar + - run: php phpcov-7.0.2.phar merge build --clover build/clover.xml + - run: wget https://scrutinizer-ci.com/ocular.phar + - run: php ocular.phar code-coverage:upload --format=php-clover build/clover.xml + + delete-artifacts: + needs: + - mutation-tests + - upload-coverage + runs-on: ubuntu-20.04 + steps: + - uses: geekyeggo/delete-artifact@v1 + with: + name: | + coverage-unit + coverage-db + coverage-api + + build-docker-image: + runs-on: ubuntu-20.04 + steps: + - name: Checkout code + uses: actions/checkout@v2 + - uses: marceloprado/has-changed-path@v1 + id: changed-dockerfile + with: + paths: ./Dockerfile + - if: ${{ steps.changed-dockerfile.outputs.changed == 'true' }} + run: docker build -t shlink-docker-image:temp . + - if: ${{ steps.changed-dockerfile.outputs.changed != 'true' }} + run: echo "Dockerfile didn't change. Skipped" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f3857e5d..00000000 --- a/.travis.yml +++ /dev/null @@ -1,56 +0,0 @@ -dist: bionic - -language: php - -branches: - only: - - /.*/ - -services: - - docker - -cache: - directories: - - $HOME/.composer/cache/files - -jobs: - fast_finish: true - allow_failures: - - php: '8.0' - include: - - name: 'CI - 8.0' - php: '8.0' - env: - - COMPOSER_FLAGS='--ignore-platform-req=php' - - name: 'CI - 7.4' - php: '7.4' - env: - - COMPOSER_FLAGS='' - -before_install: - - echo 'extension = apcu.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini - - phpenv config-rm xdebug.ini || return 0 - - sudo ./data/infra/ci/install-ms-odbc.sh - - docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_ms shlink_db shlink_db_postgres shlink_db_maria - - yes | pecl install pdo_sqlsrv-5.9.0beta2 swoole-4.5.9 pcov - -install: - - composer self-update - - composer install --no-interaction --prefer-dist $COMPOSER_FLAGS - -before_script: - - docker-compose exec shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;" - - mkdir build - - export DOCKERFILE_CHANGED=$(git diff ${TRAVIS_COMMIT_RANGE:-origin/main} --name-only | grep Dockerfile) - -script: - - composer ci - - bin/test/run-api-tests.sh - - if [[ ! -z "${DOCKERFILE_CHANGED}" && "${TRAVIS_PHP_VERSION}" == "7.4" ]]; then docker build -t shlink-docker-image:temp . ; fi - -after_success: - - rm -f build/clover.xml - - wget https://phar.phpunit.de/phpcov-7.0.2.phar - - php phpcov-7.0.2.phar merge build --clover build/clover.xml - - wget https://scrutinizer-ci.com/ocular.phar - - php ocular.phar code-coverage:upload --format=php-clover build/clover.xml diff --git a/README.md b/README.md index 1f6d2149..255c719e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ![Shlink](https://raw.githubusercontent.com/shlinkio/shlink.io/main/public/images/shlink-hero.png) -[![Build Status](https://img.shields.io/travis/com/shlinkio/shlink.svg?style=flat-square)](https://travis-ci.com/shlinkio/shlink) +[![Build Status](https://img.shields.io/github/workflow/status/shlinkio/shlink/Continuous%20integration/main?logo=github&style=flat-square)](https://github.com/shlinkio/shlink/actions?query=workflow%3A%22Continuous+integration%22) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/shlinkio/shlink.svg?style=flat-square)](https://scrutinizer-ci.com/g/shlinkio/shlink/) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/shlinkio/shlink.svg?style=flat-square)](https://scrutinizer-ci.com/g/shlinkio/shlink/) [![Latest Stable Version](https://img.shields.io/github/release/shlinkio/shlink.svg?style=flat-square)](https://packagist.org/packages/shlinkio/shlink) -[![Docker pulls](https://img.shields.io/docker/pulls/shlinkio/shlink.svg?style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) +[![Docker pulls](https://img.shields.io/docker/pulls/shlinkio/shlink.svg?logo=docker&style=flat-square)](https://hub.docker.com/r/shlinkio/shlink/) [![License](https://img.shields.io/github/license/shlinkio/shlink.svg?style=flat-square)](https://github.com/shlinkio/shlink/blob/main/LICENSE) [![Paypal donate](https://img.shields.io/badge/Donate-paypal-blue.svg?style=flat-square&logo=paypal&colorA=aaaaaa)](https://slnk.to/donate) diff --git a/composer.json b/composer.json index b89d3e63..19c4097e 100644 --- a/composer.json +++ b/composer.json @@ -115,7 +115,8 @@ ], "test:ci": [ "@test:unit:ci", - "@test:db" + "@test:db", + "@test:api" ], "test:unit": "@php vendor/bin/phpunit --order-by=random --colors=always --coverage-php build/coverage-unit.cov --testdox", "test:unit:ci": "@test:unit --coverage-xml=build/coverage-unit/coverage-xml --log-junit=build/coverage-unit/junit.xml", diff --git a/config/test/test_config.global.php b/config/test/test_config.global.php index 6b3c6612..3608257e 100644 --- a/config/test/test_config.global.php +++ b/config/test/test_config.global.php @@ -36,7 +36,7 @@ if ($isApiTest) { $buildDbConnection = function (): array { $driver = env('DB_DRIVER', 'sqlite'); - $isCi = env('TRAVIS', false); + $isCi = env('CI', false); $getMysqlHost = fn (string $driver) => sprintf('shlink_db%s', $driver === 'mysql' ? '' : '_maria'); $getCiMysqlPort = fn (string $driver) => $driver === 'mysql' ? '3307' : '3308'; diff --git a/data/infra/ci/install-ms-odbc.sh b/data/infra/ci/install-ms-odbc.sh index 8cd60580..1efdf8a3 100755 --- a/data/infra/ci/install-ms-odbc.sh +++ b/data/infra/ci/install-ms-odbc.sh @@ -3,7 +3,7 @@ set -ex curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - -curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list +curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list > /etc/apt/sources.list.d/mssql-release.list apt-get update ACCEPT_EULA=Y apt-get install msodbcsql17 apt-get install unixodbc-dev