|
| 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: "${{ github.workflow }}-${{ github.head_ref || github.ref }}" |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +env: |
| 19 | + TEST_OUTPUT_STYLE: pretty |
| 20 | + COMPOSER_OPTIONS: --optimize-autoloader |
| 21 | + CODACY_CACHE_PATH: ~/.cache/codacy |
| 22 | + CODACY_BIN: ~/.cache/codacy/codacy.sh |
| 23 | + |
| 24 | +jobs: |
| 25 | + tests: |
| 26 | + name: UTs & FTs - PHP ${{ matrix.php-version }} |
| 27 | + runs-on: ubuntu-latest |
| 28 | + env: |
| 29 | + COVERAGE_TYPE: none |
| 30 | + strategy: |
| 31 | + fail-fast: true |
| 32 | + max-parallel: 4 |
| 33 | + matrix: |
| 34 | + include: |
| 35 | + # Bare minimum => Lowest versions allowed by composer config |
| 36 | + - php-version: '8.0' |
| 37 | + composer-flag: --prefer-lowest |
| 38 | + # Up to date versions => Latest versions allowed by composer config |
| 39 | + - php-version: '8.2' |
| 40 | + steps: |
| 41 | + - name: Check out code |
| 42 | + uses: actions/checkout@v3 |
| 43 | + |
| 44 | + - name: Enable coverage |
| 45 | + if: ${{ matrix.php-version == '8.2' }} |
| 46 | + run: | |
| 47 | + echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV |
| 48 | + echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV |
| 49 | +
|
| 50 | + - name: Setup PHP ${{ matrix.php-version }} |
| 51 | + uses: shivammathur/setup-php@v2 |
| 52 | + with: |
| 53 | + php-version: '${{ matrix.php-version }}' |
| 54 | + tools: composer |
| 55 | + coverage: ${{ env.COVERAGE_TYPE }} |
| 56 | + env: |
| 57 | + # Always use latest available patch for the version |
| 58 | + update: true |
| 59 | + |
| 60 | + - name: Setup cache |
| 61 | + id: cache |
| 62 | + uses: actions/cache@v3 |
| 63 | + with: |
| 64 | + path: | |
| 65 | + ~/.composer |
| 66 | + ./vendor |
| 67 | + ${{ env.CODACY_CACHE_PATH }} |
| 68 | + # Clear the cache if composer json (as composer.lock is in the repo) has been updated |
| 69 | + key: tests-${{ matrix.php-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }} |
| 70 | + |
| 71 | + - name: Download codacy binary |
| 72 | + if: steps.cache.outputs.cache-hit != 'true' |
| 73 | + run: | |
| 74 | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ |
| 75 | + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ |
| 76 | + && chmod +x ${{ env.CODACY_BIN }} \ |
| 77 | + && ${{ env.CODACY_BIN }} download |
| 78 | +
|
| 79 | + - name: Build |
| 80 | + run: | |
| 81 | + composer update ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \ |
| 82 | + && make build |
| 83 | +
|
| 84 | + - name: Tests |
| 85 | + run: make test-unit && make test-functional |
| 86 | + |
| 87 | + # Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false |
| 88 | + # And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context |
| 89 | + - name: Upload coverages to Codacy |
| 90 | + if: ${{ (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-http-server-openapi-doc-sdk') && env.COVERAGE_TYPE == 'xdebug' }} |
| 91 | + 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 |
| 92 | + |
| 93 | + # See the reports at https://codecov.io/gh/yoanm/php-jsonrpc-http-server-openapi-doc-sdk |
| 94 | + - name: Upload unit tests coverage to codecov |
| 95 | + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} |
| 96 | + uses: codecov/codecov-action@v3 |
| 97 | + with: |
| 98 | + file: "build/coverage-phpunit/unit.clover" |
| 99 | + name: "unit-tests-${{ matrix.php-version }}" |
| 100 | + flags: "unit-tests,php-${{ matrix.php-version }}" |
| 101 | + fail_ci_if_error: true |
| 102 | + move_coverage_to_trash: false |
| 103 | + verbose: ${{ runner.debug == '1' }} |
| 104 | + |
| 105 | + - name: Upload functional tests coverage to codecov |
| 106 | + if: ${{ env.COVERAGE_TYPE == 'xdebug' }} |
| 107 | + uses: codecov/codecov-action@v3 |
| 108 | + with: |
| 109 | + files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover" |
| 110 | + name: "functional-tests-${{ matrix.php-version }}" |
| 111 | + flags: "functional-tests,php-${{ matrix.php-version }}" |
| 112 | + fail_ci_if_error: true |
| 113 | + move_coverage_to_trash: false |
| 114 | + verbose: ${{ runner.debug == '1' }} |
| 115 | + |
| 116 | + static-checks: |
| 117 | + name: Static checks |
| 118 | + runs-on: ubuntu-latest |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v3 |
| 121 | + |
| 122 | + - name: Setup PHP 8.2 |
| 123 | + uses: shivammathur/setup-php@v2 |
| 124 | + with: |
| 125 | + php-version: 8.2 # Latest supported |
| 126 | + tools: composer |
| 127 | + coverage: none |
| 128 | + env: |
| 129 | + # Always use latest available patch for the version |
| 130 | + update: true |
| 131 | + |
| 132 | + - name: Setup cache |
| 133 | + id: cache |
| 134 | + uses: actions/cache@v3 |
| 135 | + with: |
| 136 | + path: | |
| 137 | + ~/.composer |
| 138 | + # Clear the cache if composer json (as composer.lock is in the repo) has been updated |
| 139 | + key: tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }} |
| 140 | + |
| 141 | + - name: Build |
| 142 | + run: make build |
| 143 | + |
| 144 | + - name: ComposerRequireChecker |
| 145 | + uses: docker://webfactory/composer-require-checker:4.5.0 |
| 146 | + |
| 147 | + - name: Dependencies check |
| 148 | + if: ${{ github.event_name == 'pull_request' }} |
| 149 | + uses: actions/dependency-review-action@v1 |
| 150 | + |
| 151 | + finalize-codacy-coverage-report: |
| 152 | + runs-on: ubuntu-latest |
| 153 | + name: Finalize Codacy coverage report |
| 154 | + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'yoanm/php-jsonrpc-http-server-openapi-doc-sdk' }} |
| 155 | + needs: [ tests ] |
| 156 | + steps: |
| 157 | + - name: Setup cache |
| 158 | + id: cache |
| 159 | + uses: actions/cache@v3 |
| 160 | + with: |
| 161 | + path: | |
| 162 | + ${{ env.CODACY_CACHE_PATH }} |
| 163 | + key: codacy-final |
| 164 | + |
| 165 | + - name: Download codacy binary |
| 166 | + if: steps.cache.outputs.cache-hit != 'true' |
| 167 | + run: | |
| 168 | + mkdir -p ${{ env.CODACY_CACHE_PATH }} \ |
| 169 | + && curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \ |
| 170 | + && chmod +x ${{ env.CODACY_BIN }} \ |
| 171 | + && ${{ env.CODACY_BIN }} download |
| 172 | +
|
| 173 | + - name: Finalize reporting |
| 174 | + run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }} |
| 175 | + |
| 176 | + nightly-tests: |
| 177 | + name: Nightly - PHP ${{ matrix.php-version }} |
| 178 | + runs-on: ubuntu-latest |
| 179 | + env: |
| 180 | + COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+' |
| 181 | + continue-on-error: true |
| 182 | + needs: [ static-checks, tests ] |
| 183 | + strategy: |
| 184 | + fail-fast: false |
| 185 | + max-parallel: 4 |
| 186 | + matrix: |
| 187 | + php-version: |
| 188 | + - '8.3' # Current php dev version |
| 189 | + |
| 190 | + steps: |
| 191 | + - name: Check out code |
| 192 | + uses: actions/checkout@v3 |
| 193 | + |
| 194 | + - name: Setup PHP ${{ matrix.php-version }} |
| 195 | + uses: shivammathur/setup-php@v2 |
| 196 | + with: |
| 197 | + php-version: '${{ matrix.php-version }}' |
| 198 | + tools: composer |
| 199 | + coverage: none |
| 200 | + env: |
| 201 | + # Always use latest available patch for the version |
| 202 | + update: true |
| 203 | + |
| 204 | + - name: Setup cache |
| 205 | + id: cache |
| 206 | + uses: actions/cache@v3 |
| 207 | + with: |
| 208 | + path: | |
| 209 | + ~/.composer |
| 210 | + ./vendor |
| 211 | + # Clear the cache if composer json (as composer.lock is in the repo) has been updated |
| 212 | + key: tests-${{ matrix.php-version }}-${{ hashFiles('composer.json') }} |
| 213 | + |
| 214 | + - name: Build |
| 215 | + run: | |
| 216 | + composer update ${{ env.COMPOSER_OPTIONS }} \ |
| 217 | + && make build |
| 218 | +
|
| 219 | + - name: Test |
| 220 | + run: make test-unit && make test-functional |
0 commit comments