|
| 1 | +--- |
| 2 | + |
| 3 | +name: CI |
| 4 | + |
| 5 | +on: # yamllint disable-line rule:truthy |
| 6 | + push: |
| 7 | + branches: ['**'] |
| 8 | + paths-ignore: |
| 9 | + - '**.md' |
| 10 | + pull_request: |
| 11 | + branches: [master, release-*] |
| 12 | + paths-ignore: |
| 13 | + - '**.md' |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +jobs: |
| 17 | + phplinter: |
| 18 | + name: 'PHP-Linter' |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + php-version: ['8.3', '8.4', '8.5'] |
| 23 | + |
| 24 | + uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/[email protected] |
| 25 | + with: |
| 26 | + php-version: ${{ matrix.php-version }} |
| 27 | + |
| 28 | + linter: |
| 29 | + name: 'Linter' |
| 30 | + strategy: |
| 31 | + fail-fast: false |
| 32 | + |
| 33 | + uses: simplesamlphp/simplesamlphp-test-framework/.github/workflows/[email protected] |
| 34 | + with: |
| 35 | + enable_eslinter: false |
| 36 | + enable_jsonlinter: true |
| 37 | + enable_stylelinter: false |
| 38 | + enable_yamllinter: true |
| 39 | + |
| 40 | + unit-tests-linux: |
| 41 | + name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" |
| 42 | + runs-on: ${{ matrix.operating-system }} |
| 43 | + needs: [phplinter, linter] |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: |
| 47 | + operating-system: [ubuntu-latest] |
| 48 | + php-versions: ['8.3', '8.4', '8.5'] |
| 49 | + |
| 50 | + steps: |
| 51 | + - name: Setup PHP, with composer and extensions |
| 52 | + # https://github.com/shivammathur/setup-php |
| 53 | + uses: shivammathur/setup-php@v2 |
| 54 | + with: |
| 55 | + php-version: ${{ matrix.php-versions }} |
| 56 | + extensions: ctype, date, dom, intl, pcre, sodium, spl, xml |
| 57 | + tools: composer |
| 58 | + ini-values: error_reporting=E_ALL |
| 59 | + coverage: pcov |
| 60 | + |
| 61 | + - name: Setup problem matchers for PHP |
| 62 | + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" |
| 63 | + |
| 64 | + - name: Setup problem matchers for PHPUnit |
| 65 | + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" |
| 66 | + |
| 67 | + - name: Set git to use LF |
| 68 | + run: | |
| 69 | + git config --global core.autocrlf false |
| 70 | + git config --global core.eol lf |
| 71 | +
|
| 72 | + - uses: actions/checkout@v6 |
| 73 | + |
| 74 | + - name: Get composer cache directory |
| 75 | + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV" |
| 76 | + |
| 77 | + - name: Cache composer dependencies |
| 78 | + uses: actions/cache@v5 |
| 79 | + with: |
| 80 | + path: ${{ env.COMPOSER_CACHE }} |
| 81 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 82 | + restore-keys: ${{ runner.os }}-composer- |
| 83 | + |
| 84 | + - name: Install Composer dependencies |
| 85 | + run: composer install --no-progress --prefer-dist --optimize-autoloader |
| 86 | + |
| 87 | + - name: Run unit tests with coverage |
| 88 | + if: ${{ matrix.php-versions == '8.5' }} |
| 89 | + run: vendor/bin/phpunit |
| 90 | + |
| 91 | + - name: Run unit tests (no coverage) |
| 92 | + if: ${{ matrix.php-versions != '8.5' }} |
| 93 | + run: vendor/bin/phpunit --no-coverage |
| 94 | + |
| 95 | + - name: Save coverage data |
| 96 | + if: ${{ matrix.php-versions == '8.5' }} |
| 97 | + uses: actions/upload-artifact@v6 |
| 98 | + with: |
| 99 | + name: coverage-data |
| 100 | + path: ${{ github.workspace }}/build |
| 101 | + |
| 102 | + unit-tests-windows: |
| 103 | + name: "Unit tests, PHP ${{ matrix.php-versions }}, ${{ matrix.operating-system }}" |
| 104 | + runs-on: ${{ matrix.operating-system }} |
| 105 | + needs: [phplinter, linter] |
| 106 | + strategy: |
| 107 | + fail-fast: true |
| 108 | + matrix: |
| 109 | + operating-system: [windows-latest] |
| 110 | + php-versions: ['8.3', '8.4', '8.5'] |
| 111 | + |
| 112 | + steps: |
| 113 | + - name: Setup PHP, with composer and extensions |
| 114 | + # https://github.com/shivammathur/setup-php |
| 115 | + uses: shivammathur/setup-php@v2 |
| 116 | + with: |
| 117 | + php-version: ${{ matrix.php-versions }} |
| 118 | + extensions: ctype, date, dom, intl, pcre, sodium, spl, xml |
| 119 | + tools: composer |
| 120 | + ini-values: error_reporting=E_ALL |
| 121 | + coverage: none |
| 122 | + |
| 123 | + - name: Setup problem matchers for PHP |
| 124 | + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" |
| 125 | + |
| 126 | + - name: Setup problem matchers for PHPUnit |
| 127 | + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" |
| 128 | + |
| 129 | + - name: Set git to use LF |
| 130 | + run: | |
| 131 | + git config --global core.autocrlf false |
| 132 | + git config --global core.eol lf |
| 133 | +
|
| 134 | + - uses: actions/checkout@v6 |
| 135 | + |
| 136 | + - name: Get composer cache directory |
| 137 | + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$env:GITHUB_ENV" |
| 138 | + |
| 139 | + - name: Cache composer dependencies |
| 140 | + uses: actions/cache@v5 |
| 141 | + with: |
| 142 | + path: ${{ env.COMPOSER_CACHE }} |
| 143 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 144 | + restore-keys: ${{ runner.os }}-composer- |
| 145 | + |
| 146 | + - name: Install Composer dependencies |
| 147 | + run: composer install --no-progress --prefer-dist --optimize-autoloader |
| 148 | + |
| 149 | + - name: Run unit tests |
| 150 | + run: vendor/bin/phpunit --no-coverage |
| 151 | + |
| 152 | + security: |
| 153 | + name: Security checks |
| 154 | + needs: [unit-tests-linux] |
| 155 | + runs-on: [ubuntu-latest] |
| 156 | + |
| 157 | + steps: |
| 158 | + - name: Setup PHP, with composer and extensions |
| 159 | + # https://github.com/shivammathur/setup-php |
| 160 | + uses: shivammathur/setup-php@v2 |
| 161 | + with: |
| 162 | + # Should be the lowest supported version |
| 163 | + php-version: '8.3' |
| 164 | + extensions: ctype, date, dom, intl, pcre, sodium, spl, xml |
| 165 | + tools: composer |
| 166 | + coverage: none |
| 167 | + |
| 168 | + - name: Setup problem matchers for PHP |
| 169 | + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" |
| 170 | + |
| 171 | + - uses: actions/checkout@v6 |
| 172 | + |
| 173 | + - name: Get composer cache directory |
| 174 | + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV" |
| 175 | + |
| 176 | + - name: Cache composer dependencies |
| 177 | + uses: actions/cache@v5 |
| 178 | + with: |
| 179 | + path: ${{ env.COMPOSER_CACHE }} |
| 180 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 181 | + restore-keys: ${{ runner.os }}-composer- |
| 182 | + |
| 183 | + - name: Install Composer dependencies |
| 184 | + run: composer install --no-progress --prefer-dist --optimize-autoloader |
| 185 | + |
| 186 | + - name: Security check for locked dependencies |
| 187 | + run: composer audit |
| 188 | + |
| 189 | + - name: Update Composer dependencies |
| 190 | + run: composer update --no-progress --prefer-dist --optimize-autoloader |
| 191 | + |
| 192 | + - name: Security check for updated dependencies |
| 193 | + run: composer audit |
| 194 | + |
| 195 | + quality: |
| 196 | + name: Quality control |
| 197 | + needs: [unit-tests-linux] |
| 198 | + runs-on: [ubuntu-latest] |
| 199 | + |
| 200 | + steps: |
| 201 | + - name: Setup PHP, with composer and extensions |
| 202 | + id: setup-php |
| 203 | + # https://github.com/shivammathur/setup-php |
| 204 | + uses: shivammathur/setup-php@v2 |
| 205 | + with: |
| 206 | + # Should be the higest supported version, so we can use the newest tools |
| 207 | + php-version: '8.5' |
| 208 | + tools: composer, composer-require-checker, composer-unused, phpcs |
| 209 | + extensions: ctype, date, dom, pcre, spl, xml |
| 210 | + |
| 211 | + - name: Setup problem matchers for PHP |
| 212 | + run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" |
| 213 | + |
| 214 | + - uses: actions/checkout@v6 |
| 215 | + |
| 216 | + - name: Get composer cache directory |
| 217 | + run: echo COMPOSER_CACHE="$(composer config cache-files-dir)" >> "$GITHUB_ENV" |
| 218 | + |
| 219 | + - name: Cache composer dependencies |
| 220 | + uses: actions/cache@v5 |
| 221 | + with: |
| 222 | + path: ${{ env.COMPOSER_CACHE }} |
| 223 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 224 | + restore-keys: ${{ runner.os }}-composer- |
| 225 | + |
| 226 | + - name: Validate composer.json and composer.lock |
| 227 | + run: composer validate |
| 228 | + |
| 229 | + - name: Install Composer dependencies |
| 230 | + run: composer install --no-progress --prefer-dist --optimize-autoloader |
| 231 | + |
| 232 | + - name: Check code for hard dependencies missing in composer.json |
| 233 | + run: composer-require-checker check composer.json |
| 234 | + |
| 235 | + - name: Check code for unused dependencies in composer.json |
| 236 | + run: composer-unused |
| 237 | + |
| 238 | + - name: PHP Code Sniffer |
| 239 | + run: vendor/bin/phpcs |
| 240 | + |
| 241 | + - name: PHPStan |
| 242 | + run: | |
| 243 | + vendor/bin/phpstan analyze -c phpstan.neon |
| 244 | +
|
| 245 | + - name: PHPStan (testsuite) |
| 246 | + run: | |
| 247 | + vendor/bin/phpstan analyze -c phpstan-dev.neon |
| 248 | +
|
| 249 | + coverage: |
| 250 | + name: Code coverage |
| 251 | + runs-on: [ubuntu-latest] |
| 252 | + needs: [unit-tests-linux] |
| 253 | + |
| 254 | + steps: |
| 255 | + - uses: actions/checkout@v6 |
| 256 | + |
| 257 | + - uses: actions/download-artifact@v7 |
| 258 | + with: |
| 259 | + name: coverage-data |
| 260 | + path: ${{ github.workspace }}/build |
| 261 | + |
| 262 | + - name: Codecov |
| 263 | + uses: codecov/codecov-action@v5 |
| 264 | + with: |
| 265 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 266 | + fail_ci_if_error: true |
| 267 | + verbose: true |
| 268 | + |
| 269 | + cleanup: |
| 270 | + name: Cleanup artifacts |
| 271 | + needs: [unit-tests-linux, coverage] |
| 272 | + runs-on: [ubuntu-latest] |
| 273 | + if: | |
| 274 | + always() && |
| 275 | + needs.coverage.result == 'success' || |
| 276 | + (needs.unit-tests-linux.result == 'success' && needs.coverage.result == 'skipped') |
| 277 | +
|
| 278 | + steps: |
| 279 | + - uses: geekyeggo/delete-artifact@v5 |
| 280 | + with: |
| 281 | + name: coverage-data |
0 commit comments