tests.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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.6", "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.6"
  79. database: "postgres"
  80. postgres-version: "9.6"
  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:bionic # 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.6"]
  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: bionic
  200. - sytest-tag: bionic
  201. postgres: postgres
  202. - sytest-tag: testing
  203. postgres: postgres
  204. - sytest-tag: bionic
  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.6"
  268. postgres-version: "9.6"
  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. container:
  296. # https://github.com/matrix-org/complement/blob/master/dockerfiles/ComplementCIBuildkite.Dockerfile
  297. image: matrixdotorg/complement:latest
  298. env:
  299. CI: true
  300. ports:
  301. - 8448:8448
  302. volumes:
  303. - /var/run/docker.sock:/var/run/docker.sock
  304. steps:
  305. - name: Run actions/checkout@v2 for synapse
  306. uses: actions/checkout@v2
  307. with:
  308. path: synapse
  309. # Attempt to check out the same branch of Complement as the PR. If it
  310. # doesn't exist, fallback to master.
  311. - name: Checkout complement
  312. shell: bash
  313. run: |
  314. mkdir -p complement
  315. # Attempt to use the version of complement which best matches the current
  316. # build. Depending on whether this is a PR or release, etc. we need to
  317. # use different fallbacks.
  318. #
  319. # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF
  320. # for pull requests, otherwise GITHUB_REF).
  321. # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y
  322. # (GITHUB_BASE_REF for pull requests).
  323. # 3. Use the default complement branch ("master").
  324. for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "master"; do
  325. # Skip empty branch names and merge commits.
  326. if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then
  327. continue
  328. fi
  329. (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break
  330. done
  331. # Build initial Synapse image
  332. - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
  333. working-directory: synapse
  334. # Build a ready-to-run Synapse image based on the initial image above.
  335. # This new image includes a config file, keys for signing and TLS, and
  336. # other settings to make it suitable for testing under Complement.
  337. - run: docker build -t complement-synapse -f Synapse.Dockerfile .
  338. working-directory: complement/dockerfiles
  339. # Run Complement
  340. - run: go test -v -tags synapse_blacklist,msc2403,msc2946,msc3083 ./tests/...
  341. env:
  342. COMPLEMENT_BASE_IMAGE: complement-synapse:latest
  343. working-directory: complement
  344. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  345. tests-done:
  346. if: ${{ always() }}
  347. needs:
  348. - lint
  349. - lint-crlf
  350. - lint-newsfile
  351. - lint-sdist
  352. - trial
  353. - trial-olddeps
  354. - sytest
  355. - portdb
  356. - complement
  357. runs-on: ubuntu-latest
  358. steps:
  359. - name: Set build result
  360. env:
  361. NEEDS_CONTEXT: ${{ toJSON(needs) }}
  362. # the `jq` incantation dumps out a series of "<job> <result>" lines.
  363. # we set it to an intermediate variable to avoid a pipe, which makes it
  364. # hard to set $rc.
  365. run: |
  366. rc=0
  367. results=$(jq -r 'to_entries[] | [.key,.value.result] | join(" ")' <<< $NEEDS_CONTEXT)
  368. while read job result ; do
  369. # The newsfile lint may be skipped on non PR builds
  370. if [ $result == "skipped" ] && [ $job == "lint-newsfile" ]; then
  371. continue
  372. fi
  373. if [ "$result" != "success" ]; then
  374. echo "::set-failed ::Job $job returned $result"
  375. rc=1
  376. fi
  377. done <<< $results
  378. exit $rc