|
| 1 | +name: PHPStan Code Quality (2.10.x) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 2.10.x |
| 7 | + |
| 8 | + pull_request_target: |
| 9 | + branches: |
| 10 | + - 2.10.x |
| 11 | + types: [labeled,synchronize] |
| 12 | + |
| 13 | +jobs: |
| 14 | + build: |
| 15 | + if: | |
| 16 | + ( ((github.event_name != 'pull_request') || contains(github.event.pull_request.labels.*.name, 'safe to test')) |
| 17 | + && (github.event.pull_request.draft == false) ) |
| 18 | + runs-on: ubuntu-22.04 |
| 19 | + name: PHPStan Quality |
| 20 | + |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - php-versions: '7.4' |
| 26 | + magento-versions: '2.4.2-p2' |
| 27 | + magento-editions: 'enterprise' |
| 28 | + experimental: true |
| 29 | + - php-versions: '7.4' |
| 30 | + magento-versions: '2.4.3-p3' |
| 31 | + magento-editions: 'enterprise' |
| 32 | + experimental: false |
| 33 | + - php-versions: '8.1' |
| 34 | + magento-versions: '2.4.4-p13' |
| 35 | + magento-editions: 'enterprise' |
| 36 | + experimental: false |
| 37 | + - php-versions: '8.1' |
| 38 | + magento-versions: '2.4.5-p14' |
| 39 | + magento-editions: 'enterprise' |
| 40 | + experimental: false |
| 41 | + |
| 42 | + continue-on-error: ${{ matrix.experimental }} |
| 43 | + |
| 44 | + env: |
| 45 | + magento-directory: /var/www/magento |
| 46 | + MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }} |
| 47 | + MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }} |
| 48 | + |
| 49 | + steps: |
| 50 | + - name: "[Init] Checkout" |
| 51 | + uses: actions/checkout@v3 |
| 52 | + with: |
| 53 | + ref: ${{ github.event.pull_request.head.sha }} |
| 54 | + persist-credentials: false |
| 55 | + |
| 56 | + - name: "[Init] Setup PHP" |
| 57 | + uses: shivammathur/setup-php@v2 |
| 58 | + with: |
| 59 | + php-version: ${{ matrix.php-versions }} |
| 60 | + extensions: hash, iconv, mbstring, intl, bcmath, ctype, gd, pdo, mysql, curl, zip, dom, sockets, soap, openssl, simplexml, xsl |
| 61 | + ini-values: post_max_size=256M, max_execution_time=180 |
| 62 | + |
| 63 | + - name: "[Init] Setup Magento Directory" |
| 64 | + env: |
| 65 | + MAGENTO_ROOT: ${{ env.magento-directory }} |
| 66 | + version: ${{ matrix.php-versions }} |
| 67 | + run: | |
| 68 | + sudo usermod -a -G www-data $USER |
| 69 | + sudo mkdir -p $MAGENTO_ROOT |
| 70 | + sudo chown -R $USER:www-data $MAGENTO_ROOT |
| 71 | +
|
| 72 | + - name: "[Init] Downgrade Composer" |
| 73 | + env: |
| 74 | + MAGENTO_VERSION: ${{ matrix.magento-versions }} |
| 75 | + run: | |
| 76 | + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 77 | + if [ $(version $MAGENTO_VERSION) -lt $(version "2.4.2") ]; then |
| 78 | + composer self-update --1 |
| 79 | + else |
| 80 | + composer self-update 2.1.14 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: "[Init] Optimize Composer" |
| 84 | + env: |
| 85 | + MAGENTO_VERSION: ${{ matrix.magento-versions }} |
| 86 | + run: | |
| 87 | + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 88 | + if [ $(version $MAGENTO_VERSION) -lt $(version "2.4.2") ]; then |
| 89 | + composer global require hirak/prestissimo:0.3.10 |
| 90 | + fi |
| 91 | +
|
| 92 | + - name: "[Init] Determine composer cache directory" |
| 93 | + id: composer-cache-directory |
| 94 | + run: "echo \"directory=$(composer config cache-dir)\" >> $GITHUB_OUTPUT" |
| 95 | + |
| 96 | + - name: "[Init] Cache Composer cache" |
| 97 | + id: composer-cache |
| 98 | + uses: actions/cache@v3 |
| 99 | + with: |
| 100 | + path: ${{ steps.composer-cache-directory.outputs.directory }} |
| 101 | + key: composer-${{ matrix.php-versions }}-${{ matrix.magento-editions }}-${{ matrix.magento-versions }} |
| 102 | + restore-keys: | |
| 103 | + composer-${{ matrix.php-versions }}-${{ matrix.magento-editions }}-${{ matrix.magento-versions }} |
| 104 | +
|
| 105 | + - name: "[Init] Cache Magento install" |
| 106 | + id: magento-cache |
| 107 | + uses: actions/cache@v3 |
| 108 | + with: |
| 109 | + path: ${{ env.magento-directory }} |
| 110 | + key: magento-${{ matrix.php-versions }}-${{ matrix.magento-editions }}-${{ matrix.magento-versions }} |
| 111 | + restore-keys: | |
| 112 | + magento-${{ matrix.php-versions }}-${{ matrix.magento-editions }}-${{ matrix.magento-versions }} |
| 113 | +
|
| 114 | + - name: "[Init] Prepare credentials" |
| 115 | + if: ${{env.MAGENTO_USERNAME}} != 0 |
| 116 | + run: composer config -g http-basic.repo.magento.com "$MAGENTO_USERNAME" "$MAGENTO_PASSWORD" |
| 117 | + |
| 118 | + - name: "[Init] Prepare Magento install if needed" |
| 119 | + if: steps.magento-cache.outputs.cache-hit == 'true' |
| 120 | + working-directory: ${{ env.magento-directory }} |
| 121 | + run: | |
| 122 | + rm -rf app/etc/env.php app/etc/config.php |
| 123 | + composer config discard-changes true |
| 124 | + composer remove smile/elasticsuite --no-update --no-interaction |
| 125 | + composer update --no-interaction --ignore-platform-reqs smile/elasticsuite |
| 126 | + composer config discard-changes false |
| 127 | +
|
| 128 | + - name: "[Init] Install proper version of Magento through Composer" |
| 129 | + if: steps.magento-cache.outputs.cache-hit != 'true' |
| 130 | + env: |
| 131 | + MAGENTO_VERSION: ${{ matrix.magento-versions }} |
| 132 | + MAGENTO_EDITION: ${{ matrix.magento-editions }} |
| 133 | + MAGENTO_ROOT: ${{ env.magento-directory }} |
| 134 | + EXPERIMENTAL: ${{ matrix.experimental }} |
| 135 | + run: | |
| 136 | + STABILITY="--stability=stable" |
| 137 | + if [ $EXPERIMENTAL = true ]; then |
| 138 | + STABILITY="" |
| 139 | + fi |
| 140 | + sudo rm -rf $MAGENTO_ROOT |
| 141 | + sudo mkdir -p $MAGENTO_ROOT |
| 142 | + sudo chown -R $USER:www-data $MAGENTO_ROOT |
| 143 | + composer create-project --repository-url=https://repo.magento.com magento/project-$MAGENTO_EDITION-edition=$MAGENTO_VERSION $STABILITY $MAGENTO_ROOT --quiet |
| 144 | +
|
| 145 | + - name: "[Init] Fix symfony/console and symfony string version" |
| 146 | + working-directory: ${{ env.magento-directory }} |
| 147 | + env: |
| 148 | + MAGENTO_VERSION: ${{ matrix.magento-versions }} |
| 149 | + run: | |
| 150 | + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 151 | + if [ $(version $MAGENTO_VERSION) -lt $(version "2.4.4") ]; then |
| 152 | + composer require symfony/console:4.4.26 --ignore-platform-reqs |
| 153 | + composer require symfony/string:5.4.2 --ignore-platform-reqs |
| 154 | + fi |
| 155 | +
|
| 156 | + - name: "[Init] Add current build of Elasticsuite" |
| 157 | + working-directory: ${{ env.magento-directory }} |
| 158 | + run: | |
| 159 | + composer require --dev "smile/elasticsuite:${GITHUB_BASE_REF:-${GITHUB_REF##*/}}-dev" --ignore-platform-reqs |
| 160 | + rm -rf vendor/smile/elasticsuite/** |
| 161 | + cp -Rf $GITHUB_WORKSPACE/* vendor/smile/elasticsuite/ |
| 162 | +
|
| 163 | + - name: "[Init] Unconditionally add phpstan/phpstan" |
| 164 | + working-directory: ${{ env.magento-directory }} |
| 165 | + run: composer require --dev --no-update smile/magento2-smilelab-phpstan ^1.0 |
| 166 | + |
| 167 | + - name: "[Init] Fix Magento directory permissions" |
| 168 | + env: |
| 169 | + MAGENTO_ROOT: ${{ env.magento-directory }} |
| 170 | + working-directory: ${{ env.magento-directory }} |
| 171 | + run: | |
| 172 | + sudo chmod -R a=r,u+w,a+X . |
| 173 | + sudo find var pub/static pub/media app/etc generated/ -type f -exec chmod g+w {} \; |
| 174 | + sudo find var pub/static pub/media app/etc generated/ -type d -exec chmod g+ws {} \; |
| 175 | + sudo chown -R $USER:www-data . |
| 176 | + sudo chmod u+x bin/magento |
| 177 | +
|
| 178 | + - name: "[Init] Enabling modules" |
| 179 | + working-directory: ${{ env.magento-directory }} |
| 180 | + run: php bin/magento module:enable --all |
| 181 | + |
| 182 | + - name: "[Init] Compile" |
| 183 | + working-directory: ${{ env.magento-directory }} |
| 184 | + run: php bin/magento setup:di:compile |
| 185 | + |
| 186 | + - name: "[Test] PHPStan" |
| 187 | + working-directory: ${{ env.magento-directory }} |
| 188 | + run: | |
| 189 | + sudo chmod u+x vendor/bin/phpstan |
| 190 | + vendor/bin/phpstan analyze --level=0 vendor/smile/elasticsuite |
| 191 | +
|
| 192 | + - name: "[Test] PHPUnit" |
| 193 | + env: |
| 194 | + PHP_VERSION: ${{ matrix.php-versions }} |
| 195 | + working-directory: ${{ env.magento-directory }} |
| 196 | + run: | |
| 197 | + function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; } |
| 198 | + if [ $(version $PHP_VERSION) -ge $(version "8.1") ]; then |
| 199 | + sudo chmod u+x vendor/bin/phpunit |
| 200 | + vendor/bin/phpunit -c vendor/smile/elasticsuite/Resources/tests/unit/phpunit.xml |
| 201 | + fi |
| 202 | +
|
| 203 | + - name: "[End] Job failed, gathering logs" |
| 204 | + env: |
| 205 | + MAGENTO_ROOT: ${{ env.magento-directory }} |
| 206 | + if: ${{ failure() }} |
| 207 | + run: | |
| 208 | + tail -n 100 $MAGENTO_ROOT/var/log/*.log |
0 commit comments