You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

636 lines
20 KiB

  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.60.0
  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: Install Rust
  83. uses: dtolnay/rust-toolchain@1.60.0
  84. - uses: Swatinem/rust-cache@v2
  85. - name: Setup Poetry
  86. uses: matrix-org/setup-python-poetry@v1
  87. with:
  88. # We want to make use of type hints in optional dependencies too.
  89. extras: all
  90. # We have seen odd mypy failures that were resolved when we started
  91. # installing the project again:
  92. # https://github.com/matrix-org/synapse/pull/15376#issuecomment-1498983775
  93. # To make CI green, err towards caution and install the project.
  94. install-project: "true"
  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.60.0
  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.60.0
  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.60.0
  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.60.0
  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 update
  278. sudo apt-get -qq install build-essential libffi-dev python-dev \
  279. libxml2-dev libxslt-dev xmlsec1 zlib1g-dev libjpeg-dev libwebp-dev
  280. - uses: actions/setup-python@v4
  281. with:
  282. python-version: '3.8'
  283. - name: Prepare old deps
  284. if: steps.cache-poetry-old-deps.outputs.cache-hit != 'true'
  285. run: .ci/scripts/prepare_old_deps.sh
  286. # Note: we install using `pip` here, not poetry. `poetry install` ignores the
  287. # build-system section (https://github.com/python-poetry/poetry/issues/6154), but
  288. # we explicitly want to test that you can `pip install` using the oldest version
  289. # of poetry-core and setuptools-rust.
  290. - run: pip install .[all,test]
  291. # We nuke the local copy, as we've installed synapse into the virtualenv
  292. # (rather than use an editable install, which we no longer support). If we
  293. # don't do this then python can't find the native lib.
  294. - run: rm -rf synapse/
  295. # Sanity check we can import/run Synapse
  296. - run: python -m synapse.app.homeserver --help
  297. - run: python -m twisted.trial -j6 tests
  298. - name: Dump logs
  299. # Logs are most useful when the command fails, always include them.
  300. if: ${{ always() }}
  301. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  302. # This keeps logs colocated with failing jobs
  303. # It also ignores find's exit code; this is a best effort affair
  304. run: >-
  305. find _trial_temp -name '*.log'
  306. -exec echo "::group::{}" \;
  307. -exec cat {} \;
  308. -exec echo "::endgroup::" \;
  309. || true
  310. trial-pypy:
  311. # Very slow; only run if the branch name includes 'pypy'
  312. # Note: sqlite only; no postgres. Completely untested since poetry move.
  313. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  314. needs: linting-done
  315. runs-on: ubuntu-latest
  316. strategy:
  317. matrix:
  318. python-version: ["pypy-3.8"]
  319. extras: ["all"]
  320. steps:
  321. - uses: actions/checkout@v3
  322. # Install libs necessary for PyPy to build binary wheels for dependencies
  323. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  324. - uses: matrix-org/setup-python-poetry@v1
  325. with:
  326. python-version: ${{ matrix.python-version }}
  327. poetry-version: "1.3.2"
  328. extras: ${{ matrix.extras }}
  329. - run: poetry run trial --jobs=2 tests
  330. - name: Dump logs
  331. # Logs are most useful when the command fails, always include them.
  332. if: ${{ always() }}
  333. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  334. # This keeps logs colocated with failing jobs
  335. # It also ignores find's exit code; this is a best effort affair
  336. run: >-
  337. find _trial_temp -name '*.log'
  338. -exec echo "::group::{}" \;
  339. -exec cat {} \;
  340. -exec echo "::endgroup::" \;
  341. || true
  342. sytest:
  343. if: ${{ !failure() && !cancelled() }}
  344. needs: calculate-test-jobs
  345. runs-on: ubuntu-latest
  346. container:
  347. image: matrixdotorg/sytest-synapse:${{ matrix.job.sytest-tag }}
  348. volumes:
  349. - ${{ github.workspace }}:/src
  350. env:
  351. SYTEST_BRANCH: ${{ github.head_ref }}
  352. POSTGRES: ${{ matrix.job.postgres && 1}}
  353. MULTI_POSTGRES: ${{ (matrix.job.postgres == 'multi-postgres') || '' }}
  354. ASYNCIO_REACTOR: ${{ (matrix.job.reactor == 'asyncio') || '' }}
  355. WORKERS: ${{ matrix.job.workers && 1 }}
  356. BLACKLIST: ${{ matrix.job.workers && 'synapse-blacklist-with-workers' }}
  357. TOP: ${{ github.workspace }}
  358. strategy:
  359. fail-fast: false
  360. matrix:
  361. job: ${{ fromJson(needs.calculate-test-jobs.outputs.sytest_test_matrix) }}
  362. steps:
  363. - uses: actions/checkout@v3
  364. - name: Prepare test blacklist
  365. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  366. - name: Install Rust
  367. uses: dtolnay/rust-toolchain@1.60.0
  368. - uses: Swatinem/rust-cache@v2
  369. - name: Run SyTest
  370. run: /bootstrap.sh synapse
  371. working-directory: /src
  372. - name: Summarise results.tap
  373. if: ${{ always() }}
  374. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  375. - name: Upload SyTest logs
  376. uses: actions/upload-artifact@v3
  377. if: ${{ always() }}
  378. with:
  379. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.job.*, ', ') }})
  380. path: |
  381. /logs/results.tap
  382. /logs/**/*.log*
  383. export-data:
  384. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  385. needs: [linting-done, portdb]
  386. runs-on: ubuntu-latest
  387. env:
  388. TOP: ${{ github.workspace }}
  389. services:
  390. postgres:
  391. image: postgres
  392. ports:
  393. - 5432:5432
  394. env:
  395. POSTGRES_PASSWORD: "postgres"
  396. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  397. options: >-
  398. --health-cmd pg_isready
  399. --health-interval 10s
  400. --health-timeout 5s
  401. --health-retries 5
  402. steps:
  403. - uses: actions/checkout@v3
  404. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  405. - uses: matrix-org/setup-python-poetry@v1
  406. with:
  407. poetry-version: "1.3.2"
  408. extras: "postgres"
  409. - run: .ci/scripts/test_export_data_command.sh
  410. env:
  411. PGHOST: localhost
  412. PGUSER: postgres
  413. PGPASSWORD: postgres
  414. PGDATABASE: postgres
  415. portdb:
  416. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  417. needs: linting-done
  418. runs-on: ubuntu-latest
  419. strategy:
  420. matrix:
  421. include:
  422. - python-version: "3.8"
  423. postgres-version: "11"
  424. - python-version: "3.11"
  425. postgres-version: "15"
  426. services:
  427. postgres:
  428. image: postgres:${{ matrix.postgres-version }}
  429. ports:
  430. - 5432:5432
  431. env:
  432. POSTGRES_PASSWORD: "postgres"
  433. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  434. options: >-
  435. --health-cmd pg_isready
  436. --health-interval 10s
  437. --health-timeout 5s
  438. --health-retries 5
  439. steps:
  440. - uses: actions/checkout@v3
  441. - name: Add PostgreSQL apt repository
  442. # We need a version of pg_dump that can handle the version of
  443. # PostgreSQL being tested against. The Ubuntu package repository lags
  444. # behind new releases, so we have to use the PostreSQL apt repository.
  445. # Steps taken from https://www.postgresql.org/download/linux/ubuntu/
  446. run: |
  447. sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
  448. wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
  449. sudo apt-get update
  450. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  451. - uses: matrix-org/setup-python-poetry@v1
  452. with:
  453. python-version: ${{ matrix.python-version }}
  454. poetry-version: "1.3.2"
  455. extras: "postgres"
  456. - run: .ci/scripts/test_synapse_port_db.sh
  457. id: run_tester_script
  458. env:
  459. PGHOST: localhost
  460. PGUSER: postgres
  461. PGPASSWORD: postgres
  462. PGDATABASE: postgres
  463. - name: "Upload schema differences"
  464. uses: actions/upload-artifact@v3
  465. if: ${{ failure() && !cancelled() && steps.run_tester_script.outcome == 'failure' }}
  466. with:
  467. name: Schema dumps
  468. path: |
  469. unported.sql
  470. ported.sql
  471. schema_diff
  472. complement:
  473. if: "${{ !failure() && !cancelled() }}"
  474. needs: linting-done
  475. runs-on: ubuntu-latest
  476. strategy:
  477. fail-fast: false
  478. matrix:
  479. include:
  480. - arrangement: monolith
  481. database: SQLite
  482. - arrangement: monolith
  483. database: Postgres
  484. - arrangement: workers
  485. database: Postgres
  486. steps:
  487. - name: Run actions/checkout@v3 for synapse
  488. uses: actions/checkout@v3
  489. with:
  490. path: synapse
  491. - name: Install Rust
  492. uses: dtolnay/rust-toolchain@1.60.0
  493. - uses: Swatinem/rust-cache@v2
  494. - uses: actions/setup-go@v4
  495. - name: Prepare Complement's Prerequisites
  496. run: synapse/.ci/scripts/setup_complement_prerequisites.sh
  497. - run: |
  498. set -o pipefail
  499. COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt
  500. shell: bash
  501. env:
  502. POSTGRES: ${{ (matrix.database == 'Postgres') && 1 || '' }}
  503. WORKERS: ${{ (matrix.arrangement == 'workers') && 1 || '' }}
  504. name: Run Complement Tests
  505. cargo-test:
  506. if: ${{ needs.changes.outputs.rust == 'true' }}
  507. runs-on: ubuntu-latest
  508. needs:
  509. - linting-done
  510. - changes
  511. steps:
  512. - uses: actions/checkout@v3
  513. - name: Install Rust
  514. uses: dtolnay/rust-toolchain@1.60.0
  515. - uses: Swatinem/rust-cache@v2
  516. - run: cargo test
  517. # We want to ensure that the cargo benchmarks still compile, which requires a
  518. # nightly compiler.
  519. cargo-bench:
  520. if: ${{ needs.changes.outputs.rust == 'true' }}
  521. runs-on: ubuntu-latest
  522. needs:
  523. - linting-done
  524. - changes
  525. steps:
  526. - uses: actions/checkout@v3
  527. - name: Install Rust
  528. uses: dtolnay/rust-toolchain@master
  529. with:
  530. toolchain: nightly-2022-12-01
  531. - uses: Swatinem/rust-cache@v2
  532. - run: cargo bench --no-run
  533. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  534. tests-done:
  535. if: ${{ always() }}
  536. needs:
  537. - trial
  538. - trial-olddeps
  539. - sytest
  540. - export-data
  541. - portdb
  542. - complement
  543. - cargo-test
  544. - cargo-bench
  545. runs-on: ubuntu-latest
  546. steps:
  547. - uses: matrix-org/done-action@v2
  548. with:
  549. needs: ${{ toJSON(needs) }}
  550. # The newsfile lint may be skipped on non PR builds
  551. # Cargo test is skipped if there is no changes on Rust code
  552. skippable: |
  553. lint-newsfile
  554. cargo-test
  555. cargo-bench