|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "master" ] |
| 8 | + schedule: |
| 9 | + - cron: "0 0 * * 0" # Runs at 00:00 UTC on Sun. |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + ######################### |
| 16 | + # Run PHPUnit testsuite # |
| 17 | + ######################### |
| 18 | + testsuite: |
| 19 | + |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + strategy: |
| 23 | + fail-fast: false |
| 24 | + matrix: |
| 25 | + php-version: ['7.4', '8.0', '8.1', '8.2'] |
| 26 | + db-type: [sqlite, mysql] |
| 27 | + prefer-lowest: ['', 'prefer-lowest'] |
| 28 | + |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v3 |
| 31 | + |
| 32 | + - name: Setup MySQL 8 |
| 33 | + if: matrix.db-type == 'mysql' |
| 34 | + run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:8 --default-authentication-plugin=mysql_native_password --disable-log-bin |
| 35 | + |
| 36 | + - name: Validate composer.json and composer.lock |
| 37 | + run: composer validate --strict |
| 38 | + |
| 39 | + - name: Get composer cache directory |
| 40 | + id: composer-cache |
| 41 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 42 | + |
| 43 | + - name: Get date part for cache key |
| 44 | + id: key-date |
| 45 | + run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT |
| 46 | + |
| 47 | + - name: Cache composer dependencies |
| 48 | + uses: actions/cache@v3 |
| 49 | + with: |
| 50 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 51 | + key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} |
| 52 | + |
| 53 | + - name: Install composer dependencies |
| 54 | + run: | |
| 55 | + if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then |
| 56 | + composer update --prefer-lowest --prefer-stable |
| 57 | + elif ${{ matrix.php-version == '8.2' }}; then |
| 58 | + composer update --ignore-platform-req=php |
| 59 | + else |
| 60 | + composer update |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Wait for MySQL |
| 64 | + if: matrix.db-type == 'mysql' |
| 65 | + run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done; |
| 66 | + |
| 67 | + - name: Run PHPUnit testsuite |
| 68 | + run: | |
| 69 | + if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi |
| 70 | + if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp'; fi |
| 71 | + vendor/bin/phpunit --stderr; |
| 72 | +
|
| 73 | + ############## |
| 74 | + # Code style # |
| 75 | + ############## |
| 76 | + cs: |
| 77 | + |
| 78 | + runs-on: ubuntu-latest |
| 79 | + |
| 80 | + strategy: |
| 81 | + fail-fast: false |
| 82 | + matrix: |
| 83 | + php-version: ['8.0'] |
| 84 | + |
| 85 | + steps: |
| 86 | + - uses: actions/checkout@v3 |
| 87 | + |
| 88 | + - name: Validate composer.json and composer.lock |
| 89 | + run: composer validate --strict |
| 90 | + |
| 91 | + - name: Get composer cache directory |
| 92 | + id: composer-cache |
| 93 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 94 | + |
| 95 | + - name: Get date part for cache key |
| 96 | + id: key-date |
| 97 | + run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT |
| 98 | + |
| 99 | + - name: Cache composer dependencies |
| 100 | + uses: actions/cache@v3 |
| 101 | + with: |
| 102 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 103 | + key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} |
| 104 | + |
| 105 | + - name: Install composer dependencies |
| 106 | + run: | |
| 107 | + composer update |
| 108 | +
|
| 109 | + - name: Run CS check |
| 110 | + run: | |
| 111 | + vendor/bin/phpcs -n -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; |
0 commit comments