Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/syntax check #2659

Merged
merged 9 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/jobs/syntax-check
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@

set -euo pipefail
# shellcheck disable=SC2242
cd "$(dirname "$0")" || exit -1

# Change directory to the root of the repo relative to this script file
cd "$(dirname "$0")/../../" || exit 1

PHP=$(command -v php)
if [ ! -x "$PHP" ]; then
echo "PHP ($PHP) not found or not executable"
# shellcheck disable=SC2242
exit -1
exit 1
fi
if [ ! -x /usr/bin/checkbashisms ]; then
echo "/usr/bin/checkbashisms not found or not executable"
# shellcheck disable=SC2242
exit -1
exit 1
fi
if [ ! -x /usr/bin/shellcheck ]; then
echo "/usr/bin/shellcheck not found or not executable"
# shellcheck disable=SC2242
exit -1
exit 1
fi

find . \( \
-path ./webapp/vendor -prune \
-path ./webapp/vendor -prune \
vmcj marked this conversation as resolved.
Show resolved Hide resolved
-o -path ./webapp/var -prune \
-o -path ./output -prune \
-o -path ./.git -prune \
Expand All @@ -32,7 +34,8 @@ find . \( \
-o -type f \) \
-a -type f | \
while read -r i ; do
if [[ "$i" == *\.php ]] || grep -q "^#\\!.*php" "$i"; then
if [[ "$i" == *\.php ]] || grep -q "^#\\!.*php" "$i" && \
echo "$i" | grep -qvE '(^\./(webapp/resources/adminer)\.php)'; then
vmcj marked this conversation as resolved.
Show resolved Hide resolved
$PHP -l "$i" | sed -e 's|No syntax errors detected in ./|check PHP syntax: |'
if [[ "$i" == *\.php ]] && [ "$i" != "./webapp/config/bundles.php" ] && ! head -1 "$i"|grep -q "strict_types"; then
echo "PHP file missing strict types declaration: $i"
Expand Down
2 changes: 1 addition & 1 deletion etc/gen_all_secrets
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ create_pw_file()
fi

# shellcheck disable=SC2039
[ -n "$QUIET" ] || echo -n "Running '$SCRIPT'... "
[ -n "$QUIET" ] || printf "Running '%s'... " "$SCRIPT"
touch "$FILE"
chmod go= "$FILE"
"./$SCRIPT" > "$FILE"
Expand Down
4 changes: 2 additions & 2 deletions gitlab/integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ mount -o remount,exec,dev /builds
section_end mount

section_start check_cgroup_v1 "Checking for cgroup v1 availability"
grep cgroup$ /proc/filesystems
if [ $? -eq 0 ]; then

if grep -qs cgroup$ /proc/filesystems; then
cgroupv1=1
else
echo "Skipping tests that rely on cgroup v1"
Expand Down
4 changes: 2 additions & 2 deletions judge/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ chmod a+rwx "$WORKDIR/compile"
touch compile.out compile.meta

# Copy compile script into chroot
# shellcheck disable=SC2174
mkdir -m 0777 -p "$WORKDIR/compile-script"
mkdir -p "$WORKDIR/compile-script"
chmod 0777 "$WORKDIR/compile-script"
cp -a "$(dirname "$COMPILE_SCRIPT")"/* "$WORKDIR/compile-script/"

cd "$WORKDIR/compile"
Expand Down
19 changes: 12 additions & 7 deletions judge/runguard_test/runguard_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash
# Ignore unreachable code, as it is called by `make test`.
# shellcheck disable=SC2317
Kevinjil marked this conversation as resolved.
Show resolved Hide resolved

cd "$(dirname "${BASH_SOURCE}")"
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1

RUNGUARD=../runguard
LOG1="$(mktemp)"
LOG2="$(mktemp)"
# shellcheck disable=SC2154
META=$(mktemp -p "$judgehost_tmpdir")

fail() {
Expand Down Expand Up @@ -98,7 +101,7 @@ test_streamsize() {
exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -t 1 -s 123 yes DOMjudge
expect_stdout "DOMjudge"
limit=$((123*1024))
actual=$(cat "$LOG1" | wc -c)
actual=$(wc -c < "$LOG1")
Kevinjil marked this conversation as resolved.
Show resolved Hide resolved
[ $limit -eq $actual ] || fail "stdout not limited to ${limit}B, but wrote ${actual}B"
}

Expand All @@ -107,7 +110,7 @@ test_streamsize_stderr() {
expect_stderr "DOMjudge"
# Allow 100 bytes extra, for the runguard time limit message.
limit=$((42*1024 + 100))
actual=$(cat "$LOG2" | wc -c)
actual=$(wc -c < "$LOG2")
[ $limit -gt $actual ] || fail "stdout not limited to ${limit}B, but wrote ${actual}B"
}

Expand All @@ -120,7 +123,7 @@ test_redir_stdout() {
grep -q "foobar" "$stdout" || fail "did not find expected 'foobar' in redirect stdout"

# Verify that stdout is empty.
actual=$(cat "$LOG1" | wc -c)
actual=$(wc -c < "$LOG1")
[ $actual -eq 0 ] || fail "stdout should be empty, but contains ${actual}B"

# This will fail because of the timeout.
Expand All @@ -129,13 +132,13 @@ test_redir_stdout() {
expect_stderr "hard wall time"

# Verify that stdout is empty.
actual=$(cat "$LOG1" | wc -c)
actual=$(wc -c < "$LOG1")
[ $actual -eq 0 ] || fail "stdout should be empty, but contains ${actual}B"

# Verify that redirected stdout has the right contents.
grep -q "DOMjudge" "$stdout" || fail "did not find expected 'DOMjudge' in redirect stdout"
limit=$((23*1024))
actual=$(cat "$stdout" | wc -c)
actual=$(wc -c < "$stdout")
[ $limit -eq $actual ] || fail "redirected stdout not limited to ${limit}B, but wrote ${actual}B"

rm "$stdout"
Expand All @@ -156,14 +159,15 @@ test_redir_stderr() {
# Verify that redirected stdout has the right contents.
grep -q "DOMjudge" "$stderr" || fail "did not find expected 'DOMjudge' in redirect stderr"
limit=$((11*1024))
actual=$(cat "$stderr" | wc -c)
actual=$(wc -c < "$stderr")
[ $limit -eq $actual ] || fail "redirected stdout not limited to ${limit}B, but wrote ${actual}B"

rm "$stderr"
}

test_rootdir_changedir() {
# Prepare test directory.
# shellcheck disable=SC2154
almost_empty_dir="$judgehost_judgedir/runguard_tests/almost_empty"
vmcj marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p "$almost_empty_dir"/exists
cp hello "$almost_empty_dir"/
Expand Down Expand Up @@ -243,6 +247,7 @@ test_meta() {
exec_check_fail sudo $RUNGUARD -u domjudge-run-0 -M "$META" false
expect_meta 'exitcode: 1'

# shellcheck disable=SC2024
echo "DOMjudge" | sudo $RUNGUARD -u domjudge-run-0 -t 2 -M "$META" rev > "$LOG1" 2> "$LOG2"
expect_meta 'wall-time: 0.0'
expect_meta 'stdout-bytes: 9'
Expand Down
3 changes: 2 additions & 1 deletion judge/version_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ touch version_check.out version_check.meta
if [ -e "$WORKDIR/version_check-script" ]; then
mv "$WORKDIR/version_check-script" "$WORKDIR/version_check-script-old"
fi
mkdir -m 0777 -p "$WORKDIR/version_check-script"
mkdir -p "$WORKDIR/version_check-script"
chmod 0777 -p "$WORKDIR/version_check-script"
cp -a "$VERSION_CHECK_SCRIPT" "$PWD/version_check-script/"

cd "$WORKDIR/version_check"
Expand Down
3 changes: 2 additions & 1 deletion misc-tools/dj_make_chroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ if [ "$DISTRO" = 'Ubuntu' ]; then
# x86(_64) can use the main Ubuntu repo's, other
# architectures need to use a mirror from ubuntu-ports.
MAINSTREAM="amd64 i386"
if [ -z "${MAINSTREAM##*$ARCH*}" ]; then
if [ -z "${MAINSTREAM##*"$ARCH"*}" ]; then
DEBMIRROR="http://us.archive.ubuntu.com/ubuntu/"
else
DEBMIRROR="http://ports.ubuntu.com/ubuntu-ports/"
Expand Down Expand Up @@ -321,6 +321,7 @@ fi

# Add indication to interactive shell that the user is in the chroot
for bashrc in "root/.bashrc" "etc/bash.bashrc"; do
# shellcheck disable=SC2016
echo 'PS1=(chroot)$PS1' >> "$CHROOTDIR/$bashrc"
done

Expand Down
2 changes: 2 additions & 0 deletions misc-tools/dj_run_chroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# Abort when a single command fails:
set -e

# See https://github.com/koalaman/shellcheck/issues/2660
# shellcheck disable=SC2317
Kevinjil marked this conversation as resolved.
Show resolved Hide resolved
cleanup() {
# Unmount things on cleanup
umount -f "$CHROOTDIR/proc" >/dev/null 2>&1 || /bin/true
Expand Down
30 changes: 15 additions & 15 deletions sql/dj_setup_database.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ EOF

mysql_options()
{
local user pass

Kevinjil marked this conversation as resolved.
Show resolved Hide resolved
# shellcheck disable=SC2153
if [ -n "$DBUSER" ]; then
user="-u $DBUSER"
_user="-u $DBUSER"
else
user="${DBA_USER:+-u ${DBA_USER}}"
_user="${DBA_USER:+-u ${DBA_USER}}"
fi
# shellcheck disable=SC2153
if [ -n "$PASSWD" ]; then
pass="-p$PASSWD"
_pass="-p$PASSWD"
else
[ -n "$PROMPT_PASSWD" ] && pass="-p"
[ -n "$DBA_PASSWD" ] && pass="-p$DBA_PASSWD"
[ -n "$PROMPT_PASSWD" ] && _pass="-p"
[ -n "$DBA_PASSWD" ] && _pass="-p$DBA_PASSWD"
fi

[ -z "$USE_SOCKET" ] && port="-P$DBPORT"
echo $user ${pass:+"$pass"} -h "$DBHOST" ${port:+"$port"}
echo $_user ${_pass:+"$_pass"} -h "$DBHOST" ${port:+"$port"}
}

# Wrapper around mysql command to allow setting options, user, etc.
Expand Down Expand Up @@ -363,7 +361,7 @@ upgrade)
# Check if we need to upgrade the Doctrine migrations table
if ! echo "SHOW CREATE TABLE \`doctrine_migration_versions\`" | mysql "$DBNAME" >/dev/null 2>&1; then
symfony_console doctrine:migrations:sync-metadata-storage -n
# shellcheck disable=SC2016
# shellcheck disable=SC2016,SC2028
echo 'INSERT INTO `doctrine_migration_versions`
(version, executed_at, execution_time)
SELECT concat("DoctrineMigrations\\\\Version", version), executed_at, 1
Expand All @@ -386,7 +384,8 @@ dump)

if [ -f "${DATABASEDUMPDIR}/${DUMPNAME}.sql.gz" ]; then
while true; do
read -p "Overwrite existing database dump (y/N)? " yn
printf "Overwrite existing database dump (y/N)? "
read -r yn
Kevinjil marked this conversation as resolved.
Show resolved Hide resolved
case $yn in
[Yy]* ) break ;;
''|[Nn]* ) exit 0;;
Expand All @@ -407,19 +406,20 @@ load)
exit 1
fi
ind=1
for i in "$databases"; do
for i in $databases; do
Kevinjil marked this conversation as resolved.
Show resolved Hide resolved
echo "$ind) $i"
: $((ind+=1))
ind=$((ind+1))
done
while true; do
read -p "Which database should be loaded? " db
printf "Which database should be loaded? "
read -r db
ind=1
for i in "$databases"; do
for i in $databases; do
if [ "$ind" = "$db" ]; then
FILE="$i"
break
fi
: $((ind+=1))
ind=$((ind+1))
done
if [ -n "$FILE" ]; then
break
Expand Down
12 changes: 8 additions & 4 deletions sql/files/defaultdata/r/run
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ fi
#
# Store intermediate files in the current dir (/compile) as its only
# available during compilation step.
export TMPDIR=`pwd`
Rscript -e "parse('"$@"')"
EXITCODE=$?
[ "$EXITCODE" -ne 0 ] && exit $EXITCODE
TMPDIR=`pwd`
export TMPDIR
for f in "$@"
vmcj marked this conversation as resolved.
Show resolved Hide resolved
do
Rscript -e "parse('$f')"
EXITCODE=$?
[ "$EXITCODE" -ne 0 ] && exit $EXITCODE
done

# Write executing script:
cat > "$DEST" <<EOF
Expand Down
2 changes: 1 addition & 1 deletion sql/files/defaultdata/swift/run
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ while [ $# -gt 0 ]; do
if [ "x${1%.swift}" != "x$1" ]; then
SOURCE="$1"
[ -z "$MAINSOURCE" ] && MAINSOURCE="$1"
if [ "x$SOURCE" = "x$MAINSOURCE" ] && [ "x$MAINSOURCE" != "xmain.swift" ]; then
if [ "$SOURCE" = "$MAINSOURCE" ] && [ "$MAINSOURCE" != "main.swift" ]; then
if [ -f "main.swift" ]; then
echo "main.swift exists but is not the main source; not allowed by Swift compiler"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion webapp/config/preload.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

if (file_exists(dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php')) {
require dirname(__DIR__) . '/var/cache/prod/App_KernelProdContainer.preload.php';
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Utils/EventFeedFormat.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

namespace App\Utils;

Expand Down
2 changes: 1 addition & 1 deletion webapp/tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);

use Symfony\Component\Dotenv\Dotenv;

Expand Down
Loading