|
| 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-versions: ['7.4', '8.0', '8.1', '8.2'] |
| 26 | + db-type: [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: test-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} |
| 52 | + |
| 53 | + - name: Setup PHP |
| 54 | + uses: shivammathur/setup-php@v2 |
| 55 | + with: |
| 56 | + php-version: ${{ matrix.php-versions }} |
| 57 | + extensions: mbstring, intl |
| 58 | + |
| 59 | + - name: Install composer dependencies |
| 60 | + run: | |
| 61 | + if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then |
| 62 | + composer update --prefer-lowest --prefer-stable |
| 63 | + elif ${{ matrix.php-version == '8.2' }}; then |
| 64 | + composer update --ignore-platform-req=php |
| 65 | + else |
| 66 | + composer update |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Wait for MySQL |
| 70 | + if: matrix.db-type == 'mysql' |
| 71 | + run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done; |
| 72 | + |
| 73 | + - name: Run PHPUnit testsuite |
| 74 | + run: | |
| 75 | + if [[ ${{ matrix.db-type }} == 'mysql' ]]; then |
| 76 | + export DB_URL='mysql://root:[email protected]/cakephp'; |
| 77 | + mysql -h 127.0.0.1 -u root -proot cakephp < ./tests/Schema/articles.sql |
| 78 | + fi |
| 79 | + vendor/bin/phpunit --stderr; |
| 80 | +
|
| 81 | + ############## |
| 82 | + # Code style # |
| 83 | + ############## |
| 84 | + cs: |
| 85 | + |
| 86 | + runs-on: ubuntu-latest |
| 87 | + |
| 88 | + strategy: |
| 89 | + matrix: |
| 90 | + php-versions: ['7.4'] |
| 91 | + |
| 92 | + steps: |
| 93 | + - name: Checkout |
| 94 | + uses: actions/checkout@v3 |
| 95 | + |
| 96 | + - name: Validate composer.json and composer.lock |
| 97 | + run: composer validate --strict |
| 98 | + |
| 99 | + - name: Get composer cache directory |
| 100 | + id: composer-cache |
| 101 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 102 | + |
| 103 | + - name: Get date part for cache key |
| 104 | + id: key-date |
| 105 | + run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT |
| 106 | + |
| 107 | + - name: Cache composer dependencies |
| 108 | + uses: actions/cache@v3 |
| 109 | + with: |
| 110 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 111 | + key: cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} |
| 112 | + restore-keys: | |
| 113 | + cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }} |
| 114 | +
|
| 115 | + - name: Setup PHP |
| 116 | + uses: shivammathur/setup-php@v2 |
| 117 | + with: |
| 118 | + php-version: ${{ matrix.php-versions }} |
| 119 | + extensions: mbstring, intl |
| 120 | + |
| 121 | + - name: Install composer dependencies |
| 122 | + run: composer update --no-interaction |
| 123 | + |
| 124 | + - name: Run CS check |
| 125 | + run: composer cs-check |
0 commit comments