-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (145 loc) · 5.98 KB
/
Copy pathtest.yml
File metadata and controls
165 lines (145 loc) · 5.98 KB
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
156
157
158
159
160
161
162
163
164
165
name: "CI: Test"
on:
workflow_call:
inputs:
multisite:
type: boolean
default: false
smoke_grep:
type: string
default: ''
debug:
type: boolean
default: false
activate_plugins:
type: string
default: ''
redis:
type: boolean
default: false
env_vars:
type: string
default: ''
secrets:
NPM_FONTAWESOME_AUTH_TOKEN:
required: true
PACKAGIST_GITHUB_TOKEN:
required: true
YOAST_LICENSE_TOKEN:
required: false
# Superseded pushes to the same ref are worthless — a full test run is ~4
# minutes, so let a newer push cancel the one it replaces. Keyed by repository
# because this workflow is shared: github.repository and github.ref both refer
# to the calling repo.
concurrency:
group: test-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup project
uses: generoi/github-actions/setup@v1
with:
npm_fontawesome_auth_token: ${{ secrets.NPM_FONTAWESOME_AUTH_TOKEN }}
packagist_github_token: ${{ secrets.PACKAGIST_GITHUB_TOKEN }}
yoast_license_token: ${{ secrets.YOAST_LICENSE_TOKEN }}
# composer install is a no-op here whenever the vendor cache hit, so
# skip restoring the 288 MB download cache in that case (~11s).
composer_download_cache: 'on-vendor-miss'
- name: Install development packages
run: composer install:development
- name: Run CI tests
run: composer ci --no-interaction
- name: Install WordPress
uses: generoi/github-actions/install-wordpress@v1
with:
multisite: ${{ inputs.multisite }}
activate_plugins: ${{ inputs.activate_plugins }}
redis: ${{ inputs.redis }}
env_vars: ${{ inputs.env_vars }}
- name: Optimize acorn
run: ./vendor/bin/wp acorn optimize
continue-on-error: true
- name: Load frontpage
run: |
# install-wordpress already waited for the server to accept connections,
# so reaching this step with nothing listening means it came up and then
# DIED — a different failure, and one the old retry loop reported as a
# bare curl exit 7 with no explanation. Say so, and show its output.
if ! curl -s -o /dev/null http://localhost:8080/ 2>/dev/null; then
echo "::error::Web server was up during install but is no longer listening"
if [ -f /tmp/wp-server.pid ] && ! kill -0 "$(cat /tmp/wp-server.pid)" 2>/dev/null; then
echo "wp server process $(cat /tmp/wp-server.pid) is gone"
fi
echo "--- wp server output ---"
cat /tmp/wp-server.log || echo "(no log)"
exit 1
fi
RESPONSE=$(curl -sSLf http://localhost:8080/)
echo "$RESPONSE" > /tmp/frontpage.html
- name: Verify frontpage content
if: inputs.smoke_grep != ''
env:
SMOKE_GREP: ${{ inputs.smoke_grep }}
run: grep "$SMOKE_GREP" /tmp/frontpage.html
- name: Dump web server log
if: failure() || inputs.debug
run: |
echo "--- wp server output ---"
cat /tmp/wp-server.log || echo "(no log)"
- name: Enable debugging
if: failure() || inputs.debug
run: |
# Set development environment for debug output
if grep -q WP_ENVIRONMENT_TYPE .env; then
sed -i 's/.*WP_ENVIRONMENT_TYPE=.*/WP_ENVIRONMENT_TYPE=development/g' .env
else
echo 'WP_ENVIRONMENT_TYPE=development' >> .env
fi
# Clear Acorn's cached config so the env change takes effect
./vendor/bin/wp acorn optimize:clear 2>/dev/null || true
./vendor/bin/wp acorn config:clear 2>/dev/null || true
- name: Display debug response
if: failure() || inputs.debug
run: |
# Try JSON endpoint first — Ignition/Acorn returns structured errors with Accept: application/json
echo "--- JSON error response ---"
JSON=$(curl -s -H "Accept: application/json" http://localhost:8080/)
# Extract message and exception class from JSON if available
if echo "$JSON" | jq -e '.message' >/dev/null 2>&1; then
echo "$JSON" | jq -r '"Exception: \(.exception // "unknown")\nMessage: \(.message)\nFile: \(.file // "unknown"):\(.line // "?")\n\nTrace:\n\(.trace[:5][]? | " \(.file // "?"):\(.line // "?") \(.class // "")\(.type // "")\(.function // "")()")"' 2>/dev/null || echo "$JSON" | jq '.' 2>/dev/null || echo "$JSON" | head -200
else
echo "(no JSON error response)"
fi
echo ""
BODY=$(curl -s http://localhost:8080/)
# Check for wp_die() error pages
WPDIE=$(echo "$BODY" | grep -o '<div class="wp-die-message">.*</div>' 2>/dev/null | sed 's/<[^>]*>//g' || true)
if [ -n "$WPDIE" ]; then
echo "--- wp_die() error ---"
echo "$WPDIE"
fi
# Check for PHP fatal errors in plain text
FATAL=$(echo "$BODY" | grep -iE "Fatal error|Parse error|TypeError|Warning:" | head -10 || true)
if [ -n "$FATAL" ]; then
echo "--- PHP errors ---"
echo "$FATAL"
fi
# Show verbose response headers as fallback
echo "--- Response headers ---"
curl -sI http://localhost:8080/ 2>&1
- name: Check if phpunit is available
id: has-phpunit
run: |
if composer show phpunit/phpunit 2>/dev/null; then
echo "available=true" >> $GITHUB_OUTPUT
else
echo "available=false" >> $GITHUB_OUTPUT
fi
- name: Run unit tests
if: steps.has-phpunit.outputs.available == 'true'
run: composer phpunit