tests.yml 14 KB

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