Merge branch 'main' into 6.x #9323
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Visual Regression Testing | |
on: | |
push: | |
branches: [temp] | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review] | |
repository_dispatch: | |
types: [visual-tests-command] # triggered by /visual-tests PR comment | |
env: | |
writable: ${{ (github.event_name == 'repository_dispatch' || github.ref == 'refs/heads/temp' || github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') && 1 || 0 }} | |
permissions: | |
contents: read | |
jobs: | |
visual-tests: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
permissions: | |
contents: write # for Git to git apply | |
steps: | |
- name: Add action run link to trigger comment | |
uses: peter-evans/create-or-update-comment@v4 | |
if: github.event_name == 'repository_dispatch' | |
with: | |
token: ${{ secrets.BOT_TOKEN }} | |
repository: ${{ github.event.client_payload.github.payload.repository.full_name }} | |
comment-id: ${{ github.event.client_payload.github.payload.comment.id }} | |
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: env.writable == 1 && github.event_name != 'repository_dispatch' | |
with: | |
ref: ${{ github.head_ref }} | |
token: ${{ secrets.BOT_TOKEN }} | |
- name: Checkout fork | |
uses: actions/checkout@v4 | |
if: env.writable == 0 | |
- name: Checkout on chat commnad | |
uses: actions/checkout@v4 | |
if: github.event_name == 'repository_dispatch' | |
with: | |
token: ${{ secrets.BOT_TOKEN }} | |
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} | |
ref: ${{ github.event.client_payload.pull_request.head.ref }} | |
- name: Setup nodejs | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: npm | |
cache-dependency-path: .github/workflows/visual-tests.yml | |
- name: Install npm packages | |
run: npm install playwright pixelmatch pngjs fs mkdirp | |
- name: Get installed Playwright version (used in cache key) | |
id: playwright-version | |
run: echo "PLAYWRIGHT_VERSION=$(node -e "process.stdout.write(require('playwright/package.json').version)")" >> $GITHUB_ENV | |
- name: Cache Playwright browser binaries | |
uses: actions/cache@v4 | |
id: playwright-cache | |
with: | |
path: ~/.cache/ms-playwright | |
key: playwright-${{ env.PLAYWRIGHT_VERSION }} | |
- name: Install Playwright browsers binaries if cache missed | |
run: npx playwright install chromium --with-deps | |
if: steps.playwright-cache.outputs.cache-hit != 'true' | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: '8.3' | |
ini-values: 'error_reporting=E_ALL, display_errors=On, display_startup_errors=On' | |
extensions: gd, pdo_mysql | |
coverage: none # disable xdebug, pcov | |
tools: cs2pr | |
- name: Composer install | |
uses: ramsey/composer-install@v2 | |
with: | |
composer-options: --ansi --prefer-dist | |
- name: Init database | |
run: | | |
sudo /etc/init.d/mysql start | |
mysql -uroot -h127.0.0.1 -proot -e 'create database redaxo6;' | |
php redaxo/bin/console setup:run -n --lang=de_de --db-host=127.0.0.1 --db-name=redaxo6 --db-password=root --db-createdb=no --db-setup=normal --admin-username=admin --admin-password=adminpassword --error-email=test@redaxo.invalid --ansi -v | |
php redaxo/bin/console config:set --type boolean debug.enabled true -v | |
php redaxo/bin/console config:set --type boolean debug.throw_always_exception true -v | |
- name: Create user, update config | |
run: | | |
php redaxo/bin/console user:create myusername mypassword --admin --ansi -v | |
php redaxo/bin/console config:set error_email 'test@redaxo.invalid' --ansi -v | |
- name: Import mock data | |
run: | | |
mkdir -p $GITHUB_WORKSPACE/redaxo/data/core/backup && cp -r .github/imports/inital-content-for-visual-tests.sql $GITHUB_WORKSPACE/redaxo/data/core/backup/ | |
cp -r .github/imports/media/* $GITHUB_WORKSPACE/media/ | |
cp -f .github/imports/README.md $GITHUB_WORKSPACE/redaxo/src/addons/project/README.de.md | |
php redaxo/bin/console setup:run -n --lang=de_de --db-password=root --db-setup=import --db-import=inital-content-for-visual-tests --admin-username=myusername --admin-password=mypassword --ansi -v | |
- name: Install packages | |
run: | | |
php redaxo/bin/console addon:install debug --ansi -v | |
- name: Start php server | |
run: | | |
cat <<EOF > router.php | |
<?php | |
if (preg_match('@redaxo/(?:bin|data|cache|src)@', \$_SERVER['REQUEST_URI'])) http_response_code(403); | |
else return false; | |
EOF | |
php -S localhost:8080 router.php & | |
- name: Take screenshots (differential) | |
if: github.event_name != 'repository_dispatch' | |
run: | | |
php redaxo/bin/console config:set setup true -t boolean --ansi -v | |
php redaxo/bin/console cache:clear --ansi -v | |
node .github/tests-visual/visual-record.js setup | |
php redaxo/bin/console config:set setup false -t boolean --ansi -v | |
php redaxo/bin/console cache:clear --ansi -v | |
node .github/tests-visual/visual-record.js | |
git diff --exit-code --name-only .github/tests-visual/ | |
- name: Force regenerate all screenshots | |
if: github.event_name == 'repository_dispatch' | |
run: | | |
php redaxo/bin/console config:set setup true -t boolean --ansi -v | |
php redaxo/bin/console cache:clear --ansi -v | |
node .github/tests-visual/visual-record.js setup regenerate-all | |
php redaxo/bin/console config:set setup false -t boolean --ansi -v | |
php redaxo/bin/console cache:clear --ansi -v | |
node .github/tests-visual/visual-record.js regenerate-all | |
git diff --exit-code --name-only .github/tests-visual/ | |
- name: Commit changed files | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
if: failure() && env.writable == 1 | |
with: | |
commit_message: Update screenshots | |
commit_user_name: rex-bot | |
commit_user_email: rex-bot@users.noreply.github.com | |
file_pattern: .github/tests-visual/* | |
branch: ${{ github.head_ref }} # repo dispatch needs the target branch | |
- name: Remove automerge label | |
uses: actions-ecosystem/action-remove-labels@v1 | |
if: failure() && env.writable == 1 | |
with: | |
github_token: ${{ secrets.BOT_TOKEN }} | |
labels: automerge |