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.
 
 
 
 
 
 

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