Skip to content

Commit fdd73a2

Browse files
committed
Move webstandard script to .github directory
Also added: - More MySQL debugging. - Prevent failing on HTTP404 errors, as we should only fail on HTTP500. - Test for both with and without example data. This is to make sure that when we have no entities for something (which we rarely test as we always upload data) the pages still look decent. As this script was used before we keep the old behaviour of always installing the data when there is no explicit database method given.
1 parent f58745e commit fdd73a2

File tree

7 files changed

+401
-127
lines changed

7 files changed

+401
-127
lines changed

.github/jobs/baseinstall.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/sh
2+
3+
. .github/jobs/ci_settings.sh
4+
5+
export version="$1"
6+
db=${2:-install}
7+
8+
set -eux
9+
10+
PHPVERSION=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION."\n";')
11+
export PHPVERSION
12+
13+
section_start "Run composer"
14+
export APP_ENV="dev"
15+
composer install --no-scripts |tee "$ARTIFACTS"/composer_out.txt
16+
section_end
17+
18+
section_start "Set simple admin password"
19+
echo "password" > ./etc/initial_admin_password.secret
20+
echo "default login admin password password" > ~/.netrc
21+
section_end
22+
23+
section_start "Install domserver"
24+
make configure
25+
./configure \
26+
--with-baseurl='https://localhost/domjudge/' \
27+
--with-domjudge-user=root \
28+
--enable-doc-build=no \
29+
--enable-judgehost-build=no | tee "$ARTIFACTS"/configure.txt
30+
31+
make domserver
32+
make install-domserver
33+
section_end
34+
35+
section_start "SQL settings"
36+
cat > ~/.my.cnf <<EOF
37+
[client]
38+
host=sqlserver
39+
user=root
40+
password=root
41+
EOF
42+
cat ~/.my.cnf
43+
44+
mysql_root "CREATE DATABASE IF NOT EXISTS \`domjudge\` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
45+
mysql_root "CREATE USER IF NOT EXISTS \`domjudge\`@'%' IDENTIFIED BY 'domjudge';"
46+
mysql_root "GRANT SELECT, INSERT, UPDATE, DELETE ON \`domjudge\`.* TO 'domjudge'@'%';"
47+
mysql_root "FLUSH PRIVILEGES;"
48+
49+
# Show some MySQL debugging
50+
mysql_root "show databases"
51+
mysql_root "SELECT CURRENT_USER();"
52+
mysql_root "SELECT USER();"
53+
mysql_root "SELECT user,host FROM mysql.user"
54+
echo "unused:sqlserver:domjudge:domjudge:domjudge:3306" > /opt/domjudge/domserver/etc/dbpasswords.secret
55+
mysql_user "SELECT CURRENT_USER();"
56+
mysql_user "SELECT USER();"
57+
section_end
58+
59+
section_start "Install DOMjudge database"
60+
/opt/domjudge/domserver/bin/dj_setup_database -uroot -proot bare-install
61+
#>> "$ARTIFACTS"/mysql.txt
62+
# We don't have -o pipefail so the `tee` eats away the potential error.
63+
#cat "$ARTIFACTS"/mysql.txt
64+
section_end
65+
66+
section_start "Show PHP config"
67+
php -v | tee -a "$ARTIFACTS"/php.txt
68+
php -m | tee -a "$ARTIFACTS"/php.txt
69+
section_end
70+
71+
section_start "Show general config"
72+
printenv | tee -a "$ARTIFACTS"/environment.txt
73+
cp /etc/os-release "$ARTIFACTS"/os-release.txt
74+
cp /proc/cmdline "$ARTIFACTS"/cmdline.txt
75+
section_end
76+
77+
section_start "Setup webserver"
78+
cp /opt/domjudge/domserver/etc/domjudge-fpm.conf /etc/php/"$PHPVERSION"/fpm/pool.d/domjudge.conf
79+
80+
rm -f /etc/nginx/sites-enabled/*
81+
cp /opt/domjudge/domserver/etc/nginx-conf /etc/nginx/sites-enabled/domjudge
82+
83+
openssl req -nodes -new -x509 -keyout /tmp/server.key -out /tmp/server.crt -subj "/C=NL/ST=Noord-Holland/L=Amsterdam/O=TestingForPR/CN=localhost"
84+
cp /tmp/server.crt /usr/local/share/ca-certificates/
85+
update-ca-certificates
86+
# shellcheck disable=SC2002
87+
cat "$(pwd)/.github/jobs/data/nginx_extra" | tee -a /etc/nginx/sites-enabled/domjudge
88+
nginx -t
89+
section_end
90+
91+
section_start "Show webserver is up"
92+
for service in nginx php${PHPVERSION}-fpm; do
93+
service "$service" restart
94+
service "$service" status
95+
done
96+
section_end
97+
98+
if [ "${db}" = "install" ]; then
99+
section_start "Install the example data"
100+
/opt/domjudge/domserver/bin/dj_setup_database -uroot -proot install-examples | tee -a "$ARTIFACTS/mysql.txt"
101+
section_end
102+
fi
103+
104+
section_start "Setup user"
105+
# We're using the admin user in all possible roles
106+
mysql_root "DELETE FROM userrole WHERE userid=1;" domjudge
107+
if [ "$version" = "team" ]; then
108+
# Add team to admin user
109+
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 3);" domjudge
110+
mysql_root "UPDATE user SET teamid = 1 WHERE userid = 1;" domjudge
111+
elif [ "$version" = "jury" ]; then
112+
# Add jury to admin user
113+
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 2);" domjudge
114+
elif [ "$version" = "balloon" ]; then
115+
# Add balloon to admin user
116+
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 4);" domjudge
117+
elif [ "$version" = "admin" ]; then
118+
# Add admin to admin user
119+
mysql_root "INSERT INTO userrole (userid, roleid) VALUES (1, 1);" domjudge
120+
fi
121+
section_end
122+

.github/jobs/ci_settings.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/sh
2+
3+
# Store artifacts/logs
4+
export ARTIFACTS="/tmp/artifacts"
5+
mkdir -p "$ARTIFACTS"
6+
7+
# Functions to annotate the Github actions logs
8+
trace_on () {
9+
set -x
10+
}
11+
trace_off () {
12+
{
13+
set +x
14+
} 2>/dev/null
15+
}
16+
17+
section_start_internal () {
18+
echo "::group::$1"
19+
trace_on
20+
}
21+
22+
section_end_internal () {
23+
echo "::endgroup::"
24+
trace_on
25+
}
26+
27+
mysql_root () {
28+
# shellcheck disable=SC2086
29+
echo "$1" | mysql -uroot -proot ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
30+
}
31+
32+
mysql_user () {
33+
# shellcheck disable=SC2086
34+
echo "$1" | mysql -udomjudge -pdomjudge ${2:-} | tee -a "$ARTIFACTS"/mysql.txt
35+
}
36+
37+
section_start () {
38+
if [ "$#" -ne 1 ]; then
39+
echo "Only 1 argument is needed for GHA, 2 was needed for GitLab."
40+
exit 1
41+
fi
42+
trace_off
43+
section_start_internal "$1"
44+
}
45+
46+
section_end () {
47+
trace_off
48+
section_end_internal
49+
}

.github/jobs/pa11y_config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"chromeLaunchConfig": {
3+
"args": [
4+
"--no-sandbox",
5+
"--disable-setuid-sandbox",
6+
"--disable-dev-shm-usage"
7+
]
8+
}
9+
}

.github/jobs/webstandard.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
. .github/jobs/ci_settings.sh
4+
5+
DIR="$PWD"
6+
7+
if [ "$#" -ne "2" ]; then
8+
exit 2
9+
fi
10+
11+
TEST="$1"
12+
ROLE="$2"
13+
14+
cd /opt/domjudge/domserver
15+
16+
section_start "Setup pa11y"
17+
pa11y --version
18+
section_end
19+
20+
section_start "Setup the test user"
21+
ADMINPASS=$(cat etc/initial_admin_password.secret)
22+
export COOKIEJAR
23+
COOKIEJAR=$(mktemp --tmpdir)
24+
export CURLOPTS="--fail -sq -m 30 -b $COOKIEJAR"
25+
if [ "$ROLE" = "public" ]; then
26+
ADMINPASS="failedlogin"
27+
fi
28+
29+
# Make an initial request which will get us a session id, and grab the csrf token from it
30+
CSRFTOKEN=$(curl $CURLOPTS -c $COOKIEJAR "http://localhost/domjudge/login" 2>/dev/null | sed -n 's/.*_csrf_token.*value="\(.*\)".*/\1/p')
31+
# Make a second request with our session + csrf token to actually log in
32+
# shellcheck disable=SC2086
33+
curl $CURLOPTS -c "$COOKIEJAR" -F "_csrf_token=$CSRFTOKEN" -F "_username=admin" -F "_password=$ADMINPASS" "http://localhost/domjudge/login"
34+
35+
# Move back to the default directory
36+
cd "$DIR"
37+
38+
cp "$COOKIEJAR" cookies.txt
39+
sed -i 's/#HttpOnly_//g' cookies.txt
40+
sed -i 's/\t0\t/\t1999999999\t/g' cookies.txt
41+
section_end
42+
43+
# Could try different entrypoints
44+
FOUNDERR=0
45+
URL=public
46+
mkdir "$URL"
47+
cd "$URL"
48+
cp "$DIR"/cookies.txt ./
49+
section_start "Scrape the site with the rebuild admin user"
50+
set +e
51+
wget \
52+
--reject-regex logout \
53+
--recursive \
54+
--no-clobber \
55+
--page-requisites \
56+
--html-extension \
57+
--convert-links \
58+
--restrict-file-names=windows \
59+
--domains localhost \
60+
--no-parent \
61+
--load-cookies cookies.txt \
62+
http://localhost/domjudge/"$URL"
63+
set -e
64+
RET=$?
65+
section_end
66+
67+
section_start "Archive downloaded site"
68+
cp -r localhost $ARTIFACTS/
69+
section_end
70+
71+
section_start "Analyse failures"
72+
#https://www.gnu.org/software/wget/manual/html_node/Exit-Status.html
73+
# Exit code 4 is network error which we can ignore
74+
# Exit code 8 can also be because of HTTP404 or 400
75+
if [ $RET -ne 4 ] && [ $RET -ne 0 ] && [ $RET -ne 8 ]; then
76+
exit $RET
77+
fi
78+
79+
EXPECTED_HTTP_CODES="200\|302\|400\|404"
80+
if [ "$ROLE" = "public" ]; then
81+
# It's expected to encounter a 401 for the login page as we supply the wrong password
82+
EXPECTED_HTTP_CODES="$EXPECTED_HTTP_CODES\|401"
83+
fi
84+
set +e
85+
NUM_ERRORS=$(grep -v "HTTP/1.1\" \($EXPECTED_HTTP_CODES\)" /var/log/nginx/domjudge.log | grep -v "robots.txt" -c; if [ "$?" -gt 1 ]; then exit 127; fi)
86+
set -e
87+
echo "$NUM_ERRORS"
88+
89+
if [ "$NUM_ERRORS" -ne 0 ]; then
90+
echo "Entered the if"
91+
grep -v "HTTP/1.1\" \($EXPECTED_HTTP_CODES\)" /var/log/nginx/domjudge.log | grep -v "robots.txt"
92+
exit 1
93+
fi
94+
section_end
95+
96+
if [ "$TEST" = "w3cval" ]; then
97+
section_start "Remove files from upstream with problems"
98+
rm -rf localhost/domjudge/doc
99+
rm -rf localhost/domjudge/css/fontawesome-all.min.css*
100+
rm -rf localhost/domjudge/bundles/nelmioapidoc*
101+
rm -f localhost/domjudge/css/bootstrap.min.css*
102+
rm -f localhost/domjudge/css/select2-bootstrap*.css*
103+
rm -f localhost/domjudge/css/dataTables*.css*
104+
rm -f localhost/domjudge/jury/config/check/phpinfo*
105+
section_end
106+
107+
section_start "Install testsuite"
108+
cd "$DIR"
109+
wget https://github.com/validator/validator/releases/latest/download/vnu.linux.zip
110+
unzip -q vnu.linux.zip
111+
section_end
112+
113+
FLTR='--filterpattern .*autocomplete.*|.*style.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*'
114+
for typ in html css svg
115+
do
116+
section_start "Analyse with $typ"
117+
# shellcheck disable=SC2086
118+
"$DIR"/vnu-runtime-image/bin/vnu --errors-only --exit-zero-always --skip-non-$typ --format json $FLTR "$URL" 2> result.json
119+
# shellcheck disable=SC2086
120+
NEWFOUNDERRORS=$("$DIR"/vnu-runtime-image/bin/vnu --errors-only --exit-zero-always --skip-non-$typ --format gnu $FLTR "$URL" 2>&1 | wc -l)
121+
FOUNDERR=$((NEWFOUNDERRORS+FOUNDERR))
122+
python3 -m "json.tool" < result.json > "$ARTIFACTS/w3c$typ$URL.json"
123+
trace_off; python3 gitlab/jsontogitlab.py "$ARTIFACTS/w3c$typ$URL.json"; trace_on
124+
section_end
125+
done
126+
else
127+
section_start "Remove files from upstream with problems"
128+
rm -rf localhost/domjudge/{doc,api}
129+
section_end
130+
131+
if [ "$TEST" == "axe" ]; then
132+
STAN="-e $TEST"
133+
FLTR=""
134+
else
135+
STAN="-s $TEST"
136+
FLTR="-E '#DataTables_Table_0 > tbody > tr > td > a','#menuDefault > a','#filter-card > div > div > div > span > span:nth-child(1) > span > ul > li > input',.problem-badge"
137+
fi
138+
chown -R domjudge:domjudge "$DIR"
139+
cd "$DIR"
140+
ACCEPTEDERR=5
141+
# shellcheck disable=SC2044,SC2035
142+
for file in $(find $URL -name "*.html")
143+
do
144+
section_start "$file"
145+
su domjudge -c "pa11y --config .github/jobs/pa11y_config.json $STAN -r json -T $ACCEPTEDERR $FLTR $file" | python3 -m json.tool
146+
ERR=$(su domjudge -c "pa11y --config .github/jobs/pa11y_config.json $STAN -r csv -T $ACCEPTEDERR $FLTR $file" | wc -l)
147+
FOUNDERR=$((ERR+FOUNDERR-1)) # Remove header row
148+
section_end
149+
done
150+
fi
151+
152+
echo "Found: " $FOUNDERR
153+
[ "$FOUNDERR" -eq 0 ]

0 commit comments

Comments
 (0)