-
Notifications
You must be signed in to change notification settings - Fork 9
/
run.sh
executable file
·139 lines (101 loc) · 5.22 KB
/
run.sh
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
#!/usr/bin/env bash
# Install wpp-research if missing
if [ ! -d "./wpp-research" ]; then
git clone https://github.com/GoogleChromeLabs/wpp-research.git
(cd ./wpp-research && nvm i && npm ci)
fi
OLD_VERSION=${1-latest}
NEW_VERSION=${2-trunk}
THEME=${3-twentytwentyone}
SKIP_INIT=${4-false}
OUTPUT=${5-markdown}
SKIP_FORMATTING=${6-false}
PRINT_TO_FILES=${7-false}
# Configure WordPress versions
rm -rf old/.wp-env.override.json
rm -rf new/.wp-env.override.json
if [[ $OLD_VERSION == 'trunk' ]]; then
OLD_VERSION='master'
fi
if [[ $NEW_VERSION == 'trunk' ]]; then
NEW_VERSION='master'
fi
echo "Old version: $OLD_VERSION"
if [[ $OLD_VERSION != 'latest' ]]; then
if [[ "$OLD_VERSION" == *".zip"* ]]; then
echo "{\"core\":\"$OLD_VERSION\"}" >> old/.wp-env.override.json
else
echo "{\"core\":\"WordPress/WordPress#$OLD_VERSION\"}" >> old/.wp-env.override.json
fi
fi
echo "New version: $NEW_VERSION"
if [[ "$NEW_VERSION" == *".zip"* ]]; then
echo "{\"core\":\"$NEW_VERSION\"}" >> new/.wp-env.override.json
else
echo "{\"core\":\"WordPress/WordPress#$NEW_VERSION\"}" >> new/.wp-env.override.json
fi
if [[ $SKIP_INIT != 'true' ]]; then
# Install WordPress
(cd old && npm i && npm run wp-env --silent start)
(cd new && npm i && npm run wp-env --silent start)
# Update permalink structure
(cd old && npm run wp-env --silent run tests-cli wp rewrite structure '/%postname%/' -- --hard)
(cd new && npm run wp-env --silent run tests-cli wp rewrite structure '/%postname%/' -- --hard)
# Delete any data that might already exist by re-installing WordPress.
# Prevents mock data from being duplicated on subsequent runs.
(cd old && npm run wp-env --silent run tests-cli wp db reset -- --yes)
(cd old && npm run wp-env --silent run tests-cli wp core install -- --url=http://localhost:8891 --title=old --admin_user=admin --admin_password=password [email protected] --skip-email)
(cd new && npm run wp-env --silent run tests-cli wp db reset -- --yes)
(cd new && npm run wp-env --silent run tests-cli wp core install -- --url=http://localhost:8881 --title=new --admin_user=admin --admin_password=password [email protected] --skip-email)
# Activate plugins (again)
(cd old && npm run wp-env --silent run tests-cli wp plugin activate performance-lab wordpress-importer)
(cd new && npm run wp-env --silent run tests-cli wp plugin activate performance-lab wordpress-importer)
# Import mock data
(cd old && npm run wp-env --silent run tests-cli curl https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml)
(cd old && npm run wp-env --silent run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create)
(cd new && npm run wp-env --silent run tests-cli curl https://raw.githubusercontent.com/WordPress/theme-test-data/b9752e0533a5acbb876951a8cbb5bcc69a56474c/themeunittestdata.wordpress.xml -- --output /tmp/themeunittestdata.wordpress.xml)
(cd new && npm run wp-env --silent run tests-cli wp import /tmp/themeunittestdata.wordpress.xml -- --authors=create)
# Deactivate WordPress Importer
(cd old && npm run wp-env --silent run tests-cli wp plugin deactivate wordpress-importer)
(cd new && npm run wp-env --silent run tests-cli wp plugin deactivate wordpress-importer)
else
(cd old && npm run wp-env --silent start)
(cd new && npm run wp-env --silent start)
fi
# Install theme
(cd old && npm run wp-env --silent run tests-cli wp theme activate $THEME)
(cd new && npm run wp-env --silent run tests-cli wp theme activate $THEME)
## Post debuging info.
echo "Old version – Theme info"
(cd old && npm run wp-env run tests-cli wp theme list)
echo "New version – Theme info"
(cd new && npm run wp-env run tests-cli wp theme list)
cd ./wpp-research || exit
# Benchmark Web Vitals
npm run research --silent -- benchmark-web-vitals -u http://localhost:8881/ -n 20 -p -o csv > before.csv
npm run research --silent -- benchmark-web-vitals -u http://localhost:8891/ -n 20 -p -o csv > after.csv
if [[ $PRINT_TO_FILES == 'true' ]]; then
if [[ $OUTPUT == 'csv' ]]; then
node ../scripts/results.js "Web Vitals ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING > web-vitals-$THEME.csv
else
node ../scripts/results.js "Web Vitals ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING > web-vitals-$THEME.md
fi
else
node ../scripts/results.js "Web Vitals ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING
fi
# Benchmark Server-Timing
npm run research --silent -- benchmark-server-timing -u http://localhost:8881/ -n 100 -p -o csv > before.csv
npm run research --silent -- benchmark-server-timing -u http://localhost:8891/ -n 100 -p -o csv > after.csv
if [[ $PRINT_TO_FILES == 'true' ]]; then
if [[ $OUTPUT == 'csv' ]]; then
node ../scripts/results.js "Server-Timing ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING > server-timing-$THEME.csv
else
node ../scripts/results.js "Server-Timing ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING > server-timing-$THEME.md
fi
else
node ../scripts/results.js "Server-Timing ($THEME)" before.csv after.csv $OUTPUT $SKIP_FORMATTING
fi
# Shutdown sites again
cd ../
(cd old && npm run wp-env --silent stop)
(cd new && npm run wp-env --silent stop)