|
| 1 | +name: Playwright |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - '*.x' |
| 8 | + pull_request: |
| 9 | + schedule: |
| 10 | + - cron: '0 0 * * *' |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + update_all_screenshots: |
| 14 | + description: 'Update all screenshots?' |
| 15 | + type: boolean |
| 16 | + |
| 17 | +env: |
| 18 | + PACKAGE: reviews |
| 19 | + |
| 20 | +jobs: |
| 21 | + test: |
| 22 | + timeout-minutes: 60 |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + defaults: |
| 26 | + run: |
| 27 | + working-directory: ./rapidez/rapidez |
| 28 | + |
| 29 | + strategy: |
| 30 | + fail-fast: false |
| 31 | + matrix: |
| 32 | + include: |
| 33 | + - magento-version: 2.4.7-p7 |
| 34 | + magento-php-version: php83-fpm |
| 35 | + rapidez-php-version: 8.3 |
| 36 | + - magento-version: 2.4.8-p2 |
| 37 | + magento-php-version: php84-fpm |
| 38 | + rapidez-php-version: 8.4 |
| 39 | + screenshots: true |
| 40 | + |
| 41 | + services: |
| 42 | + magento: |
| 43 | + image: michielgerritsen/magento-project-community-edition:${{matrix.magento-php-version}}-magento${{matrix.magento-version}}-sample-data |
| 44 | + env: |
| 45 | + URL: http://localhost:1234/ |
| 46 | + FLAT_TABLES: true |
| 47 | + CUSTOM_ENTRYPOINT_COMMAND: "php bin/magento encryption:key:change -k 5AM3SD5SkwT8iwIxL6L1q8XQhzK3wk51; magerun2 config:store:set system/smtp/disable 1; magerun2 config:store:set checkout/options/enable_guest_checkout_login 1" |
| 48 | + ports: |
| 49 | + - 3307:3306 |
| 50 | + - 1234:80 |
| 51 | + |
| 52 | + elasticsearch: |
| 53 | + image: docker.elastic.co/elasticsearch/elasticsearch:8.18.2 |
| 54 | + ports: |
| 55 | + - 9200:9200 |
| 56 | + env: |
| 57 | + discovery.type: single-node |
| 58 | + ES_JAVA_OPTS: "-Xms512m -Xmx512m" |
| 59 | + http.cors.enabled: "true" |
| 60 | + http.cors.allow-credentials: "true" |
| 61 | + http.cors.allow-origin: "http://localhost:8000" |
| 62 | + http.cors.allow-headers: X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization, Access-Control-Allow-Headers, Accept |
| 63 | + xpack.security.enabled: "false" |
| 64 | + options: >- |
| 65 | + --health-cmd="curl http://localhost:9200/_cluster/health" |
| 66 | + --health-interval=10s |
| 67 | + --health-timeout=5s |
| 68 | + --health-retries=10 |
| 69 | +
|
| 70 | + name: P${{ matrix.rapidez-php-version }} - M${{matrix.magento-version}} on ${{matrix.magento-php-version}} |
| 71 | + |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + path: rapidez/${{ env.PACKAGE }} |
| 76 | + fetch-depth: 0 |
| 77 | + lfs: true |
| 78 | + |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + with: |
| 81 | + repository: rapidez/rapidez |
| 82 | + path: rapidez/rapidez |
| 83 | + |
| 84 | + - uses: actions/setup-node@v4 |
| 85 | + with: |
| 86 | + node-version: lts/* |
| 87 | + |
| 88 | + - name: Setup PHP |
| 89 | + uses: shivammathur/setup-php@v2 |
| 90 | + with: |
| 91 | + php-version: ${{ matrix.rapidez-php-version }} |
| 92 | + extensions: mbstring, dom, fileinfo, mysql |
| 93 | + coverage: none |
| 94 | + |
| 95 | + - name: Copy testing .env |
| 96 | + run: cp ../$PACKAGE/tests/playwright/.env.testing .env |
| 97 | + |
| 98 | + - name: Use Rapidez package from source |
| 99 | + run: composer config repositories.$PACKAGE path ../$PACKAGE |
| 100 | + |
| 101 | + - name: Get commit hash and tag of the package |
| 102 | + working-directory: ./rapidez/${{ env.PACKAGE }} |
| 103 | + run: | |
| 104 | + echo "PACKAGE_HASH=$(git symbolic-ref --short HEAD 2>/dev/null || git rev-parse HEAD | sed 's|/|_|g')" >> $GITHUB_ENV |
| 105 | + echo "LATEST_TAG=$(git describe --tags --abbrev=0)" >> $GITHUB_ENV |
| 106 | +
|
| 107 | + - name: Composer require the local rapidez package |
| 108 | + run: composer require rapidez/$PACKAGE:"dev-${{ env.PACKAGE_HASH }} as ${{ env.LATEST_TAG }}" |
| 109 | + |
| 110 | + - name: Publish Rapidez configs |
| 111 | + run: php artisan vendor:publish --provider="Rapidez\Core\RapidezServiceProvider" --tag="config" |
| 112 | + |
| 113 | + - name: Install Rapidez command |
| 114 | + run: php artisan rapidez:install --frontendonly |
| 115 | + |
| 116 | + - name: Install Yarn dependencies |
| 117 | + run: npm install -g yarn && yarn |
| 118 | + |
| 119 | + - name: Install Playwright Browsers |
| 120 | + run: yarn playwright install --with-deps |
| 121 | + |
| 122 | + - name: Frontend Build |
| 123 | + run: yarn run prod |
| 124 | + |
| 125 | + - name: Install Playwright tests |
| 126 | + run: | |
| 127 | + cp -r vendor/rapidez/$PACKAGE/tests/playwright tests/playwright |
| 128 | + cp vendor/rapidez/$PACKAGE/playwright.config.js playwright.config.js |
| 129 | +
|
| 130 | + - name: Wait for index to finish |
| 131 | + run: for i in {1..60}; do [[ $(mysql -h 127.0.0.1 -P 3307 -u magento -ppassword -ss -r -e "CALL sys.table_exists('magento', 'catalog_product_flat_1', @exists); SELECT @exists;") == *"BASE TABLE"* ]] && break || sleep 5; done |
| 132 | + |
| 133 | + - name: Rapidez index |
| 134 | + run: php artisan rapidez:index |
| 135 | + |
| 136 | + - name: Start the webserver |
| 137 | + run: php artisan serve & |
| 138 | + |
| 139 | + - name: Run Playwright tests |
| 140 | + run: yarn playwright test |
| 141 | + |
| 142 | + # Screenshots |
| 143 | + - name: Collect failed tests |
| 144 | + if: (failure() || inputs.update_all_screenshots) |
| 145 | + run: yarn playwright test --last-failed --list --reporter=dot --pass-with-no-tests > failed-tests.txt |
| 146 | + |
| 147 | + - name: Update screenshots |
| 148 | + if: failure() && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x'))) |
| 149 | + run: | |
| 150 | + while read -r test_name; do |
| 151 | + yarn playwright test "$test_name" --update-snapshots --reporter=list |
| 152 | + done < <(awk -F ' › ' 'NF>1{print $2}' failed-tests.txt | sort -u) |
| 153 | +
|
| 154 | + - name: Update all screenshots |
| 155 | + if: ${{ inputs.update_all_screenshots && matrix.screenshots == true }} |
| 156 | + run: yarn playwright test --update-snapshots --reporter=list |
| 157 | + |
| 158 | + - name: Move the screenshots |
| 159 | + if: (failure() || inputs.update_all_screenshots) && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x'))) |
| 160 | + run: cp -r tests/playwright/. ../$PACKAGE/tests/playwright/ |
| 161 | + |
| 162 | + - name: Commit the screenshots |
| 163 | + if: (failure() || inputs.update_all_screenshots) && matrix.screenshots == true && github.event_name != 'schedule' && !(github.event_name == 'push' && (github.ref_name == 'master' || endsWith(github.ref_name, '.x'))) |
| 164 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 165 | + with: |
| 166 | + commit_message: "[CI] Update Snapshots" |
| 167 | + repository: rapidez/${{ env.PACKAGE }} |
| 168 | + |
| 169 | + # Artifact |
| 170 | + - name: Dump docker logs |
| 171 | + if: failure() |
| 172 | + uses: jwalton/gh-docker-logs@v2 |
| 173 | + with: |
| 174 | + dest: './docker-logs' |
| 175 | + |
| 176 | + - name: Dump magento logs |
| 177 | + if: failure() |
| 178 | + working-directory: ${{ github.workspace }} |
| 179 | + run: | |
| 180 | + mkdir -p magento/var |
| 181 | + docker cp ${{ job.services.magento.id }}:/data/var/log magento/var/log |
| 182 | +
|
| 183 | + - name: Upload Artifact |
| 184 | + if: failure() |
| 185 | + uses: actions/upload-artifact@v4 |
| 186 | + with: |
| 187 | + name: artifact-P${{ matrix.rapidez-php-version }}-M${{matrix.magento-version}}-on-${{matrix.magento-php-version}} |
| 188 | + path: | |
| 189 | + rapidez/rapidez/blob-report |
| 190 | + rapidez/rapidez/storage/logs/laravel.log |
| 191 | + docker-logs |
| 192 | + magento/var/log |
| 193 | +
|
| 194 | + report: |
| 195 | + if: failure() |
| 196 | + needs: [test] |
| 197 | + runs-on: ubuntu-latest |
| 198 | + env: |
| 199 | + HTML_REPORT_PATH: ${{ github.repository }}/${{ github.ref_name }}/${{ github.run_id }}/${{ github.run_attempt }} |
| 200 | + |
| 201 | + steps: |
| 202 | + - uses: actions/checkout@v4 |
| 203 | + with: |
| 204 | + repository: rapidez/playwright-reports |
| 205 | + |
| 206 | + - uses: actions/setup-node@v4 |
| 207 | + with: |
| 208 | + node-version: lts/* |
| 209 | + |
| 210 | + - name: Install dependencies |
| 211 | + run: npm install |
| 212 | + |
| 213 | + - name: Download artifacts |
| 214 | + uses: actions/download-artifact@v4 |
| 215 | + with: |
| 216 | + path: ./reports |
| 217 | + merge-multiple: true |
| 218 | + |
| 219 | + - name: Generate HTML report |
| 220 | + run: npx playwright merge-reports --reporter html ./reports/rapidez/rapidez/blob-report |
| 221 | + |
| 222 | + - name: Upload Artifact |
| 223 | + uses: actions/upload-artifact@v4 |
| 224 | + with: |
| 225 | + name: playwright-report |
| 226 | + path: playwright-report |
| 227 | + |
| 228 | + - name: Push the new files to github pages |
| 229 | + uses: peaceiris/actions-gh-pages@v3 |
| 230 | + with: |
| 231 | + personal_token: ${{ secrets.RAPIDEZ_ACTIONS_ACCOUNT_PAT }} |
| 232 | + external_repository: rapidez/playwright-reports |
| 233 | + publish_dir: ./playwright-report |
| 234 | + destination_dir: ${{ env.HTML_REPORT_PATH }} |
| 235 | + |
| 236 | + - name: URL in summary |
| 237 | + run: echo "### Test results - https://${{ github.repository_owner }}.github.io/playwright-reports/${{ env.HTML_REPORT_PATH }}/" >> $GITHUB_STEP_SUMMARY |
0 commit comments