summary refs log tree commit diff
path: root/.github/workflows/tests.yml
blob: bf36ee1cdfff6f29a1e31a2a17798a7fcf0a9275 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: Tests

on:
  push:
    branches: ["develop", "release-*"]
  pull_request:

jobs:
  lint:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        toxenv:
          - "check-sampleconfig"
          - "check_codestyle"
          - "check_isort"
          - "mypy"
          - "packaging"

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
      - run: pip install tox
      - run: tox -e ${{ matrix.toxenv }}

  lint-crlf:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Check line endings
        run: scripts-dev/check_line_terminators.sh

  lint-newsfile:
    if: ${{ github.base_ref == 'develop'  || contains(github.base_ref, 'release-') }}
    runs-on: ubuntu-latest
    steps:
      # Note: This and the script can be simplified once we drop Buildkite. See:
      #   https://github.com/actions/checkout/issues/266#issuecomment-638346893
      #   https://github.com/actions/checkout/issues/416
      - uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          fetch-depth: 0
      - uses: actions/setup-python@v2
      - run: pip install tox
      - name: Patch Buildkite-specific test script
        run: |
          sed -i -e 's/\$BUILDKITE_PULL_REQUEST/${{ github.event.number }}/' \
            scripts-dev/check-newsfragment
      - run: scripts-dev/check-newsfragment

  lint-sdist:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: "3.x"
      - run: pip install wheel
      - run: python setup.py sdist bdist_wheel
      - uses: actions/upload-artifact@v2
        with:
          name: Python Distributions
          path: dist/*

  # Dummy step to gate other tests on without repeating the whole list
  linting-done:
    if: ${{ always() }} # Run this even if prior jobs were skipped
    needs: [lint, lint-crlf, lint-newsfile, lint-sdist]
    runs-on: ubuntu-latest
    steps:
      - run: "true"

  trial:
    if: ${{ !failure() }} # Allow previous steps to be skipped, but not fail
    needs: linting-done
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9"]
        database: ["sqlite"]
        include:
          # Newest Python without optional deps
          - python-version: "3.9"
            toxenv: "py-noextras,combine"

          # Oldest Python with PostgreSQL
          - python-version: "3.6"
            database: "postgres"
            postgres-version: "9.6"

          # Newest Python with PostgreSQL
          - python-version: "3.9"
            database: "postgres"
            postgres-version: "13"

    steps:
      - uses: actions/checkout@v2
      - run: sudo apt-get -qq install xmlsec1
      - name: Set up PostgreSQL ${{ matrix.postgres-version }}
        if: ${{ matrix.postgres-version }}
        run: |
          docker run -d -p 5432:5432 \
            -e POSTGRES_PASSWORD=postgres \
            -e POSTGRES_INITDB_ARGS="--lc-collate C --lc-ctype C --encoding UTF8" \
            postgres:${{ matrix.postgres-version }}
      - uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - run: pip install tox
      - name: Await PostgreSQL
        if: ${{ matrix.postgres-version }}
        timeout-minutes: 2
        run: until pg_isready -h localhost; do sleep 1; done
      - run: tox -e py,combine
        env:
          TRIAL_FLAGS: "--jobs=2"
          SYNAPSE_POSTGRES: ${{ matrix.database == 'postgres' || '' }}
          SYNAPSE_POSTGRES_HOST: localhost
          SYNAPSE_POSTGRES_USER: postgres
          SYNAPSE_POSTGRES_PASSWORD: postgres
      - name: Dump logs
        # Note: Dumps to workflow logs instead of using actions/upload-artifact
        #       This keeps logs colocated with failing jobs
        #       It also ignores find's exit code; this is a best effort affair
        run: >-
          find _trial_temp -name '*.log'
          -exec echo "::group::{}" \;
          -exec cat {} \;
          -exec echo "::endgroup::" \;
          || true

  trial-olddeps:
    if: ${{ !failure() }} # Allow previous steps to be skipped, but not fail
    needs: linting-done
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Test with old deps
        uses: docker://ubuntu:bionic # For old python and sqlite
        with:
          workdir: /github/workspace
          entrypoint: .buildkite/scripts/test_old_deps.sh
        env:
          TRIAL_FLAGS: "--jobs=2"
      - name: Dump logs
        # Note: Dumps to workflow logs instead of using actions/upload-artifact
        #       This keeps logs colocated with failing jobs
        #       It also ignores find's exit code; this is a best effort affair
        run: >-
          find _trial_temp -name '*.log'
          -exec echo "::group::{}" \;
          -exec cat {} \;
          -exec echo "::endgroup::" \;
          || true

  trial-pypy:
    # Very slow; only run if the branch name includes 'pypy'
    if: ${{ contains(github.ref, 'pypy') && !failure() }}
    needs: linting-done
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["pypy-3.6"]

    steps:
      - uses: actions/checkout@v2
      - run: sudo apt-get -qq install xmlsec1 libxml2-dev libxslt-dev
      - uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - run: pip install tox
      - run: tox -e py,combine
        env:
          TRIAL_FLAGS: "--jobs=2"
      - name: Dump logs
        # Note: Dumps to workflow logs instead of using actions/upload-artifact
        #       This keeps logs colocated with failing jobs
        #       It also ignores find's exit code; this is a best effort affair
        run: >-
          find _trial_temp -name '*.log'
          -exec echo "::group::{}" \;
          -exec cat {} \;
          -exec echo "::endgroup::" \;
          || true

  sytest:
    if: ${{ !failure() }}
    needs: linting-done
    runs-on: ubuntu-latest
    container:
      image: matrixdotorg/sytest-synapse:${{ matrix.sytest-tag }}
      volumes:
        - ${{ github.workspace }}:/src
      env:
        BUILDKITE_BRANCH: ${{ github.head_ref }}
        POSTGRES: ${{ matrix.postgres && 1}}
        MULTI_POSTGRES: ${{ (matrix.postgres == 'multi-postgres') && 1}}
        WORKERS: ${{ matrix.workers && 1 }}
        REDIS: ${{ matrix.redis && 1 }}
        BLACKLIST: ${{ matrix.workers && 'synapse-blacklist-with-workers' }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - sytest-tag: bionic

          - sytest-tag: bionic
            postgres: postgres

          - sytest-tag: testing
            postgres: postgres

          - sytest-tag: bionic
            postgres: multi-postgres
            workers: workers

          - sytest-tag: buster
            postgres: multi-postgres
            workers: workers

          - sytest-tag: buster
            postgres: postgres
            workers: workers
            redis: redis

    steps:
      - uses: actions/checkout@v2
      - name: Prepare test blacklist
        run: cat sytest-blacklist .buildkite/worker-blacklist > synapse-blacklist-with-workers
      - name: Run SyTest
        run: /bootstrap.sh synapse
        working-directory: /src
      - name: Summarise results.tap
        if: ${{ always() }}
        run: /sytest/scripts/tap_to_gha.pl /logs/results.tap
      - name: Upload SyTest logs
        uses: actions/upload-artifact@v2
        if: ${{ always() }}
        with:
          name: Sytest Logs - ${{ job.status }} - (${{ join(matrix.*, ', ') }})
          path: |
            /logs/results.tap
            /logs/**/*.log*

  portdb:
    if: ${{ !failure() }} # Allow previous steps to be skipped, but not fail
    needs: linting-done
    runs-on: ubuntu-latest
    strategy:
      matrix:
        include:
          - python-version: "3.6"
            postgres-version: "9.6"

          - python-version: "3.9"
            postgres-version: "13"

    services:
      postgres:
        image: postgres:${{ matrix.postgres-version }}
        ports:
          - 5432:5432
        env:
          POSTGRES_PASSWORD: "postgres"
          POSTGRES_INITDB_ARGS: "--lc-collate C --lc-ctype C --encoding UTF8"
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5

    steps:
      - uses: actions/checkout@v2
      - run: sudo apt-get -qq install xmlsec1
      - uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Patch Buildkite-specific test scripts
        run: |
          sed -i -e 's/host="postgres"/host="localhost"/' .buildkite/scripts/postgres_exec.py
          sed -i -e 's/host: postgres/host: localhost/' .buildkite/postgres-config.yaml
          sed -i -e 's|/src/||' .buildkite/{sqlite,postgres}-config.yaml
          sed -i -e 's/\$TOP/\$GITHUB_WORKSPACE/' .coveragerc
      - run: .buildkite/scripts/test_synapse_port_db.sh

  complement:
    if: ${{ !failure() }}
    needs: linting-done
    runs-on: ubuntu-latest
    container:
      # https://github.com/matrix-org/complement/blob/master/dockerfiles/ComplementCIBuildkite.Dockerfile
      image: matrixdotorg/complement:latest
      env:
        CI: true
      ports:
        - 8448:8448
      volumes:
        - /var/run/docker.sock:/var/run/docker.sock

    steps:
      - name: Run actions/checkout@v2 for synapse
        uses: actions/checkout@v2
        with:
          path: synapse

      # Attempt to check out the same branch of Complement as the PR. If it
      # doesn't exist, fallback to master.
      - name: Checkout complement
        shell: bash
        run: |
          mkdir -p complement
          # Attempt to use the version of complement which best matches the current
          # build. Depending on whether this is a PR or release, etc. we need to
          # use different fallbacks.
          #
          # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF
          #    for pull requests, otherwise GITHUB_REF).
          # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y
          #    (GITHUB_BASE_REF for pull requests).
          # 3. Use the default complement branch ("master").
          for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "master"; do
            # Skip empty branch names and merge commits.
            if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then
              continue
            fi

            (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break
          done

      # Build initial Synapse image
      - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile .
        working-directory: synapse

      # Build a ready-to-run Synapse image based on the initial image above.
      # This new image includes a config file, keys for signing and TLS, and
      # other settings to make it suitable for testing under Complement.
      - run: docker build -t complement-synapse -f Synapse.Dockerfile .
        working-directory: complement/dockerfiles

      # Run Complement
      - run: go test -v -tags synapse_blacklist,msc2403,msc2946,msc3083 ./tests
        env:
          COMPLEMENT_BASE_IMAGE: complement-synapse:latest
        working-directory: complement