-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We'll need to play around with the unit test upload features (https://github.com/EnricoMi/publish-unit-test-result-action#configuration) what works best. This is based on what we do for the integration test. Most shared code is handled by baseinstall.sh. We can now also install a database with a different name as the unit tests use that locally. As side-effect we directly test this in CI. The CI ran on GitLab before and needed extra steps to push the result to GitHub. As everything is in GitHub Actions now we can remove those extra steps. (cherry picked from commit 5530189)
- Loading branch information
Showing
4 changed files
with
190 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/bin/bash | ||
|
||
. .github/jobs/ci_settings.sh | ||
|
||
DIR="$PWD" | ||
|
||
export version=$1 | ||
unittest=$2 | ||
[ "$version" = "8.1" ] && CODECOVERAGE=1 || CODECOVERAGE=0 | ||
|
||
# Set up | ||
export unit=1 | ||
|
||
# Add team to admin user | ||
echo "UPDATE user SET teamid = 1 WHERE userid = 1;" | mysql domjudge_test | ||
|
||
# Copy the .env.test file, as this is normally not done during | ||
# installation and we need it. | ||
cp webapp/.env.test /opt/domjudge/domserver/webapp/ | ||
|
||
# We also need the composer.json for PHPunit to detect the correct directory. | ||
cp webapp/composer.json /opt/domjudge/domserver/webapp/ | ||
|
||
cd /opt/domjudge/domserver | ||
|
||
# Run phpunit tests. | ||
pcov="" | ||
phpcov="" | ||
if [ "$CODECOVERAGE" -eq 1 ]; then | ||
phpcov="-dpcov.enabled=1 -dpcov.directory=webapp/src" | ||
pcov="--coverage-html=${DIR}/coverage-html --coverage-clover coverage.xml" | ||
fi | ||
set +e | ||
echo "unused:sqlserver:domjudge:domjudge:domjudge:3306" > /opt/domjudge/domserver/etc/dbpasswords.secret | ||
php $phpcov webapp/bin/phpunit -c webapp/phpunit.xml.dist webapp/tests/$unittest --log-junit ${ARTIFACTS}/unit-tests.xml --colors=never $pcov > "$ARTIFACTS"/phpunit.out | ||
UNITSUCCESS=$? | ||
|
||
# Store the unit tests also in the root for the GHA | ||
cp $ARTIFACTS/unit-tests.xml $DIR/ | ||
|
||
# Make sure the log exists before copy | ||
touch ${DIR}/webapp/var/log/test.log | ||
cp ${DIR}/webapp/var/log/*.log "$ARTIFACTS"/ | ||
|
||
set -e | ||
CNT=0 | ||
THRESHOLD=32 | ||
if [ $CODECOVERAGE -eq 1 ]; then | ||
CNT=$(sed -n '/Generating code coverage report/,$p' "$ARTIFACTS"/phpunit.out | grep -v DoctrineTestBundle | grep -cv ^$) | ||
fi | ||
|
||
if [ $UNITSUCCESS -ne 0 ] || [ $CNT -gt $THRESHOLD ]; then | ||
exit 1 | ||
fi | ||
|
||
if [ $CODECOVERAGE -eq 1 ]; then | ||
section_start "Upload code coverage" | ||
# Only upload when we got working unit-tests. | ||
set +u # Uses some variables which are not set | ||
# shellcheck disable=SC1090 | ||
. $DIR/.github/jobs/uploadcodecov.sh &>> "$ARTIFACTS"/codecov.log | ||
section_end | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters