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