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.
 
 
 
 
 
 

510 rivejä
15 KiB

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