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.
 
 
 
 
 
 

390 lines
13 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. check-sampleconfig:
  11. runs-on: ubuntu-latest
  12. steps:
  13. - uses: actions/checkout@v2
  14. - uses: actions/setup-python@v2
  15. - run: pip install -e .
  16. - run: scripts-dev/generate_sample_config.sh --check
  17. - run: scripts-dev/config-lint.sh
  18. lint:
  19. # This does a vanilla `poetry install` - no extras. I'm slightly anxious
  20. # that we might skip some typechecks on code that uses extras. However,
  21. # I think the right way to fix this is to mark any extras needed for
  22. # typechecking as development dependencies. To detect this, we ought to
  23. # turn up mypy's strictness: disallow unknown imports and be accept fewer
  24. # uses of `Any`.
  25. uses: "matrix-org/backend-meta/.github/workflows/python-poetry-ci.yml@v1"
  26. lint-crlf:
  27. runs-on: ubuntu-latest
  28. steps:
  29. - uses: actions/checkout@v2
  30. - name: Check line endings
  31. run: scripts-dev/check_line_terminators.sh
  32. lint-newsfile:
  33. if: ${{ github.base_ref == 'develop' || contains(github.base_ref, 'release-') }}
  34. runs-on: ubuntu-latest
  35. steps:
  36. - uses: actions/checkout@v2
  37. with:
  38. ref: ${{ github.event.pull_request.head.sha }}
  39. fetch-depth: 0
  40. - uses: actions/setup-python@v2
  41. - run: "pip install 'towncrier>=18.6.0rc1'"
  42. - run: scripts-dev/check-newsfragment.sh
  43. env:
  44. PULL_REQUEST_NUMBER: ${{ github.event.number }}
  45. # Dummy step to gate other tests on without repeating the whole list
  46. linting-done:
  47. if: ${{ !cancelled() }} # Run this even if prior jobs were skipped
  48. needs: [lint, lint-crlf, lint-newsfile, check-sampleconfig]
  49. runs-on: ubuntu-latest
  50. steps:
  51. - run: "true"
  52. trial:
  53. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  54. needs: linting-done
  55. runs-on: ubuntu-latest
  56. strategy:
  57. matrix:
  58. python-version: ["3.7", "3.8", "3.9", "3.10"]
  59. database: ["sqlite"]
  60. toxenv: ["py"]
  61. include:
  62. # Newest Python without optional deps
  63. - python-version: "3.10"
  64. toxenv: "py-noextras"
  65. # Oldest Python with PostgreSQL
  66. - python-version: "3.7"
  67. database: "postgres"
  68. postgres-version: "10"
  69. toxenv: "py"
  70. # Newest Python with newest PostgreSQL
  71. - python-version: "3.10"
  72. database: "postgres"
  73. postgres-version: "14"
  74. toxenv: "py"
  75. steps:
  76. - uses: actions/checkout@v2
  77. - run: sudo apt-get -qq install xmlsec1
  78. - name: Set up PostgreSQL ${{ matrix.postgres-version }}
  79. if: ${{ matrix.postgres-version }}
  80. run: |
  81. docker run -d -p 5432:5432 \
  82. -e POSTGRES_PASSWORD=postgres \
  83. -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \
  84. postgres:${{ matrix.postgres-version }}
  85. - uses: actions/setup-python@v2
  86. with:
  87. python-version: ${{ matrix.python-version }}
  88. - run: pip install tox
  89. - name: Await PostgreSQL
  90. if: ${{ matrix.postgres-version }}
  91. timeout-minutes: 2
  92. run: until pg_isready -h localhost; do sleep 1; done
  93. - run: tox -e ${{ matrix.toxenv }}
  94. env:
  95. TRIAL_FLAGS: "--jobs=2"
  96. SYNAPSE_POSTGRES: ${{ matrix.database == 'postgres' || '' }}
  97. SYNAPSE_POSTGRES_HOST: localhost
  98. SYNAPSE_POSTGRES_USER: postgres
  99. SYNAPSE_POSTGRES_PASSWORD: postgres
  100. - name: Dump logs
  101. # Logs are most useful when the command fails, always include them.
  102. if: ${{ always() }}
  103. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  104. # This keeps logs colocated with failing jobs
  105. # It also ignores find's exit code; this is a best effort affair
  106. run: >-
  107. find _trial_temp -name '*.log'
  108. -exec echo "::group::{}" \;
  109. -exec cat {} \;
  110. -exec echo "::endgroup::" \;
  111. || true
  112. trial-olddeps:
  113. # Note: sqlite only; no postgres
  114. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  115. needs: linting-done
  116. runs-on: ubuntu-latest
  117. steps:
  118. - uses: actions/checkout@v2
  119. - name: Test with old deps
  120. uses: docker://ubuntu:focal # For old python and sqlite
  121. # Note: focal seems to be using 3.8, but the oldest is 3.7?
  122. # See https://github.com/matrix-org/synapse/issues/12343
  123. with:
  124. workdir: /github/workspace
  125. entrypoint: .ci/scripts/test_old_deps.sh
  126. - name: Dump logs
  127. # Logs are most useful when the command fails, always include them.
  128. if: ${{ always() }}
  129. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  130. # This keeps logs colocated with failing jobs
  131. # It also ignores find's exit code; this is a best effort affair
  132. run: >-
  133. find _trial_temp -name '*.log'
  134. -exec echo "::group::{}" \;
  135. -exec cat {} \;
  136. -exec echo "::endgroup::" \;
  137. || true
  138. trial-pypy:
  139. # Very slow; only run if the branch name includes 'pypy'
  140. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  141. needs: linting-done
  142. runs-on: ubuntu-latest
  143. strategy:
  144. matrix:
  145. python-version: ["pypy-3.7"]
  146. steps:
  147. - uses: actions/checkout@v2
  148. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  149. - uses: actions/setup-python@v2
  150. with:
  151. python-version: ${{ matrix.python-version }}
  152. - run: pip install tox
  153. - run: tox -e py
  154. env:
  155. TRIAL_FLAGS: "--jobs=2"
  156. - name: Dump logs
  157. # Logs are most useful when the command fails, always include them.
  158. if: ${{ always() }}
  159. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  160. # This keeps logs colocated with failing jobs
  161. # It also ignores find's exit code; this is a best effort affair
  162. run: >-
  163. find _trial_temp -name '*.log'
  164. -exec echo "::group::{}" \;
  165. -exec cat {} \;
  166. -exec echo "::endgroup::" \;
  167. || true
  168. sytest:
  169. if: ${{ !failure() && !cancelled() }}
  170. needs: linting-done
  171. runs-on: ubuntu-latest
  172. container:
  173. image: matrixdotorg/sytest-synapse:${{ matrix.sytest-tag }}
  174. volumes:
  175. - ${{ github.workspace }}:/src
  176. env:
  177. SYTEST_BRANCH: ${{ github.head_ref }}
  178. POSTGRES: ${{ matrix.postgres && 1}}
  179. MULTI_POSTGRES: ${{ (matrix.postgres == 'multi-postgres') && 1}}
  180. WORKERS: ${{ matrix.workers && 1 }}
  181. REDIS: ${{ matrix.redis && 1 }}
  182. BLACKLIST: ${{ matrix.workers && 'synapse-blacklist-with-workers' }}
  183. TOP: ${{ github.workspace }}
  184. strategy:
  185. fail-fast: false
  186. matrix:
  187. include:
  188. - sytest-tag: focal
  189. - sytest-tag: focal
  190. postgres: postgres
  191. - sytest-tag: testing
  192. postgres: postgres
  193. - sytest-tag: focal
  194. postgres: multi-postgres
  195. workers: workers
  196. - sytest-tag: buster
  197. postgres: multi-postgres
  198. workers: workers
  199. - sytest-tag: buster
  200. postgres: postgres
  201. workers: workers
  202. redis: redis
  203. steps:
  204. - uses: actions/checkout@v2
  205. - name: Prepare test blacklist
  206. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  207. - name: Run SyTest
  208. run: /bootstrap.sh synapse
  209. working-directory: /src
  210. - name: Summarise results.tap
  211. if: ${{ always() }}
  212. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  213. - name: Upload SyTest logs
  214. uses: actions/upload-artifact@v2
  215. if: ${{ always() }}
  216. with:
  217. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.*, ', ') }})
  218. path: |
  219. /logs/results.tap
  220. /logs/**/*.log*
  221. export-data:
  222. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  223. needs: [linting-done, portdb]
  224. runs-on: ubuntu-latest
  225. env:
  226. TOP: ${{ github.workspace }}
  227. services:
  228. postgres:
  229. image: postgres
  230. ports:
  231. - 5432:5432
  232. env:
  233. POSTGRES_PASSWORD: "postgres"
  234. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  235. options: >-
  236. --health-cmd pg_isready
  237. --health-interval 10s
  238. --health-timeout 5s
  239. --health-retries 5
  240. steps:
  241. - uses: actions/checkout@v2
  242. - run: sudo apt-get -qq install xmlsec1
  243. - uses: matrix-org/setup-python-poetry@v1
  244. with:
  245. python-version: ${{ matrix.python-version }}
  246. extras: "postgres"
  247. - run: .ci/scripts/test_export_data_command.sh
  248. portdb:
  249. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  250. needs: linting-done
  251. runs-on: ubuntu-latest
  252. env:
  253. TOP: ${{ github.workspace }}
  254. strategy:
  255. matrix:
  256. include:
  257. - python-version: "3.7"
  258. postgres-version: "10"
  259. - python-version: "3.10"
  260. postgres-version: "14"
  261. services:
  262. postgres:
  263. image: postgres:${{ matrix.postgres-version }}
  264. ports:
  265. - 5432:5432
  266. env:
  267. POSTGRES_PASSWORD: "postgres"
  268. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  269. options: >-
  270. --health-cmd pg_isready
  271. --health-interval 10s
  272. --health-timeout 5s
  273. --health-retries 5
  274. steps:
  275. - uses: actions/checkout@v2
  276. - run: sudo apt-get -qq install xmlsec1
  277. - uses: matrix-org/setup-python-poetry@v1
  278. with:
  279. python-version: ${{ matrix.python-version }}
  280. extras: "postgres"
  281. - run: .ci/scripts/test_synapse_port_db.sh
  282. complement:
  283. if: ${{ !failure() && !cancelled() }}
  284. needs: linting-done
  285. runs-on: ubuntu-latest
  286. steps:
  287. # The path is set via a file given by $GITHUB_PATH. We need both Go 1.17 and GOPATH on the path to run Complement.
  288. # See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path
  289. - name: "Set Go Version"
  290. run: |
  291. # Add Go 1.17 to the PATH: see https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#environment-variables-2
  292. echo "$GOROOT_1_17_X64/bin" >> $GITHUB_PATH
  293. # Add the Go path to the PATH: We need this so we can call gotestfmt
  294. echo "~/go/bin" >> $GITHUB_PATH
  295. - name: "Install Complement Dependencies"
  296. run: |
  297. sudo apt-get update && sudo apt-get install -y libolm3 libolm-dev
  298. go get -v github.com/haveyoudebuggedit/gotestfmt/v2/cmd/gotestfmt@latest
  299. - name: Run actions/checkout@v2 for synapse
  300. uses: actions/checkout@v2
  301. with:
  302. path: synapse
  303. # Attempt to check out the same branch of Complement as the PR. If it
  304. # doesn't exist, fallback to HEAD.
  305. - name: Checkout complement
  306. shell: bash
  307. run: |
  308. mkdir -p complement
  309. # Attempt to use the version of complement which best matches the current
  310. # build. Depending on whether this is a PR or release, etc. we need to
  311. # use different fallbacks.
  312. #
  313. # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF
  314. # for pull requests, otherwise GITHUB_REF).
  315. # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y
  316. # (GITHUB_BASE_REF for pull requests).
  317. # 3. Use the default complement branch ("HEAD").
  318. for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "HEAD"; do
  319. # Skip empty branch names and merge commits.
  320. if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then
  321. continue
  322. fi
  323. (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break
  324. done
  325. - run: |
  326. set -o pipefail
  327. COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | gotestfmt
  328. shell: bash
  329. name: Run Complement Tests
  330. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  331. tests-done:
  332. if: ${{ always() }}
  333. needs:
  334. - check-sampleconfig
  335. - lint
  336. - lint-crlf
  337. - lint-newsfile
  338. - trial
  339. - trial-olddeps
  340. - sytest
  341. - export-data
  342. - portdb
  343. - complement
  344. runs-on: ubuntu-latest
  345. steps:
  346. - uses: matrix-org/done-action@v2
  347. with:
  348. needs: ${{ toJSON(needs) }}
  349. # The newsfile lint may be skipped on non PR builds
  350. skippable:
  351. lint-newsfile