|
| 1 | +name: 'CI' |
| 2 | +on: # Build any PRs and main branch changes |
| 3 | + workflow_dispatch: # Allows to run the workflow manually from the Actions tab |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - opened |
| 7 | + - edited |
| 8 | + - synchronize |
| 9 | + push: |
| 10 | + branches: [ master ] |
| 11 | + schedule: |
| 12 | + - cron: '0 0 1 * *' # Every month |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: "CI-${{ github.head_ref }}" |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +env: |
| 19 | + # Cache params |
| 20 | + CACHE_VERSION: 2022061905 # To be able to create a new cache (YYYYMMDDXX) |
| 21 | + TEST_OUTPUT_STYLE: pretty |
| 22 | + COMPOSER_OPTIONS: --optimize-autoloader |
| 23 | + CODACY_CACHE_PATH: ~/.cache/codacy |
| 24 | + CODACY_BIN: ~/.cache/codacy/codacy.sh |
| 25 | + |
| 26 | +jobs: |
| 27 | + tests: |
| 28 | + name: UTs & FTs - Symfony ${{ matrix.symfony-version }} |
| 29 | + runs-on: ubuntu-latest |
| 30 | + env: |
| 31 | + COVERAGE_TYPE: none |
| 32 | + strategy: |
| 33 | + fail-fast: true |
| 34 | + max-parallel: 4 |
| 35 | + matrix: |
| 36 | + php-version: |
| 37 | + - '7.3' # Lowest supported |
| 38 | + - '7.4' # Latest php 7 version |
| 39 | + - '8.0' # First php 8 version |
| 40 | + - '8.1' # Latest supported |
| 41 | + symfony-version: |
| 42 | + - '4.4' # Lowest LTS |
| 43 | + - '5.4' # Latest LTS |
| 44 | + exclude: |
| 45 | + # Run all symfony version only on Lowest and Latest php versions, run it only one time for others |
| 46 | + - php-version: '8.0' |
| 47 | + symfony-version: '4.4' |
| 48 | + - php-version: '7.4' |
| 49 | + symfony-version: '5.4' |
| 50 | + steps: |
| 51 | + - name: Check out code |
| 52 | + uses: actions/checkout@v2 |
| 53 | + |
| 54 | + - name: Enable coverage |
| 55 | + if: ${{ matrix.php-version == '8.1' }} |
| 56 | + run: | |
| 57 | + echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV |
| 58 | + echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + - name: Setup PHP ${{ matrix.php-version }} |
| 61 | + uses: shivammathur/setup-php@v2 |
| 62 | + with: |
| 63 | + php-version: '${{ matrix.php-version }}' |
| 64 | + tools: composer |
| 65 | + coverage: ${{ env.COVERAGE_TYPE }} |
| 66 | + env: |
| 67 | + # Always use latest available patch for the version |
| 68 | + update: true |
| 69 | + |
| 70 | + - name: Setup cache |
| 71 | + id: cache |
| 72 | + uses: actions/cache@v2 |
| 73 | + with: |
| 74 | + path: | |
| 75 | + ~/.composer |
| 76 | + ./vendor |
| 77 | + ${{ env.CODACY_CACHE_PATH }} |
| 78 | + build/behat-code-coverage-cache |
| 79 | + # Clear the cache if composer json (as composer.lock is in the repo) has been updated |
| 80 | + key: ${{ env.CACHE_VERSION }}-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}-${{ hashFiles('composer.json') }} |
| 81 | + |
| 82 | + - name: Download codacy binary |
| 83 | + if: steps.cache.outputs.cache-hit != 'true' |
| 84 | + run: | |
| 85 | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ |
| 86 | + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ |
| 87 | + && chmod +x ${{ env.CODACY_BIN }} \ |
| 88 | + && ${{ env.CODACY_BIN }} download |
| 89 | +
|
| 90 | + - name: Build |
| 91 | + run: | |
| 92 | + composer require -W \ |
| 93 | + symfony/http-foundation:^${{ matrix.symfony-version }} \ |
| 94 | + symfony/http-kernel:^${{ matrix.symfony-version }} \ |
| 95 | + symfony/config:^${{ matrix.symfony-version }} \ |
| 96 | + symfony/dependency-injection:^${{ matrix.symfony-version }} \ |
| 97 | + symfony/event-dispatcher:^${{ matrix.symfony-version }} \ |
| 98 | + symfony/routing:^${{ matrix.symfony-version }} \ |
| 99 | + && make build |
| 100 | +
|
| 101 | + - name: Tests |
| 102 | + run: make test-unit && make test-functional |
| 103 | + |
| 104 | + # See the reports at https://codecov.io/gh/yoanm/symfony-jsonrpc-http-server |
| 105 | + - name: Upload unit tests coverage to codecov |
| 106 | + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} |
| 107 | + uses: codecov/codecov-action@v3 |
| 108 | + with: |
| 109 | + file: "build/coverage-phpunit/unit.clover" |
| 110 | + name: "unit-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}" |
| 111 | + flags: "unit-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}" |
| 112 | + fail_ci_if_error: true |
| 113 | + |
| 114 | + - name: Upload functional tests coverage to codecov |
| 115 | + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} |
| 116 | + uses: codecov/codecov-action@v3 |
| 117 | + with: |
| 118 | + files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover" |
| 119 | + name: "functional-tests-${{ matrix.php-version }}-${{ matrix.symfony-version }}" |
| 120 | + flags: "functional-tests,php-${{ matrix.php-version }},sf-${{ matrix.symfony-version }}" |
| 121 | + fail_ci_if_error: true |
| 122 | + |
| 123 | + - name: Upload coverages to Codacy |
| 124 | + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} |
| 125 | + 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 |
| 126 | + |
| 127 | + finalize-codacy-coverage-report: |
| 128 | + runs-on: ubuntu-latest |
| 129 | + name: Finalize Codacy coverage report |
| 130 | + needs: [ tests ] |
| 131 | + steps: |
| 132 | + - name: Setup cache |
| 133 | + id: cache |
| 134 | + uses: actions/cache@v2 |
| 135 | + with: |
| 136 | + path: | |
| 137 | + ${{ env.CODACY_CACHE_PATH }} |
| 138 | + key: ${{ env.CACHE_VERSION }}-codacy-final |
| 139 | + |
| 140 | + - name: Download codacy binary |
| 141 | + if: steps.cache.outputs.cache-hit != 'true' |
| 142 | + run: | |
| 143 | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ |
| 144 | + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ |
| 145 | + && chmod +x ${{ env.CODACY_BIN }} \ |
| 146 | + && ${{ env.CODACY_BIN }} download |
| 147 | +
|
| 148 | + - name: Finalize reporting |
| 149 | + run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }} |
0 commit comments