tests.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. name: Tests
  2. on:
  3. push:
  4. branches: ["develop", "release-*"]
  5. pull_request:
  6. merge_group:
  7. workflow_dispatch:
  8. concurrency:
  9. group: ${{ github.workflow }}-${{ github.ref }}
  10. cancel-in-progress: true
  11. jobs:
  12. # Job to detect what has changed so we don't run e.g. Rust checks on PRs that
  13. # don't modify Rust code.
  14. changes:
  15. runs-on: ubuntu-latest
  16. outputs:
  17. rust: ${{ !startsWith(github.ref, 'refs/pull/') || steps.filter.outputs.rust }}
  18. steps:
  19. - uses: dorny/paths-filter@v2
  20. id: filter
  21. # We only check on PRs
  22. if: startsWith(github.ref, 'refs/pull/')
  23. with:
  24. filters: |
  25. rust:
  26. - 'rust/**'
  27. - 'Cargo.toml'
  28. - 'Cargo.lock'
  29. check-sampleconfig:
  30. runs-on: ubuntu-latest
  31. steps:
  32. - uses: actions/checkout@v3
  33. - name: Install Rust
  34. uses: dtolnay/rust-toolchain@1.58.1
  35. - uses: Swatinem/rust-cache@v2
  36. - uses: matrix-org/setup-python-poetry@v1
  37. with:
  38. python-version: "3.x"
  39. poetry-version: "1.3.2"
  40. extras: "all"
  41. - run: poetry run scripts-dev/generate_sample_config.sh --check
  42. - run: poetry run scripts-dev/config-lint.sh
  43. check-schema-delta:
  44. runs-on: ubuntu-latest
  45. steps:
  46. - uses: actions/checkout@v3
  47. - uses: actions/setup-python@v4
  48. with:
  49. python-version: "3.x"
  50. - run: "pip install 'click==8.1.1' 'GitPython>=3.1.20'"
  51. - run: scripts-dev/check_schema_delta.py --force-colors
  52. check-lockfile:
  53. runs-on: ubuntu-latest
  54. steps:
  55. - uses: actions/checkout@v3
  56. - uses: actions/setup-python@v4
  57. with:
  58. python-version: "3.x"
  59. - run: .ci/scripts/check_lockfile.py
  60. lint:
  61. runs-on: ubuntu-latest
  62. steps:
  63. - name: Checkout repository
  64. uses: actions/checkout@v3
  65. - name: Setup Poetry
  66. uses: matrix-org/setup-python-poetry@v1
  67. with:
  68. install-project: "false"
  69. - name: Import order (isort)
  70. run: poetry run isort --check --diff .
  71. - name: Code style (black)
  72. run: poetry run black --check --diff .
  73. - name: Semantic checks (ruff)
  74. # --quiet suppresses the update check.
  75. run: poetry run ruff --quiet .
  76. lint-mypy:
  77. runs-on: ubuntu-latest
  78. name: Typechecking
  79. steps:
  80. - name: Checkout repository
  81. uses: actions/checkout@v3
  82. - name: Setup Poetry
  83. uses: matrix-org/setup-python-poetry@v1
  84. with:
  85. # We want to make use of type hints in optional dependencies too.
  86. extras: all
  87. # We have seen odd mypy failures that were resolved when we started
  88. # installing the project again:
  89. # https://github.com/matrix-org/synapse/pull/15376#issuecomment-1498983775
  90. # To make CI green, err towards caution and install the project.
  91. install-project: "true"
  92. - name: Install Rust
  93. uses: dtolnay/rust-toolchain@1.58.1
  94. - uses: Swatinem/rust-cache@v2
  95. # Cribbed from
  96. # https://github.com/AustinScola/mypy-cache-github-action/blob/85ea4f2972abed39b33bd02c36e341b28ca59213/src/restore.ts#L10-L17
  97. - name: Restore/persist mypy's cache
  98. uses: actions/cache@v3
  99. with:
  100. path: |
  101. .mypy_cache
  102. key: mypy-cache-${{ github.context.sha }}
  103. restore-keys: mypy-cache-
  104. - name: Run mypy
  105. run: poetry run mypy
  106. lint-crlf:
  107. runs-on: ubuntu-latest
  108. steps:
  109. - uses: actions/checkout@v3
  110. - name: Check line endings
  111. run: scripts-dev/check_line_terminators.sh
  112. lint-newsfile:
  113. if: ${{ (github.base_ref == 'develop' || contains(github.base_ref, 'release-')) && github.actor != 'dependabot[bot]' }}
  114. runs-on: ubuntu-latest
  115. steps:
  116. - uses: actions/checkout@v3
  117. with:
  118. ref: ${{ github.event.pull_request.head.sha }}
  119. fetch-depth: 0
  120. - uses: actions/setup-python@v4
  121. with:
  122. python-version: "3.x"
  123. - run: "pip install 'towncrier>=18.6.0rc1'"
  124. - run: scripts-dev/check-newsfragment.sh
  125. env:
  126. PULL_REQUEST_NUMBER: ${{ github.event.number }}
  127. lint-pydantic:
  128. runs-on: ubuntu-latest
  129. steps:
  130. - uses: actions/checkout@v3
  131. with:
  132. ref: ${{ github.event.pull_request.head.sha }}
  133. - name: Install Rust
  134. uses: dtolnay/rust-toolchain@1.58.1
  135. - uses: Swatinem/rust-cache@v2
  136. - uses: matrix-org/setup-python-poetry@v1
  137. with:
  138. poetry-version: "1.3.2"
  139. extras: "all"
  140. - run: poetry run scripts-dev/check_pydantic_models.py
  141. lint-clippy:
  142. runs-on: ubuntu-latest
  143. needs: changes
  144. if: ${{ needs.changes.outputs.rust == 'true' }}
  145. steps:
  146. - uses: actions/checkout@v3
  147. - name: Install Rust
  148. uses: dtolnay/rust-toolchain@1.58.1
  149. with:
  150. components: clippy
  151. - uses: Swatinem/rust-cache@v2
  152. - run: cargo clippy -- -D warnings
  153. # We also lint against a nightly rustc so that we can lint the benchmark
  154. # suite, which requires a nightly compiler.
  155. lint-clippy-nightly:
  156. runs-on: ubuntu-latest
  157. needs: changes
  158. if: ${{ needs.changes.outputs.rust == 'true' }}
  159. steps:
  160. - uses: actions/checkout@v3
  161. - name: Install Rust
  162. uses: dtolnay/rust-toolchain@master
  163. with:
  164. toolchain: nightly-2022-12-01
  165. components: clippy
  166. - uses: Swatinem/rust-cache@v2
  167. - run: cargo clippy --all-features -- -D warnings
  168. lint-rustfmt:
  169. runs-on: ubuntu-latest
  170. needs: changes
  171. if: ${{ needs.changes.outputs.rust == 'true' }}
  172. steps:
  173. - uses: actions/checkout@v3
  174. - name: Install Rust
  175. uses: dtolnay/rust-toolchain@master
  176. with:
  177. # We use nightly so that it correctly groups together imports
  178. toolchain: nightly-2022-12-01
  179. components: rustfmt
  180. - uses: Swatinem/rust-cache@v2
  181. - run: cargo fmt --check
  182. # Dummy step to gate other tests on without repeating the whole list
  183. linting-done:
  184. if: ${{ !cancelled() }} # Run this even if prior jobs were skipped
  185. needs:
  186. - lint
  187. - lint-mypy
  188. - lint-crlf
  189. - lint-newsfile
  190. - lint-pydantic
  191. - check-sampleconfig
  192. - check-schema-delta
  193. - check-lockfile
  194. - lint-clippy
  195. - lint-rustfmt
  196. runs-on: ubuntu-latest
  197. steps:
  198. - run: "true"
  199. calculate-test-jobs:
  200. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  201. needs: linting-done
  202. runs-on: ubuntu-latest
  203. steps:
  204. - uses: actions/checkout@v3
  205. - uses: actions/setup-python@v4
  206. with:
  207. python-version: "3.x"
  208. - id: get-matrix
  209. run: .ci/scripts/calculate_jobs.py
  210. outputs:
  211. trial_test_matrix: ${{ steps.get-matrix.outputs.trial_test_matrix }}
  212. sytest_test_matrix: ${{ steps.get-matrix.outputs.sytest_test_matrix }}
  213. trial:
  214. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  215. needs: calculate-test-jobs
  216. runs-on: ubuntu-latest
  217. strategy:
  218. matrix:
  219. job: ${{ fromJson(needs.calculate-test-jobs.outputs.trial_test_matrix) }}
  220. steps:
  221. - uses: actions/checkout@v3
  222. - run: sudo apt-get -qq install xmlsec1
  223. - name: Set up PostgreSQL ${{ matrix.job.postgres-version }}
  224. if: ${{ matrix.job.postgres-version }}
  225. # 1. Mount postgres data files onto a tmpfs in-memory filesystem to reduce overhead of docker's overlayfs layer.
  226. # 2. Expose the unix socket for postgres. This removes latency of using docker-proxy for connections.
  227. run: |
  228. docker run -d -p 5432:5432 \
  229. --tmpfs /var/lib/postgres:rw,size=6144m \
  230. --mount 'type=bind,src=/var/run/postgresql,dst=/var/run/postgresql' \
  231. -e POSTGRES_PASSWORD=postgres \
  232. -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \
  233. postgres:${{ matrix.job.postgres-version }}
  234. - name: Install Rust
  235. uses: dtolnay/rust-toolchain@1.58.1
  236. - uses: Swatinem/rust-cache@v2
  237. - uses: matrix-org/setup-python-poetry@v1
  238. with:
  239. python-version: ${{ matrix.job.python-version }}
  240. poetry-version: "1.3.2"
  241. extras: ${{ matrix.job.extras }}
  242. - name: Await PostgreSQL
  243. if: ${{ matrix.job.postgres-version }}
  244. timeout-minutes: 2
  245. run: until pg_isready -h localhost; do sleep 1; done
  246. - run: poetry run trial --jobs=6 tests
  247. env:
  248. SYNAPSE_POSTGRES: ${{ matrix.job.database == 'postgres' || '' }}
  249. SYNAPSE_POSTGRES_HOST: /var/run/postgresql
  250. SYNAPSE_POSTGRES_USER: postgres
  251. SYNAPSE_POSTGRES_PASSWORD: postgres
  252. - name: Dump logs
  253. # Logs are most useful when the command fails, always include them.
  254. if: ${{ always() }}
  255. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  256. # This keeps logs colocated with failing jobs
  257. # It also ignores find's exit code; this is a best effort affair
  258. run: >-
  259. find _trial_temp -name '*.log'
  260. -exec echo "::group::{}" \;
  261. -exec cat {} \;
  262. -exec echo "::endgroup::" \;
  263. || true
  264. trial-olddeps:
  265. # Note: sqlite only; no postgres
  266. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  267. needs: linting-done
  268. runs-on: ubuntu-20.04
  269. steps:
  270. - uses: actions/checkout@v3
  271. - name: Install Rust
  272. uses: dtolnay/rust-toolchain@1.58.1
  273. - uses: Swatinem/rust-cache@v2
  274. # There aren't wheels for some of the older deps, so we need to install
  275. # their build dependencies
  276. - run: |
  277. sudo apt-get -qq install build-essential libffi-dev python-dev \
  278. libxml2-dev libxslt-dev xmlsec1 zlib1g-dev libjpeg-dev libwebp-dev
  279. - uses: actions/setup-python@v4
  280. with:
  281. python-version: '3.7'
  282. - name: Prepare old deps
  283. if: steps.cache-poetry-old-deps.outputs.cache-hit != 'true'
  284. run: .ci/scripts/prepare_old_deps.sh
  285. # Note: we install using `pip` here, not poetry. `poetry install` ignores the
  286. # build-system section (https://github.com/python-poetry/poetry/issues/6154), but
  287. # we explicitly want to test that you can `pip install` using the oldest version
  288. # of poetry-core and setuptools-rust.
  289. - run: pip install .[all,test]
  290. # We nuke the local copy, as we've installed synapse into the virtualenv
  291. # (rather than use an editable install, which we no longer support). If we
  292. # don't do this then python can't find the native lib.
  293. - run: rm -rf synapse/
  294. # Sanity check we can import/run Synapse
  295. - run: python -m synapse.app.homeserver --help
  296. - run: python -m twisted.trial -j6 tests
  297. - name: Dump logs
  298. # Logs are most useful when the command fails, always include them.
  299. if: ${{ always() }}
  300. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  301. # This keeps logs colocated with failing jobs
  302. # It also ignores find's exit code; this is a best effort affair
  303. run: >-
  304. find _trial_temp -name '*.log'
  305. -exec echo "::group::{}" \;
  306. -exec cat {} \;
  307. -exec echo "::endgroup::" \;
  308. || true
  309. trial-pypy:
  310. # Very slow; only run if the branch name includes 'pypy'
  311. # Note: sqlite only; no postgres. Completely untested since poetry move.
  312. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  313. needs: linting-done
  314. runs-on: ubuntu-latest
  315. strategy:
  316. matrix:
  317. python-version: ["pypy-3.7"]
  318. extras: ["all"]
  319. steps:
  320. - uses: actions/checkout@v3
  321. # Install libs necessary for PyPy to build binary wheels for dependencies
  322. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  323. - uses: matrix-org/setup-python-poetry@v1
  324. with:
  325. python-version: ${{ matrix.python-version }}
  326. poetry-version: "1.3.2"
  327. extras: ${{ matrix.extras }}
  328. - run: poetry run trial --jobs=2 tests
  329. - name: Dump logs
  330. # Logs are most useful when the command fails, always include them.
  331. if: ${{ always() }}
  332. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  333. # This keeps logs colocated with failing jobs
  334. # It also ignores find's exit code; this is a best effort affair
  335. run: >-
  336. find _trial_temp -name '*.log'
  337. -exec echo "::group::{}" \;
  338. -exec cat {} \;
  339. -exec echo "::endgroup::" \;
  340. || true
  341. sytest:
  342. if: ${{ !failure() && !cancelled() }}
  343. needs: calculate-test-jobs
  344. runs-on: ubuntu-latest
  345. container:
  346. image: matrixdotorg/sytest-synapse:${{ matrix.job.sytest-tag }}
  347. volumes:
  348. - ${{ github.workspace }}:/src
  349. env:
  350. SYTEST_BRANCH: ${{ github.head_ref }}
  351. POSTGRES: ${{ matrix.job.postgres && 1}}
  352. MULTI_POSTGRES: ${{ (matrix.job.postgres == 'multi-postgres') && 1}}
  353. ASYNCIO_REACTOR: ${{ (matrix.job.reactor == 'asyncio') && 1 }}
  354. WORKERS: ${{ matrix.job.workers && 1 }}
  355. BLACKLIST: ${{ matrix.job.workers && 'synapse-blacklist-with-workers' }}
  356. TOP: ${{ github.workspace }}
  357. strategy:
  358. fail-fast: false
  359. matrix:
  360. job: ${{ fromJson(needs.calculate-test-jobs.outputs.sytest_test_matrix) }}
  361. steps:
  362. - uses: actions/checkout@v3
  363. - name: Prepare test blacklist
  364. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  365. - name: Install Rust
  366. uses: dtolnay/rust-toolchain@1.58.1
  367. - uses: Swatinem/rust-cache@v2
  368. - name: Run SyTest
  369. run: /bootstrap.sh synapse
  370. working-directory: /src
  371. - name: Summarise results.tap
  372. if: ${{ always() }}
  373. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  374. - name: Upload SyTest logs
  375. uses: actions/upload-artifact@v3
  376. if: ${{ always() }}
  377. with:
  378. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.job.*, ', ') }})
  379. path: |
  380. /logs/results.tap
  381. /logs/**/*.log*
  382. export-data:
  383. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  384. needs: [linting-done, portdb]
  385. runs-on: ubuntu-latest
  386. env:
  387. TOP: ${{ github.workspace }}
  388. services:
  389. postgres:
  390. image: postgres
  391. ports:
  392. - 5432:5432
  393. env:
  394. POSTGRES_PASSWORD: "postgres"
  395. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  396. options: >-
  397. --health-cmd pg_isready
  398. --health-interval 10s
  399. --health-timeout 5s
  400. --health-retries 5
  401. steps:
  402. - uses: actions/checkout@v3
  403. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  404. - uses: matrix-org/setup-python-poetry@v1
  405. with:
  406. poetry-version: "1.3.2"
  407. extras: "postgres"
  408. - run: .ci/scripts/test_export_data_command.sh
  409. env:
  410. PGHOST: localhost
  411. PGUSER: postgres
  412. PGPASSWORD: postgres
  413. PGDATABASE: postgres
  414. portdb:
  415. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  416. needs: linting-done
  417. runs-on: ubuntu-latest
  418. strategy:
  419. matrix:
  420. include:
  421. - python-version: "3.7"
  422. postgres-version: "11"
  423. - python-version: "3.11"
  424. postgres-version: "15"
  425. services:
  426. postgres:
  427. image: postgres:${{ matrix.postgres-version }}
  428. ports:
  429. - 5432:5432
  430. env:
  431. POSTGRES_PASSWORD: "postgres"
  432. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  433. options: >-
  434. --health-cmd pg_isready
  435. --health-interval 10s
  436. --health-timeout 5s
  437. --health-retries 5
  438. steps:
  439. - uses: actions/checkout@v3
  440. - name: Add PostgreSQL apt repository
  441. # We need a version of pg_dump that can handle the version of
  442. # PostgreSQL being tested against. The Ubuntu package repository lags
  443. # behind new releases, so we have to use the PostreSQL apt repository.
  444. # Steps taken from https://www.postgresql.org/download/linux/ubuntu/
  445. run: |
  446. sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  447. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  448. sudo apt-get update
  449. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  450. - uses: matrix-org/setup-python-poetry@v1
  451. with:
  452. python-version: ${{ matrix.python-version }}
  453. poetry-version: "1.3.2"
  454. extras: "postgres"
  455. - run: .ci/scripts/test_synapse_port_db.sh
  456. id: run_tester_script
  457. env:
  458. PGHOST: localhost
  459. PGUSER: postgres
  460. PGPASSWORD: postgres
  461. PGDATABASE: postgres
  462. - name: "Upload schema differences"
  463. uses: actions/upload-artifact@v3
  464. if: ${{ failure() && !cancelled() && steps.run_tester_script.outcome == 'failure' }}
  465. with:
  466. name: Schema dumps
  467. path: |
  468. unported.sql
  469. ported.sql
  470. schema_diff
  471. complement:
  472. if: "${{ !failure() && !cancelled() }}"
  473. needs: linting-done
  474. runs-on: ubuntu-latest
  475. strategy:
  476. fail-fast: false
  477. matrix:
  478. include:
  479. - arrangement: monolith
  480. database: SQLite
  481. - arrangement: monolith
  482. database: Postgres
  483. - arrangement: workers
  484. database: Postgres
  485. steps:
  486. - name: Run actions/checkout@v3 for synapse
  487. uses: actions/checkout@v3
  488. with:
  489. path: synapse
  490. - name: Install Rust
  491. uses: dtolnay/rust-toolchain@1.58.1
  492. - uses: Swatinem/rust-cache@v2
  493. - uses: actions/setup-go@v4
  494. - name: Prepare Complement's Prerequisites
  495. run: synapse/.ci/scripts/setup_complement_prerequisites.sh
  496. - run: |
  497. set -o pipefail
  498. COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt
  499. shell: bash
  500. env:
  501. POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }}
  502. WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }}
  503. name: Run Complement Tests
  504. cargo-test:
  505. if: ${{ needs.changes.outputs.rust == 'true' }}
  506. runs-on: ubuntu-latest
  507. needs:
  508. - linting-done
  509. - changes
  510. steps:
  511. - uses: actions/checkout@v3
  512. - name: Install Rust
  513. uses: dtolnay/rust-toolchain@1.58.1
  514. - uses: Swatinem/rust-cache@v2
  515. - run: cargo test
  516. # We want to ensure that the cargo benchmarks still compile, which requires a
  517. # nightly compiler.
  518. cargo-bench:
  519. if: ${{ needs.changes.outputs.rust == 'true' }}
  520. runs-on: ubuntu-latest
  521. needs:
  522. - linting-done
  523. - changes
  524. steps:
  525. - uses: actions/checkout@v3
  526. - name: Install Rust
  527. uses: dtolnay/rust-toolchain@master
  528. with:
  529. toolchain: nightly-2022-12-01
  530. - uses: Swatinem/rust-cache@v2
  531. - run: cargo bench --no-run
  532. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  533. tests-done:
  534. if: ${{ always() }}
  535. needs:
  536. - trial
  537. - trial-olddeps
  538. - sytest
  539. - export-data
  540. - portdb
  541. - complement
  542. - cargo-test
  543. - cargo-bench
  544. runs-on: ubuntu-latest
  545. steps:
  546. - uses: matrix-org/done-action@v2
  547. with:
  548. needs: ${{ toJSON(needs) }}
  549. # The newsfile lint may be skipped on non PR builds
  550. # Cargo test is skipped if there is no changes on Rust code
  551. skippable: |
  552. lint-newsfile
  553. cargo-test
  554. cargo-bench