tests.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. # Note: This and the script can be simplified once we drop Buildkite. See:
  36. # https://github.com/actions/checkout/issues/266#issuecomment-638346893
  37. # https://github.com/actions/checkout/issues/416
  38. - uses: actions/checkout@v2
  39. with:
  40. ref: ${{ github.event.pull_request.head.sha }}
  41. fetch-depth: 0
  42. - uses: actions/setup-python@v2
  43. - run: pip install tox
  44. - run: scripts-dev/check-newsfragment
  45. env:
  46. PULL_REQUEST_NUMBER: ${{ github.event.number }}
  47. lint-sdist:
  48. runs-on: ubuntu-latest
  49. steps:
  50. - uses: actions/checkout@v2
  51. - uses: actions/setup-python@v2
  52. with:
  53. python-version: "3.x"
  54. - run: pip install wheel
  55. - run: python setup.py sdist bdist_wheel
  56. - uses: actions/upload-artifact@v2
  57. with:
  58. name: Python Distributions
  59. path: dist/*
  60. # Dummy step to gate other tests on without repeating the whole list
  61. linting-done:
  62. if: ${{ !cancelled() }} # Run this even if prior jobs were skipped
  63. needs: [lint, lint-crlf, lint-newsfile, lint-sdist]
  64. runs-on: ubuntu-latest
  65. steps:
  66. - run: "true"
  67. trial:
  68. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  69. needs: linting-done
  70. runs-on: ubuntu-latest
  71. strategy:
  72. matrix:
  73. python-version: ["3.6", "3.7", "3.8", "3.9"]
  74. database: ["sqlite"]
  75. include:
  76. # Newest Python without optional deps
  77. - python-version: "3.9"
  78. toxenv: "py-noextras,combine"
  79. # Oldest Python with PostgreSQL
  80. - python-version: "3.6"
  81. database: "postgres"
  82. postgres-version: "9.6"
  83. # Newest Python with PostgreSQL
  84. - python-version: "3.9"
  85. database: "postgres"
  86. postgres-version: "13"
  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 py,combine
  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. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  114. # This keeps logs colocated with failing jobs
  115. # It also ignores find's exit code; this is a best effort affair
  116. run: >-
  117. find _trial_temp -name '*.log'
  118. -exec echo "::group::{}" \;
  119. -exec cat {} \;
  120. -exec echo "::endgroup::" \;
  121. || true
  122. trial-olddeps:
  123. if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
  124. needs: linting-done
  125. runs-on: ubuntu-latest
  126. steps:
  127. - uses: actions/checkout@v2
  128. - name: Test with old deps
  129. uses: docker://ubuntu:bionic # For old python and sqlite
  130. with:
  131. workdir: /github/workspace
  132. entrypoint: .ci/scripts/test_old_deps.sh
  133. env:
  134. TRIAL_FLAGS: "--jobs=2"
  135. - name: Dump logs
  136. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  137. # This keeps logs colocated with failing jobs
  138. # It also ignores find's exit code; this is a best effort affair
  139. run: >-
  140. find _trial_temp -name '*.log'
  141. -exec echo "::group::{}" \;
  142. -exec cat {} \;
  143. -exec echo "::endgroup::" \;
  144. || true
  145. trial-pypy:
  146. # Very slow; only run if the branch name includes 'pypy'
  147. if: ${{ contains(github.ref, 'pypy') && !failure() && !cancelled() }}
  148. needs: linting-done
  149. runs-on: ubuntu-latest
  150. strategy:
  151. matrix:
  152. python-version: ["pypy-3.6"]
  153. steps:
  154. - uses: actions/checkout@v2
  155. - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
  156. - uses: actions/setup-python@v2
  157. with:
  158. python-version: ${{ matrix.python-version }}
  159. - run: pip install tox
  160. - run: tox -e py,combine
  161. env:
  162. TRIAL_FLAGS: "--jobs=2"
  163. - name: Dump logs
  164. # Note: Dumps to workflow logs instead of using actions/upload-artifact
  165. # This keeps logs colocated with failing jobs
  166. # It also ignores find's exit code; this is a best effort affair
  167. run: >-
  168. find _trial_temp -name '*.log'
  169. -exec echo "::group::{}" \;
  170. -exec cat {} \;
  171. -exec echo "::endgroup::" \;
  172. || true
  173. sytest:
  174. if: ${{ !failure() && !cancelled() }}
  175. needs: linting-done
  176. runs-on: ubuntu-latest
  177. container:
  178. image: matrixdotorg/sytest-synapse:${{ matrix.sytest-tag }}
  179. volumes:
  180. - ${{ github.workspace }}:/src
  181. env:
  182. POSTGRES: ${{ matrix.postgres && 1}}
  183. MULTI_POSTGRES: ${{ (matrix.postgres == 'multi-postgres') && 1}}
  184. WORKERS: ${{ matrix.workers && 1 }}
  185. REDIS: ${{ matrix.redis && 1 }}
  186. BLACKLIST: ${{ matrix.workers && 'synapse-blacklist-with-workers' }}
  187. TOP: ${{ github.workspace }}
  188. strategy:
  189. fail-fast: false
  190. matrix:
  191. include:
  192. - sytest-tag: bionic
  193. - sytest-tag: bionic
  194. postgres: postgres
  195. - sytest-tag: testing
  196. postgres: postgres
  197. - sytest-tag: bionic
  198. postgres: multi-postgres
  199. workers: workers
  200. - sytest-tag: buster
  201. postgres: multi-postgres
  202. workers: workers
  203. - sytest-tag: buster
  204. postgres: postgres
  205. workers: workers
  206. redis: redis
  207. steps:
  208. - uses: actions/checkout@v2
  209. - name: Prepare test blacklist
  210. run: cat sytest-blacklist .ci/worker-blacklist > synapse-blacklist-with-workers
  211. - name: Run SyTest
  212. run: /bootstrap.sh synapse
  213. working-directory: /src
  214. - name: Summarise results.tap
  215. if: ${{ always() }}
  216. run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
  217. - name: Upload SyTest logs
  218. uses: actions/upload-artifact@v2
  219. if: ${{ always() }}
  220. with:
  221. name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.*, ', ') }})
  222. path: |
  223. /logs/results.tap
  224. /logs/**/*.log*
  225. portdb:
  226. if: ${{ !failure() && !cancelled() }} # Allow previous steps to be skipped, but not fail
  227. needs: linting-done
  228. runs-on: ubuntu-latest
  229. strategy:
  230. matrix:
  231. include:
  232. - python-version: "3.6"
  233. postgres-version: "9.6"
  234. - python-version: "3.9"
  235. postgres-version: "13"
  236. services:
  237. postgres:
  238. image: postgres:${{ matrix.postgres-version }}
  239. ports:
  240. - 5432:5432
  241. env:
  242. POSTGRES_PASSWORD: "postgres"
  243. POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
  244. options: >-
  245. --health-cmd pg_isready
  246. --health-interval 10s
  247. --health-timeout 5s
  248. --health-retries 5
  249. steps:
  250. - uses: actions/checkout@v2
  251. - run: sudo apt-get -qq install xmlsec1
  252. - uses: actions/setup-python@v2
  253. with:
  254. python-version: ${{ matrix.python-version }}
  255. - run: .ci/scripts/test_synapse_port_db.sh
  256. complement:
  257. if: ${{ !failure() && !cancelled() }}
  258. needs: linting-done
  259. runs-on: ubuntu-latest
  260. container:
  261. # https://github.com/matrix-org/complement/blob/master/dockerfiles/ComplementCIBuildkite.Dockerfile
  262. image: matrixdotorg/complement:latest
  263. env:
  264. CI: true
  265. ports:
  266. - 8448:8448
  267. volumes:
  268. - /var/run/docker.sock:/var/run/docker.sock
  269. steps:
  270. - name: Run actions/checkout@v2 for synapse
  271. uses: actions/checkout@v2
  272. with:
  273. path: synapse
  274. # Attempt to check out the same branch of Complement as the PR. If it
  275. # doesn't exist, fallback to master.
  276. - name: Checkout complement
  277. shell: bash
  278. run: |
  279. mkdir -p complement
  280. # Attempt to use the version of complement which best matches the current
  281. # build. Depending on whether this is a PR or release, etc. we need to
  282. # use different fallbacks.
  283. #
  284. # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF
  285. # for pull requests, otherwise GITHUB_REF).
  286. # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y
  287. # (GITHUB_BASE_REF for pull requests).
  288. # 3. Use the default complement branch ("master").
  289. for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "master"; do
  290. # Skip empty branch names and merge commits.
  291. if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then
  292. continue
  293. fi
  294. (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break
  295. done
  296. # Build initial Synapse image
  297. - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
  298. working-directory: synapse
  299. # Build a ready-to-run Synapse image based on the initial image above.
  300. # This new image includes a config file, keys for signing and TLS, and
  301. # other settings to make it suitable for testing under Complement.
  302. - run: docker build -t complement-synapse -f Synapse.Dockerfile .
  303. working-directory: complement/dockerfiles
  304. # Run Complement
  305. - run: go test -v -tags synapse_blacklist,msc2403,msc2946,msc3083 ./tests/...
  306. env:
  307. COMPLEMENT_BASE_IMAGE: complement-synapse:latest
  308. working-directory: complement
  309. # a job which marks all the other jobs as complete, thus allowing PRs to be merged.
  310. tests-done:
  311. if: ${{ always() }}
  312. needs:
  313. - lint
  314. - lint-crlf
  315. - lint-newsfile
  316. - lint-sdist
  317. - trial
  318. - trial-olddeps
  319. - sytest
  320. - portdb
  321. - complement
  322. runs-on: ubuntu-latest
  323. steps:
  324. - name: Set build result
  325. env:
  326. NEEDS_CONTEXT: ${{ toJSON(needs) }}
  327. # the `jq` incantation dumps out a series of "<job> <result>" lines.
  328. # we set it to an intermediate variable to avoid a pipe, which makes it
  329. # hard to set $rc.
  330. run: |
  331. rc=0
  332. results=$(jq -r 'to_entries[] | [.key,.value.result] | join(" ")' <<< $NEEDS_CONTEXT)
  333. while read job result ; do
  334. # The newsfile lint may be skipped on non PR builds
  335. if [ $result == "skipped" ] && [ $job == "lint-newsfile" ]; then
  336. continue
  337. fi
  338. if [ "$result" != "success" ]; then
  339. echo "::set-failed ::Job $job returned $result"
  340. rc=1
  341. fi
  342. done <<< $results
  343. exit $rc