-
Notifications
You must be signed in to change notification settings - Fork 0
143 lines (125 loc) · 4.78 KB
/
test.yml
File metadata and controls
143 lines (125 loc) · 4.78 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
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
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 }}
- 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: |
# Retry loop: wait for the web server to be ready (up to 30 seconds)
for i in $(seq 1 30); do
if curl -sSf -o /dev/null http://localhost:8080/ 2>/dev/null; then
break
fi
echo "Waiting for web server... attempt $i/30"
sleep 1
done
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: 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