tests.yml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. name: Tests
  2. on:
  3. push:
  4. branches: ["develop", "release-*"]
  5. pull_request:
  6. concurrency:
  7. group: ${{ github.workflow }}-${{ github.ref }}
  8. cancel-in-progress: true
  9. jobs:
  10. check-sampleconfig:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v2
  14. - uses: actions/setup-python@v2
  15. - run: pip install .
  16. - run: scripts-dev/generate_sample_config.sh --check
  17. - run: scripts-dev/config-lint.sh
  18. check-schema-delta:
  19. runs-on: ubuntu-latest
  20. steps:
  21. - uses: actions/checkout@v2
  22. - uses: actions/setup-python@v2
  23. - run: "pip install 'click==8.1.1' 'GitPython>=3.1.20'"
  24. - run: scripts-dev/check_schema_delta.py --force-colors
  25. lint:
  26. uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
  27. with:
  28. typechecking-extras: "all"
  29. lint-crlf:
  30. runs-on: ubuntu-latest
  31. steps:
  32. - uses: actions/checkout@v2
  33. - name: Check line endings
  34. run: scripts-dev/check_line_terminators.sh
  35. lint-newsfile:
  36. if: ${{ github.base_ref == 'develop' || contains(github.base_ref, 'release-') }}
  37. runs-on: ubuntu-latest
  38. steps:
  39. - uses: actions/checkout@v2
  40. with:
  41. ref: ${{ github.event.pull_request.head.sha }}
  42. fetch-depth: 0
  43. - uses: actions/setup-python@v2
  44. - run: "pip install 'towncrier>=18.6.0rc1'"
  45. - run: scripts-dev/check-newsfragment.sh
  46. env:
  47. PULL_REQUEST_NUMBER: ${{ github.event.number }}
  48. # Dummy step to gate other tests on without repeating the whole list
  49. linting-done:
  50. if: ${{ !cancelled() }} # Run this even if prior jobs were skipped
  51. needs: [lint, lint-crlf, lint-newsfile, check-sampleconfig, check-schema-delta]
  52. runs-on: ubuntu-latest
  53. steps:
  54. - run: "true"
  55. trial:
  56. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  57. needs: linting-done
  58. runs-on: ubuntu-latest
  59. strategy:
  60. matrix:
  61. python-version: ["3.7", "3.8", "3.9", "3.10"]
  62. database: ["sqlite"]
  63. extras: ["all"]
  64. include:
  65. # Newest Python without optional deps
  66. - python-version: "3.10"
  67. extras: ""
  68. # Oldest Python with PostgreSQL
  69. - python-version: "3.7"
  70. database: "postgres"
  71. postgres-version: "10"
  72. extras: "all"
  73. # Newest Python with newest PostgreSQL
  74. - python-version: "3.10"
  75. database: "postgres"
  76. postgres-version: "14"
  77. extras: "all"
  78. steps:
  79. - uses: actions/checkout@v2
  80. - run: sudo apt-get -qq install xmlsec1
  81. - name: Set up PostgreSQL ${{ matrix.postgres-version }}
  82. if: ${{ matrix.postgres-version }}
  83. run: |
  84. docker run -d -p 5432:5432 \
  85. -e POSTGRES_PASSWORD=postgres \
  86. -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \
  87. postgres:${{ matrix.postgres-version }}
  88. - uses: matrix-org/setup-python-poetry@v1
  89. with:
  90. python-version: ${{ matrix.python-version }}
  91. extras: ${{ matrix.extras }}
  92. - name: Await PostgreSQL
  93. if: ${{ matrix.postgres-version }}
  94. timeout-minutes: 2
  95. run: until pg_isready -h localhost; do sleep 1; done
  96. - run: poetry run trial --jobs=2 tests
  97. env:
  98. SYNAPSE_POSTGRES: ${{ matrix.database == 'postgres' || '' }}
  99. SYNAPSE_POSTGRES_HOST: localhost
  100. SYNAPSE_POSTGRES_USER: postgres
  101. SYNAPSE_POSTGRES_PASSWORD: postgres
  102. - name: Dump logs
  103. # Logs are most useful when the command fails, always include them.
  104. if: ${{ always() }}
  105. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  106. # This keeps logs colocated with failing jobs
  107. # It also ignores find's exit code; this is a best effort affair
  108. run: >-
  109. find _trial_temp -name '*.log'
  110. -exec echo "::group::{}" \;
  111. -exec cat {} \;
  112. -exec echo "::endgroup::" \;
  113. || true
  114. trial-olddeps:
  115. # Note: sqlite only; no postgres
  116. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  117. needs: linting-done
  118. runs-on: ubuntu-latest
  119. steps:
  120. - uses: actions/checkout@v2
  121. - name: Test with old deps
  122. uses: docker://ubuntu:focal # For old python and sqlite
  123. # Note: focal seems to be using 3.8, but the oldest is 3.7?
  124. # See https://github.com/matrix-org/synapse/issues/12343
  125. with:
  126. workdir: /github/workspace
  127. entrypoint: .ci/scripts/test_old_deps.sh
  128. - name: Dump logs
  129. # Logs are most useful when the command fails, always include them.
  130. if: ${{ always() }}
  131. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  132. # This keeps logs colocated with failing jobs
  133. # It also ignores find's exit code; this is a best effort affair
  134. run: >-
  135. find _trial_temp -name '*.log'
  136. -exec echo "::group::{}" \;
  137. -exec cat {} \;
  138. -exec echo "::endgroup::" \;
  139. || true
  140. trial-pypy:
  141. # Very slow; only run if the branch name includes 'pypy'
  142. # Note: sqlite only; no postgres. Completely untested since poetry move.
  143. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  144. needs: linting-done
  145. runs-on: ubuntu-latest
  146. strategy:
  147. matrix:
  148. python-version: ["pypy-3.7"]
  149. extras: ["all"]
  150. steps:
  151. - uses: actions/checkout@v2
  152. # Install libs necessary for PyPy to build binary wheels for dependencies
  153. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  154. - uses: matrix-org/setup-python-poetry@v1
  155. with:
  156. python-version: ${{ matrix.python-version }}
  157. extras: ${{ matrix.extras }}
  158. - run: poetry run trial --jobs=2 tests
  159. - name: Dump logs
  160. # Logs are most useful when the command fails, always include them.
  161. if: ${{ always() }}
  162. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  163. # This keeps logs colocated with failing jobs
  164. # It also ignores find's exit code; this is a best effort affair
  165. run: >-
  166. find _trial_temp -name '*.log'
  167. -exec echo "::group::{}" \;
  168. -exec cat {} \;
  169. -exec echo "::endgroup::" \;
  170. || true
  171. sytest:
  172. if: ${{ !failure() && !cancelled() }}
  173. needs: linting-done
  174. runs-on: ubuntu-latest
  175. container:
  176. image: matrixdotorg/sytest-synapse:${{ matrix.sytest-tag }}
  177. volumes:
  178. - ${{ github.workspace }}:/src
  179. env:
  180. SYTEST_BRANCH: ${{ github.head_ref }}
  181. POSTGRES: ${{ matrix.postgres && 1}}
  182. MULTI_POSTGRES: ${{ (matrix.postgres == 'multi-postgres') && 1}}
  183. WORKERS: ${{ matrix.workers && 1 }}
  184. REDIS: ${{ matrix.redis && 1 }}
  185. BLACKLIST: ${{ matrix.workers && 'synapse-blacklist-with-workers' }}
  186. TOP: ${{ github.workspace }}
  187. strategy:
  188. fail-fast: false
  189. matrix:
  190. include:
  191. - sytest-tag: focal
  192. - sytest-tag: focal
  193. postgres: postgres
  194. - sytest-tag: testing
  195. postgres: postgres
  196. - sytest-tag: focal
  197. postgres: multi-postgres
  198. workers: workers
  199. - sytest-tag: buster
  200. postgres: multi-postgres
  201. workers: workers
  202. - sytest-tag: buster
  203. postgres: postgres
  204. workers: workers
  205. redis: redis
  206. steps:
  207. - uses: actions/checkout@v2
  208. - name: Prepare test blacklist
  209. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  210. - name: Run SyTest
  211. run: /bootstrap.sh synapse
  212. working-directory: /src
  213. - name: Summarise results.tap
  214. if: ${{ always() }}
  215. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  216. - name: Upload SyTest logs
  217. uses: actions/upload-artifact@v2
  218. if: ${{ always() }}
  219. with:
  220. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.*, ', ') }})
  221. path: |
  222. /logs/results.tap
  223. /logs/**/*.log*
  224. export-data:
  225. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  226. needs: [linting-done, portdb]
  227. runs-on: ubuntu-latest
  228. env:
  229. TOP: ${{ github.workspace }}
  230. services:
  231. postgres:
  232. image: postgres
  233. ports:
  234. - 5432:5432
  235. env:
  236. POSTGRES_PASSWORD: "postgres"
  237. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  238. options: >-
  239. --health-cmd pg_isready
  240. --health-interval 10s
  241. --health-timeout 5s
  242. --health-retries 5
  243. steps:
  244. - uses: actions/checkout@v2
  245. - run: sudo apt-get -qq install xmlsec1
  246. - uses: matrix-org/setup-python-poetry@v1
  247. with:
  248. python-version: ${{ matrix.python-version }}
  249. extras: "postgres"
  250. - run: .ci/scripts/test_export_data_command.sh
  251. portdb:
  252. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  253. needs: linting-done
  254. runs-on: ubuntu-latest
  255. env:
  256. TOP: ${{ github.workspace }}
  257. strategy:
  258. matrix:
  259. include:
  260. - python-version: "3.7"
  261. postgres-version: "10"
  262. - python-version: "3.10"
  263. postgres-version: "14"
  264. services:
  265. postgres:
  266. image: postgres:${{ matrix.postgres-version }}
  267. ports:
  268. - 5432:5432
  269. env:
  270. POSTGRES_PASSWORD: "postgres"
  271. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  272. options: >-
  273. --health-cmd pg_isready
  274. --health-interval 10s
  275. --health-timeout 5s
  276. --health-retries 5
  277. steps:
  278. - uses: actions/checkout@v2
  279. - run: sudo apt-get -qq install xmlsec1
  280. - uses: matrix-org/setup-python-poetry@v1
  281. with:
  282. python-version: ${{ matrix.python-version }}
  283. extras: "postgres"
  284. - run: .ci/scripts/test_synapse_port_db.sh
  285. complement:
  286. if: "${{ !failure() && !cancelled() }}"
  287. needs: linting-done
  288. runs-on: ubuntu-latest
  289. strategy:
  290. fail-fast: false
  291. matrix:
  292. include:
  293. - arrangement: monolith
  294. database: SQLite
  295. - arrangement: monolith
  296. database: Postgres
  297. - arrangement: workers
  298. database: Postgres
  299. steps:
  300. - name: Run actions/checkout@v2 for synapse
  301. uses: actions/checkout@v2
  302. with:
  303. path: synapse
  304. - name: Prepare Complement's Prerequisites
  305. run: synapse/.ci/scripts/setup_complement_prerequisites.sh
  306. - run: |
  307. set -o pipefail
  308. POSTGRES=${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS=${{ (matrix.arrangement == 'workers') && 1 || '' }} COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | gotestfmt
  309. shell: bash
  310. name: Run Complement Tests
  311. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  312. tests-done:
  313. if: ${{ always() }}
  314. needs:
  315. - check-sampleconfig
  316. - lint
  317. - lint-crlf
  318. - lint-newsfile
  319. - trial
  320. - trial-olddeps
  321. - sytest
  322. - export-data
  323. - portdb
  324. - complement
  325. runs-on: ubuntu-latest
  326. steps:
  327. - uses: matrix-org/done-action@v2
  328. with:
  329. needs: ${{ toJSON(needs) }}
  330. # The newsfile lint may be skipped on non PR builds
  331. skippable:
  332. lint-newsfile