| 1 |
name: WebUI E2E (Playwright) |
| 2 |
|
| 3 |
on: |
| 4 |
workflow_call: |
| 5 |
inputs: |
| 6 |
image: |
| 7 |
required: true |
| 8 |
type: string |
| 9 |
name: |
| 10 |
required: true |
| 11 |
type: string |
| 12 |
|
| 13 |
concurrency: |
| 14 |
group: webui-e2e-playwright-${{ github.ref }} |
| 15 |
cancel-in-progress: true |
| 16 |
|
| 17 |
jobs: |
| 18 |
e2e: |
| 19 |
runs-on: ubuntu-latest |
| 20 |
timeout-minutes: 15 |
| 21 |
permissions: |
| 22 |
contents: read |
| 23 |
container: |
| 24 |
image: ${{ inputs.image }} |
| 25 |
options: --user root |
| 26 |
strategy: |
| 27 |
fail-fast: false |
| 28 |
matrix: |
| 29 |
include: |
| 30 |
- version: 1.45.3 |
| 31 |
label: legacy |
| 32 |
node-version: '22' |
| 33 |
- version: latest |
| 34 |
label: latest |
| 35 |
steps: |
| 36 |
- name: Check out source code |
| 37 |
uses: actions/checkout@v4 |
| 38 |
with: |
| 39 |
path: src |
| 40 |
|
| 41 |
- name: Define install prefix |
| 42 |
run: echo "PREFIX=${GITHUB_WORKSPACE}/install" >> "$GITHUB_ENV" |
| 43 |
|
| 44 |
- name: Download rspamd binary from build job |
| 45 |
uses: actions/download-artifact@v4 |
| 46 |
with: |
| 47 |
name: rspamd-binary-${{ inputs.name }} |
| 48 |
path: ${{ env.PREFIX }} |
| 49 |
|
| 50 |
- name: Prepare rspamd configuration |
| 51 |
run: | |
| 52 |
mkdir -p ${PREFIX}/etc/rspamd/local.d |
| 53 |
cp -r src/conf/* ${PREFIX}/etc/rspamd/ |
| 54 |
cat > ${PREFIX}/etc/rspamd/local.d/worker-controller.inc << 'EOF' |
| 55 |
static_dir = "${PREFIX}/share/rspamd/www"; |
| 56 |
password = "$2$8y16z4benwtsemhhcsdtxc6zem1muuhj$pufmrdhm41s53eccisds6rxych3khq493jhqra8r1i3jto93dt7b"; |
| 57 |
enable_password = "$2$hkmgaqejragy47tfe18k7r8zf4wwfegt$jdrfna838b9f4mqu73q858t3zjpse1kw8mw7e6yeftabq1of1sry"; |
| 58 |
secure_ip = "0"; |
| 59 |
EOF |
| 60 |
cat > ${PREFIX}/etc/rspamd/local.d/logging.inc << 'EOF' |
| 61 |
type = "console"; |
| 62 |
level = "error"; |
| 63 |
EOF |
| 64 |
cat > ${PREFIX}/etc/rspamd/local.d/history_redis.conf << 'EOF' |
| 65 |
servers = "127.0.0.1"; |
| 66 |
EOF |
| 67 |
chmod +x ${PREFIX}/bin/rspamd |
| 68 |
mkdir -p /var/run/rspamd /var/lib/rspamd |
| 69 |
chown $USER:$USER /var/run/rspamd /var/lib/rspamd |
| 70 |
|
| 71 |
- name: Start rspamd and wait for WebUI |
| 72 |
run: | |
| 73 |
redis-server --daemonize yes |
| 74 |
${PREFIX}/bin/rspamd -c ${PREFIX}/etc/rspamd/rspamd.conf --insecure & |
| 75 |
# Initial delay before polling (in seconds) |
| 76 |
initial_delay=5 |
| 77 |
sleep "$initial_delay" |
| 78 |
# Wait up to 60 seconds for WebUI to respond |
| 79 |
max_retries=30 |
| 80 |
for i in $(seq 1 "$max_retries"); do |
| 81 |
http_code=$(wget -qO- --server-response http://localhost:11334/ping 2>&1 | awk '/^[[:space:]]*HTTP/ {print $2}' | tail -n1 || true) |
| 82 |
if [ "$http_code" = "200" ]; then |
| 83 |
elapsed=$(( initial_delay + (i - 1) * 2 )) |
| 84 |
echo "Rspamd WebUI is up (HTTP 200) after $elapsed seconds" |
| 85 |
break |
| 86 |
elif [ -n "$http_code" ] && [ "$http_code" != "000" ]; then |
| 87 |
echo "Unexpected HTTP code $http_code from /ping; failing" |
| 88 |
exit 1 |
| 89 |
fi |
| 90 |
echo "Waiting for rspamd... ($i/$max_retries)" |
| 91 |
sleep 2 |
| 92 |
done |
| 93 |
|
| 94 |
if [ "$i" -eq "$max_retries" ] && [ "$http_code" != "200" ]; then |
| 95 |
total_wait=$(( initial_delay + max_retries * 2 )) |
| 96 |
echo "ERROR: rspamd WebUI did not become available after $total_wait seconds" |
| 97 |
exit 1 |
| 98 |
fi |
| 99 |
|
| 100 |
- name: Install Node.js |
| 101 |
uses: actions/setup-node@v4 |
| 102 |
with: |
| 103 |
node-version: ${{ matrix.node-version || 'lts/*' }} |
| 104 |
|
| 105 |
- name: Cache Playwright browsers |
| 106 |
uses: actions/cache@v4 |
| 107 |
with: |
| 108 |
path: .cache/ms-playwright-${{ matrix.label }} |
| 109 |
key: browsers-${{ matrix.label }}-${{ runner.os }} |
| 110 |
|
| 111 |
- id: run-playwright |
| 112 |
name: Run Playwright tests (${{ matrix.label }}) |
| 113 |
env: |
| 114 |
HOME: /root |
| 115 |
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/.cache/ms-playwright-${{ matrix.label }} |
| 116 |
run: | |
| 117 |
set -e |
| 118 |
mkdir -p test-${{ matrix.label }} |
| 119 |
cp -r src/test/playwright test-${{ matrix.label }}/ |
| 120 |
cd test-${{ matrix.label }}/playwright |
| 121 |
|
| 122 |
npm init -y --silent |
| 123 |
echo "::group::Installing Playwright ${{ matrix.label }}" |
| 124 |
npm install --no-save --silent @playwright/test@${{ matrix.version }} |
| 125 |
npx playwright --version |
| 126 |
npx playwright install --with-deps |
| 127 |
echo "::endgroup::" |
| 128 |
|
| 129 |
echo "::group::Running tests (${{ matrix.label }})" |
| 130 |
# Run tests; store Playwright artifacts (traces/videos) separately from HTML report |
| 131 |
ARTIFACTS_DIR="$GITHUB_WORKSPACE/playwright-artifacts-${{ matrix.label }}" |
| 132 |
HTML_OUT="$GITHUB_WORKSPACE/playwright-report-${{ matrix.label }}" |
| 133 |
set +e |
| 134 |
npx playwright test --output="$ARTIFACTS_DIR" |
| 135 |
PW_STATUS=$? |
| 136 |
set -e |
| 137 |
REPORT_DIR="$PWD/playwright-report" |
| 138 |
if [ -d "$REPORT_DIR" ]; then |
| 139 |
mv "$REPORT_DIR" "$HTML_OUT" |
| 140 |
fi |
| 141 |
echo "report_path=$HTML_OUT" >> "$GITHUB_OUTPUT" |
| 142 |
echo "::endgroup::" |
| 143 |
exit $PW_STATUS |
| 144 |
|
| 145 |
- name: Upload Playwright reports (${{ matrix.label }}) |
| 146 |
if: always() |
| 147 |
uses: actions/upload-artifact@v4 |
| 148 |
with: |
| 149 |
name: playwright-report-${{ matrix.label }} |
| 150 |
path: ${{ github.workspace }}/playwright-report-${{ matrix.label }} |
| 151 |
if-no-files-found: ignore |
| 152 |
|
| 153 |
- name: Upload Playwright artifacts on failure (${{ matrix.label }}) |
| 154 |
if: failure() |
| 155 |
uses: actions/upload-artifact@v4 |
| 156 |
with: |
| 157 |
name: playwright-artifacts-${{ matrix.label }} |
| 158 |
path: ${{ github.workspace }}/playwright-artifacts-${{ matrix.label }} |
| 159 |
if-no-files-found: ignore |