-
-
Notifications
You must be signed in to change notification settings - Fork 116
155 lines (138 loc) · 7.69 KB
/
visual-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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