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.
 
 
 
 
 
 

509 lines
15 KiB

  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. # Job to detect what has changed so we don't run e.g. Rust checks on PRs that
  11. # don't modify Rust code.
  12. changes:
  13. runs-on: ubuntu-latest
  14. outputs:
  15. rust: ${{ !startsWith(github.ref, 'refs/pull/') || steps.filter.outputs.rust }}
  16. steps:
  17. - uses: dorny/paths-filter@v2
  18. id: filter
  19. # We only check on PRs
  20. if: startsWith(github.ref, 'refs/pull/')
  21. with:
  22. filters: |
  23. rust:
  24. - 'rust/**'
  25. - 'Cargo.toml'
  26. check-sampleconfig:
  27. runs-on: ubuntu-latest
  28. steps:
  29. - uses: actions/checkout@v2
  30. - uses: actions/setup-python@v2
  31. - uses: matrix-org/setup-python-poetry@v1
  32. with:
  33. extras: "all"
  34. - run: poetry run scripts-dev/generate_sample_config.sh --check
  35. - run: poetry run scripts-dev/config-lint.sh
  36. check-schema-delta:
  37. runs-on: ubuntu-latest
  38. steps:
  39. - uses: actions/checkout@v2
  40. - uses: actions/setup-python@v2
  41. - run: "pip install 'click==8.1.1' 'GitPython>=3.1.20'"
  42. - run: scripts-dev/check_schema_delta.py --force-colors
  43. lint:
  44. uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
  45. with:
  46. typechecking-extras: "all"
  47. lint-crlf:
  48. runs-on: ubuntu-latest
  49. steps:
  50. - uses: actions/checkout@v2
  51. - name: Check line endings
  52. run: scripts-dev/check_line_terminators.sh
  53. lint-newsfile:
  54. if: ${{ github.base_ref == 'develop' || contains(github.base_ref, 'release-') }}
  55. runs-on: ubuntu-latest
  56. steps:
  57. - uses: actions/checkout@v2
  58. with:
  59. ref: ${{ github.event.pull_request.head.sha }}
  60. fetch-depth: 0
  61. - uses: actions/setup-python@v2
  62. - run: "pip install 'towncrier>=18.6.0rc1'"
  63. - run: scripts-dev/check-newsfragment.sh
  64. env:
  65. PULL_REQUEST_NUMBER: ${{ github.event.number }}
  66. lint-pydantic:
  67. runs-on: ubuntu-latest
  68. steps:
  69. - uses: actions/checkout@v2
  70. with:
  71. ref: ${{ github.event.pull_request.head.sha }}
  72. - uses: matrix-org/setup-python-poetry@v1
  73. with:
  74. extras: "all"
  75. - run: poetry run scripts-dev/check_pydantic_models.py
  76. lint-clippy:
  77. runs-on: ubuntu-latest
  78. needs: changes
  79. if: ${{ needs.changes.outputs.rust == 'true' }}
  80. steps:
  81. - uses: actions/checkout@v2
  82. - name: Install Rust
  83. uses: actions-rs/toolchain@v1
  84. with:
  85. toolchain: 1.58.1
  86. override: true
  87. components: clippy
  88. - uses: Swatinem/rust-cache@v2
  89. - run: cargo clippy
  90. lint-rustfmt:
  91. runs-on: ubuntu-latest
  92. needs: changes
  93. if: ${{ needs.changes.outputs.rust == 'true' }}
  94. steps:
  95. - uses: actions/checkout@v2
  96. - name: Install Rust
  97. uses: actions-rs/toolchain@v1
  98. with:
  99. toolchain: 1.58.1
  100. override: true
  101. components: rustfmt
  102. - uses: Swatinem/rust-cache@v2
  103. - run: cargo fmt --check
  104. # Dummy step to gate other tests on without repeating the whole list
  105. linting-done:
  106. if: ${{ !cancelled() }} # Run this even if prior jobs were skipped
  107. needs:
  108. - lint
  109. - lint-crlf
  110. - lint-newsfile
  111. - lint-pydantic
  112. - check-sampleconfig
  113. - check-schema-delta
  114. - lint-clippy
  115. - lint-rustfmt
  116. runs-on: ubuntu-latest
  117. steps:
  118. - run: "true"
  119. calculate-test-jobs:
  120. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  121. needs: linting-done
  122. runs-on: ubuntu-latest
  123. steps:
  124. - uses: actions/checkout@v2
  125. - uses: actions/setup-python@v2
  126. - id: get-matrix
  127. run: .ci/scripts/calculate_jobs.py
  128. outputs:
  129. trial_test_matrix: ${{ steps.get-matrix.outputs.trial_test_matrix }}
  130. sytest_test_matrix: ${{ steps.get-matrix.outputs.sytest_test_matrix }}
  131. trial:
  132. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  133. needs: calculate-test-jobs
  134. runs-on: ubuntu-latest
  135. strategy:
  136. matrix:
  137. job: ${{ fromJson(needs.calculate-test-jobs.outputs.trial_test_matrix) }}
  138. steps:
  139. - uses: actions/checkout@v2
  140. - run: sudo apt-get -qq install xmlsec1
  141. - name: Set up PostgreSQL ${{ matrix.job.postgres-version }}
  142. if: ${{ matrix.job.postgres-version }}
  143. run: |
  144. docker run -d -p 5432:5432 \
  145. -e POSTGRES_PASSWORD=postgres \
  146. -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \
  147. postgres:${{ matrix.job.postgres-version }}
  148. - uses: matrix-org/setup-python-poetry@v1
  149. with:
  150. python-version: ${{ matrix.job.python-version }}
  151. extras: ${{ matrix.job.extras }}
  152. - name: Await PostgreSQL
  153. if: ${{ matrix.job.postgres-version }}
  154. timeout-minutes: 2
  155. run: until pg_isready -h localhost; do sleep 1; done
  156. - run: poetry run trial --jobs=2 tests
  157. env:
  158. SYNAPSE_POSTGRES: ${{ matrix.job.database == 'postgres' || '' }}
  159. SYNAPSE_POSTGRES_HOST: localhost
  160. SYNAPSE_POSTGRES_USER: postgres
  161. SYNAPSE_POSTGRES_PASSWORD: postgres
  162. - name: Dump logs
  163. # Logs are most useful when the command fails, always include them.
  164. if: ${{ always() }}
  165. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  166. # This keeps logs colocated with failing jobs
  167. # It also ignores find's exit code; this is a best effort affair
  168. run: >-
  169. find _trial_temp -name '*.log'
  170. -exec echo "::group::{}" \;
  171. -exec cat {} \;
  172. -exec echo "::endgroup::" \;
  173. || true
  174. trial-olddeps:
  175. # Note: sqlite only; no postgres
  176. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  177. needs: linting-done
  178. runs-on: ubuntu-20.04
  179. steps:
  180. - uses: actions/checkout@v2
  181. - name: Install Rust
  182. uses: actions-rs/toolchain@v1
  183. with:
  184. toolchain: 1.58.1
  185. override: true
  186. - uses: Swatinem/rust-cache@v2
  187. # There aren't wheels for some of the older deps, so we need to install
  188. # their build dependencies
  189. - run: |
  190. sudo apt-get -qq install build-essential libffi-dev python-dev \
  191. libxml2-dev libxslt-dev xmlsec1 zlib1g-dev libjpeg-dev libwebp-dev
  192. - uses: actions/setup-python@v4
  193. with:
  194. python-version: '3.7'
  195. # Calculating the old-deps actually takes a bunch of time, so we cache the
  196. # pyproject.toml / poetry.lock. We need to cache pyproject.toml as
  197. # otherwise the `poetry install` step will error due to the poetry.lock
  198. # file being outdated.
  199. #
  200. # This caches the output of `Prepare old deps`, which should generate the
  201. # same `pyproject.toml` and `poetry.lock` for a given `pyproject.toml` input.
  202. - uses: actions/cache@v3
  203. id: cache-poetry-old-deps
  204. name: Cache poetry.lock
  205. with:
  206. path: |
  207. poetry.lock
  208. pyproject.toml
  209. key: poetry-old-deps2-${{ hashFiles('pyproject.toml') }}
  210. - name: Prepare old deps
  211. if: steps.cache-poetry-old-deps.outputs.cache-hit != 'true'
  212. run: .ci/scripts/prepare_old_deps.sh
  213. # We only now install poetry so that `setup-python-poetry` caches the
  214. # right poetry.lock's dependencies.
  215. - uses: matrix-org/setup-python-poetry@v1
  216. with:
  217. python-version: '3.7'
  218. extras: "all test"
  219. - run: poetry run trial -j2 tests
  220. - name: Dump logs
  221. # Logs are most useful when the command fails, always include them.
  222. if: ${{ always() }}
  223. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  224. # This keeps logs colocated with failing jobs
  225. # It also ignores find's exit code; this is a best effort affair
  226. run: >-
  227. find _trial_temp -name '*.log'
  228. -exec echo "::group::{}" \;
  229. -exec cat {} \;
  230. -exec echo "::endgroup::" \;
  231. || true
  232. trial-pypy:
  233. # Very slow; only run if the branch name includes 'pypy'
  234. # Note: sqlite only; no postgres. Completely untested since poetry move.
  235. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  236. needs: linting-done
  237. runs-on: ubuntu-latest
  238. strategy:
  239. matrix:
  240. python-version: ["pypy-3.7"]
  241. extras: ["all"]
  242. steps:
  243. - uses: actions/checkout@v2
  244. # Install libs necessary for PyPy to build binary wheels for dependencies
  245. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  246. - uses: matrix-org/setup-python-poetry@v1
  247. with:
  248. python-version: ${{ matrix.python-version }}
  249. extras: ${{ matrix.extras }}
  250. - run: poetry run trial --jobs=2 tests
  251. - name: Dump logs
  252. # Logs are most useful when the command fails, always include them.
  253. if: ${{ always() }}
  254. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  255. # This keeps logs colocated with failing jobs
  256. # It also ignores find's exit code; this is a best effort affair
  257. run: >-
  258. find _trial_temp -name '*.log'
  259. -exec echo "::group::{}" \;
  260. -exec cat {} \;
  261. -exec echo "::endgroup::" \;
  262. || true
  263. sytest:
  264. if: ${{ !failure() && !cancelled() }}
  265. needs: calculate-test-jobs
  266. runs-on: ubuntu-latest
  267. container:
  268. image: matrixdotorg/sytest-synapse:${{ matrix.job.sytest-tag }}
  269. volumes:
  270. - ${{ github.workspace }}:/src
  271. env:
  272. SYTEST_BRANCH: ${{ github.head_ref }}
  273. POSTGRES: ${{ matrix.job.postgres && 1}}
  274. MULTI_POSTGRES: ${{ (matrix.job.postgres == 'multi-postgres') && 1}}
  275. WORKERS: ${{ matrix.job.workers && 1 }}
  276. BLACKLIST: ${{ matrix.job.workers && 'synapse-blacklist-with-workers' }}
  277. TOP: ${{ github.workspace }}
  278. strategy:
  279. fail-fast: false
  280. matrix:
  281. job: ${{ fromJson(needs.calculate-test-jobs.outputs.sytest_test_matrix) }}
  282. steps:
  283. - uses: actions/checkout@v2
  284. - name: Prepare test blacklist
  285. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  286. - name: Install Rust
  287. uses: actions-rs/toolchain@v1
  288. with:
  289. toolchain: 1.58.1
  290. override: true
  291. - uses: Swatinem/rust-cache@v2
  292. - name: Run SyTest
  293. run: /bootstrap.sh synapse
  294. working-directory: /src
  295. - name: Summarise results.tap
  296. if: ${{ always() }}
  297. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  298. - name: Upload SyTest logs
  299. uses: actions/upload-artifact@v2
  300. if: ${{ always() }}
  301. with:
  302. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.job.*, ', ') }})
  303. path: |
  304. /logs/results.tap
  305. /logs/**/*.log*
  306. export-data:
  307. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  308. needs: [linting-done, portdb]
  309. runs-on: ubuntu-latest
  310. env:
  311. TOP: ${{ github.workspace }}
  312. services:
  313. postgres:
  314. image: postgres
  315. ports:
  316. - 5432:5432
  317. env:
  318. POSTGRES_PASSWORD: "postgres"
  319. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  320. options: >-
  321. --health-cmd pg_isready
  322. --health-interval 10s
  323. --health-timeout 5s
  324. --health-retries 5
  325. steps:
  326. - uses: actions/checkout@v2
  327. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  328. - uses: matrix-org/setup-python-poetry@v1
  329. with:
  330. extras: "postgres"
  331. - run: .ci/scripts/test_export_data_command.sh
  332. env:
  333. PGHOST: localhost
  334. PGUSER: postgres
  335. PGPASSWORD: postgres
  336. PGDATABASE: postgres
  337. portdb:
  338. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  339. needs: linting-done
  340. runs-on: ubuntu-latest
  341. strategy:
  342. matrix:
  343. include:
  344. - python-version: "3.7"
  345. postgres-version: "10"
  346. - python-version: "3.10"
  347. postgres-version: "14"
  348. services:
  349. postgres:
  350. image: postgres:${{ matrix.postgres-version }}
  351. ports:
  352. - 5432:5432
  353. env:
  354. POSTGRES_PASSWORD: "postgres"
  355. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  356. options: >-
  357. --health-cmd pg_isready
  358. --health-interval 10s
  359. --health-timeout 5s
  360. --health-retries 5
  361. steps:
  362. - uses: actions/checkout@v2
  363. - run: sudo apt-get -qq install xmlsec1 postgresql-client
  364. - uses: matrix-org/setup-python-poetry@v1
  365. with:
  366. python-version: ${{ matrix.python-version }}
  367. extras: "postgres"
  368. - run: .ci/scripts/test_synapse_port_db.sh
  369. id: run_tester_script
  370. env:
  371. PGHOST: localhost
  372. PGUSER: postgres
  373. PGPASSWORD: postgres
  374. PGDATABASE: postgres
  375. - name: "Upload schema differences"
  376. uses: actions/upload-artifact@v3
  377. if: ${{ failure() && !cancelled() && steps.run_tester_script.outcome == 'failure' }}
  378. with:
  379. name: Schema dumps
  380. path: |
  381. unported.sql
  382. ported.sql
  383. schema_diff
  384. complement:
  385. if: "${{ !failure() && !cancelled() }}"
  386. needs: linting-done
  387. runs-on: ubuntu-latest
  388. strategy:
  389. fail-fast: false
  390. matrix:
  391. include:
  392. - arrangement: monolith
  393. database: SQLite
  394. - arrangement: monolith
  395. database: Postgres
  396. - arrangement: workers
  397. database: Postgres
  398. steps:
  399. - name: Run actions/checkout@v2 for synapse
  400. uses: actions/checkout@v2
  401. with:
  402. path: synapse
  403. - name: Install Rust
  404. uses: actions-rs/toolchain@v1
  405. with:
  406. toolchain: 1.58.1
  407. override: true
  408. - uses: Swatinem/rust-cache@v2
  409. - name: Prepare Complement's Prerequisites
  410. run: synapse/.ci/scripts/setup_complement_prerequisites.sh
  411. - run: |
  412. set -o pipefail
  413. POSTGRES=${{ (matrix.database == 'Postgres') && 1 || '' }} WORKERS=${{ (matrix.arrangement == 'workers') && 1 || '' }} COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt
  414. shell: bash
  415. name: Run Complement Tests
  416. cargo-test:
  417. if: ${{ needs.changes.outputs.rust == 'true' }}
  418. runs-on: ubuntu-latest
  419. needs:
  420. - linting-done
  421. - changes
  422. steps:
  423. - uses: actions/checkout@v2
  424. - name: Install Rust
  425. uses: actions-rs/toolchain@v1
  426. with:
  427. toolchain: 1.58.1
  428. override: true
  429. - uses: Swatinem/rust-cache@v2
  430. - run: cargo test
  431. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  432. tests-done:
  433. if: ${{ always() }}
  434. needs:
  435. - trial
  436. - trial-olddeps
  437. - sytest
  438. - export-data
  439. - portdb
  440. - complement
  441. - cargo-test
  442. runs-on: ubuntu-latest
  443. steps:
  444. - uses: matrix-org/done-action@v2
  445. with:
  446. needs: ${{ toJSON(needs) }}
  447. # The newsfile lint may be skipped on non PR builds
  448. # Cargo test is skipped if there is no changes on Rust code
  449. skippable: |
  450. lint-newsfile
  451. cargo-test