diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 00000000..3712e845 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,176 @@ +name: 'CI' +on: # Build any PRs and main branch changes + workflow_dispatch: # Allows to run the workflow manually from the Actions tab + pull_request: + types: + - opened + - edited + - synchronize + push: + branches: [ master ] + schedule: + - cron: '0 0 1 * *' # Every month + +concurrency: + group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}" + cancel-in-progress: true + +env: + # Cache params + CACHE_VERSION: 2022061905 # To be able to create a new cache (YYYYMMDDXX) + TEST_OUTPUT_STYLE: pretty + COMPOSER_OPTIONS: --optimize-autoloader + CODACY_CACHE_PATH: ~/.cache/codacy + CODACY_BIN: ~/.cache/codacy/codacy.sh + + +#permissions: +# actions: write # Required to be able to trigger sub CI workflows + +jobs: + tests: + name: UTs & FTs - PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + env: + COVERAGE_TYPE: none + strategy: + fail-fast: true + max-parallel: 4 + matrix: + php-version: + - '8.2' # Latest supported + - '8.1' + - '8.0' # First php 8 version + - '7.4' # Latest php 7 version + - '7.3' + - '7.2' + - '7.1' + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Enable coverage + if: ${{ matrix.php-version == '8.1' }} + run: | + echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV + echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV + + - name: Setup PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: '${{ matrix.php-version }}' + tools: composer + coverage: ${{ env.COVERAGE_TYPE }} + env: + # Always use latest available patch for the version + update: true + + - name: Setup cache + id: cache + uses: actions/cache@v2 + with: + path: | + ~/.composer + ./vendor + ${{ env.CODACY_CACHE_PATH }} + build/behat-code-coverage-cache + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: ${{ env.CACHE_VERSION }}-tests-${{ matrix.php-version }}-${{ hashFiles('composer.json') }} + + - name: Download codacy binary + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ + && chmod +x ${{ env.CODACY_BIN }} \ + && ${{ env.CODACY_BIN }} download + + - name: Build + run: | + make build + + - name: Tests + run: make test-technical && make test-functional + + # See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-server-sdk + - name: Upload unit tests coverage to codecov + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + uses: codecov/codecov-action@v3 + with: + file: "build/coverage-phpunit/unit.clover" + name: "unit-tests-${{ matrix.php-version }}" + flags: "unit-tests,php-${{ matrix.php-version }}" + fail_ci_if_error: true + + - name: Upload functional tests coverage to codecov + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + uses: codecov/codecov-action@v3 + with: + files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover" + name: "functional-tests-${{ matrix.php-version }}" + flags: "functional-tests,php-${{ matrix.php-version }}" + fail_ci_if_error: true + + - name: Upload coverages to Codacy + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} + run: ${{ env.CODACY_BIN }} report -r build/coverage-phpunit/unit.clover -r build/coverage-behat/clover.xml -r build/coverage-phpunit/functional.clover -t ${{ secrets.CODACY_PROJECT_TOKEN }} --partial + + static-checks: + name: Static checks + runs-on: ubuntu-latest + needs: [ tests ] + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP 8.2 + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 # Latest supported + tools: composer + coverage: none + env: + # Always use latest available patch for the version + update: true + + - name: Setup cache + id: cache + uses: actions/cache@v2 + with: + path: | + ~/.composer + # Clear the cache if composer json (as composer.lock is in the repo) has been updated + key: ${{ env.CACHE_VERSION }}-tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }} + + - name: Build + run: make build + + - name: ComposerRequireChecker + uses: docker://webfactory/composer-require-checker:3.2.0 + + - name: Dependencies check + if: ${{ github.event_name == 'pull_request' }} + uses: actions/dependency-review-action@v1 + + finalize-codacy-coverage-report: + runs-on: ubuntu-latest + name: Finalize Codacy coverage report + needs: [ tests ] + steps: + - name: Setup cache + id: cache + uses: actions/cache@v2 + with: + path: | + ${{ env.CODACY_CACHE_PATH }} + key: ${{ env.CACHE_VERSION }}-codacy-final + + - name: Download codacy binary + if: steps.cache.outputs.cache-hit != 'true' + run: | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ + && chmod +x ${{ env.CODACY_BIN }} \ + && ${{ env.CODACY_BIN }} download + + - name: Finalize reporting + run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 33bb2175..00000000 --- a/.travis.yml +++ /dev/null @@ -1,39 +0,0 @@ -language: php - -php: - - '7.1' - - '7.2' - - '7.3' - - '7.4' - -env: - global: - CI: 'true' - TEST_OUTPUT_STYLE: 'pretty' - PHPCS_REPORT_STYLE: 'full' - COMPOSER_OPTIONS: '--optimize-autoloader' - -sudo: false - -matrix: - fast_finish: true - -before_install: - # remove xdebug to speed up build - - phpenv config-rm xdebug.ini || true - -install: - - make build -script: - - make test-technical - - make test-functional - -cache: - directories: - - $HOME/.composer - - vendor - -branches: - except: - - /.*\-dev$/ - - /.*\-patch(\-\d+)?$/ diff --git a/README.md b/README.md index 738f44aa..83b71f83 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Scrutinizer Build Status](https://img.shields.io/scrutinizer/build/g/yoanm/php-jsonrpc-server-sdk.svg?label=Scrutinizer&logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-server-sdk/build-status/master) [![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/yoanm/php-jsonrpc-server-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-server-sdk/?branch=master) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/yoanm/php-jsonrpc-server-sdk/master.svg?logo=scrutinizer)](https://scrutinizer-ci.com/g/yoanm/php-jsonrpc-server-sdk/?branch=master) -[![Travis Build Status](https://img.shields.io/travis/yoanm/php-jsonrpc-server-sdk/master.svg?label=Travis&logo=travis)](https://travis-ci.org/yoanm/php-jsonrpc-server-sdk) [![Travis PHP versions](https://img.shields.io/travis/php-v/yoanm/php-jsonrpc-server-sdk.svg?logo=travis)](https://travis-ci.org/yoanm/php-jsonrpc-server-sdk) +[![CI](https://github.com/yoanm/php-jsonrpc-server-sdk/actions/workflows/CI.yml/badge.svg?branch=master)](https://github.com/yoanm/sphp-jsonrpc-server-sdk/actions/workflows/CI.yml) [![Latest Stable Version](https://img.shields.io/packagist/v/yoanm/jsonrpc-server-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-server-sdk) [![Packagist PHP version](https://img.shields.io/packagist/php-v/yoanm/jsonrpc-server-sdk.svg)](https://packagist.org/packages/yoanm/jsonrpc-server-sdk)