jenkins.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. set -eux
  3. : ${WORKSPACE:="$(pwd)"}
  4. export PYTHONDONTWRITEBYTECODE=yep
  5. export SYNAPSE_CACHE_FACTOR=1
  6. # Output test results as junit xml
  7. export TRIAL_FLAGS="--reporter=subunit"
  8. export TOXSUFFIX="| subunit-1to2 | subunit2junitxml --no-passthrough --output-to=results.xml"
  9. # Write coverage reports to a separate file for each process
  10. export COVERAGE_OPTS="-p"
  11. export DUMP_COVERAGE_COMMAND="coverage help"
  12. # Output flake8 violations to violations.flake8.log
  13. # Don't exit with non-0 status code on Jenkins,
  14. # so that the build steps continue and a later step can decided whether to
  15. # UNSTABLE or FAILURE this build.
  16. export PEP8SUFFIX="--output-file=violations.flake8.log || echo flake8 finished with status code \$?"
  17. rm .coverage* || echo "No coverage files to remove"
  18. tox
  19. : ${GIT_BRANCH:="origin/$(git rev-parse --abbrev-ref HEAD)"}
  20. TOX_BIN=$WORKSPACE/.tox/py27/bin
  21. if [[ ! -e .sytest-base ]]; then
  22. git clone https://github.com/matrix-org/sytest.git .sytest-base --mirror
  23. else
  24. (cd .sytest-base; git fetch -p)
  25. fi
  26. rm -rf sytest
  27. git clone .sytest-base sytest --shared
  28. cd sytest
  29. git checkout "${GIT_BRANCH}" || (echo >&2 "No ref ${GIT_BRANCH} found, falling back to develop" ; git checkout develop)
  30. : ${PERL5LIB:=$WORKSPACE/perl5/lib/perl5}
  31. : ${PERL_MB_OPT:=--install_base=$WORKSPACE/perl5}
  32. : ${PERL_MM_OPT:=INSTALL_BASE=$WORKSPACE/perl5}
  33. export PERL5LIB PERL_MB_OPT PERL_MM_OPT
  34. ./install-deps.pl
  35. : ${PORT_BASE:=8000}
  36. echo >&2 "Running sytest with SQLite3";
  37. ./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \
  38. --python $TOX_BIN/python --all --port-base $PORT_BASE > results-sqlite3.tap
  39. RUN_POSTGRES=""
  40. for port in $(($PORT_BASE + 1)) $(($PORT_BASE + 2)); do
  41. if psql synapse_jenkins_$port <<< ""; then
  42. RUN_POSTGRES="$RUN_POSTGRES:$port"
  43. cat > localhost-$port/database.yaml << EOF
  44. name: psycopg2
  45. args:
  46. database: synapse_jenkins_$port
  47. EOF
  48. fi
  49. done
  50. # Run if both postgresql databases exist
  51. if test "$RUN_POSTGRES" = ":$(($PORT_BASE + 1)):$(($PORT_BASE + 2))"; then
  52. echo >&2 "Running sytest with PostgreSQL";
  53. $TOX_BIN/pip install psycopg2
  54. ./run-tests.pl --coverage -O tap --synapse-directory $WORKSPACE \
  55. --python $TOX_BIN/python --all --port-base $PORT_BASE > results-postgresql.tap
  56. else
  57. echo >&2 "Skipping running sytest with PostgreSQL, $RUN_POSTGRES"
  58. fi
  59. cd ..
  60. cp sytest/.coverage.* .
  61. # Combine the coverage reports
  62. echo "Combining:" .coverage.*
  63. $TOX_BIN/python -m coverage combine
  64. # Output coverage to coverage.xml
  65. $TOX_BIN/coverage xml -o coverage.xml