aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/ci.yml
blob: d0c391be87b2b55d4903fc5a5f345f2855107419 (plain)
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
name: CI

on:
  push:
  pull_request:
    types: [opened, reopened]

defaults:
  run:
    shell: bash

concurrency: ci-${{ github.ref }}

jobs:
  CI:
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.update-api != '' }} # the current upstream API definitions are expected to fail the test
    strategy:
      fail-fast: false
      max-parallel: 1
      matrix:
        os: [ubuntu-20.04, macos-10.15]
        compiler: [ GCC, Clang ]
        platform: [ '' ]
        qt-version: [ '5.12.10' ]
        qt-arch: [ '' ]
        # Not using binary values here, to make the job captions more readable
        e2ee: [ '' ]
        update-api: [ '', 'update-api' ]
        exclude:
        - os: macos-10.15
          compiler: GCC
        include:
        - os: windows-2019
          compiler: MSVC
          platform: x64
          qt-version: '5.12.10'
          qt-arch: win64_msvc2017_64
        - os: windows-2019
          compiler: MSVC
          platform: x64
          qt-version: '5.12.10'
          qt-arch: win64_msvc2017_64
          update-api: update-api

    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
        submodules: ${{ matrix.e2ee != '' }}

    - name: Cache Qt
      id: cache-qt
      uses: actions/cache@v2
      with:
        path: ${{ runner.workspace }}/Qt
        key: ${{ runner.os }}${{ matrix.platform }}-Qt${{ matrix.qt-version }}-cache

    - name: Install Qt
      uses: jurplel/install-qt-action@v2.11.1
      with:
        version: ${{ matrix.qt-version }}
        arch: ${{ matrix.qt-arch }}
        cached: ${{ steps.cache-qt.outputs.cache-hit }}

    - name: Install Ninja (macOS/Windows)
      if: ${{ !startsWith(matrix.os, 'ubuntu') }}
      uses: seanmiddleditch/gha-setup-ninja@v3

    - name: Install Ninja and Valgrind (Linux)
      if: startsWith(matrix.os, 'ubuntu')
      run: |
        sudo apt-get -qq install ninja-build valgrind
        echo "VALGRIND=valgrind --tool=memcheck --leak-check=yes --gen-suppressions=all --suppressions=quotest/.valgrind.supp" >>$GITHUB_ENV

    - name: Setup build environment
      run: |
        if [ "${{ matrix.compiler }}" == "GCC" ]; then
            CXX_VERSION_POSTFIX='-10'
            echo "CC=gcc$CXX_VERSION_POSTFIX" >>$GITHUB_ENV
            echo "CXX=g++$CXX_VERSION_POSTFIX" >>$GITHUB_ENV
        elif [[ '${{ matrix.compiler }}' == 'Clang' ]]; then
            if [[ '${{ runner.os }}' == 'Linux' ]]; then
                CXX_VERSION_POSTFIX='-11'
                # Do CodeQL analysis on one of Linux branches
                echo "CODEQL_ANALYSIS=true" >>$GITHUB_ENV
            fi
            echo "CC=clang$CXX_VERSION_POSTFIX" >>$GITHUB_ENV
            echo "CXX=clang++$CXX_VERSION_POSTFIX" >>$GITHUB_ENV
        fi
        if grep -q 'refs/tags' <<<'${{ github.ref }}'; then
            VERSION="$(git describe --tags)"
        elif [ '${{ github.ref }}' == 'refs/heads/master' ]; then
            VERSION="ci${{ github.run_number }}-$(git rev-parse --short HEAD)"
        else
            VERSION="$(git describe --all --contains)-ci${{ github.run_number }}-$(git rev-parse --short HEAD)"
        fi
        echo "QUOTEST_ORIGIN=$VERSION @ ${{ runner.os }}/${{ matrix.compiler }}" >>$GITHUB_ENV
        echo "CMAKE_ARGS=-G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=false \
                         -DCMAKE_INSTALL_PREFIX=~/.local -DCMAKE_PREFIX_PATH=~/.local" >>$GITHUB_ENV
        cmake -E make_directory ${{ runner.workspace }}/build

    - name: Setup MSVC environment
      uses: ilammy/msvc-dev-cmd@v1
      if: matrix.compiler == 'MSVC'
      with:
        arch: ${{ matrix.platform }}

    - name: Install OpenSSL
      if: ${{ contains(matrix.os, 'ubuntu') && matrix.e2ee }}
      run: |
        sudo apt-get install libssl-dev
        echo "openssl version" >>$GITHUB_ENV

    - name: Build and install olm
      if: matrix.e2ee
      run: |
        cd ..
        git clone https://gitlab.matrix.org/matrix-org/olm.git
        cmake -S olm -B olm/build $CMAKE_ARGS
        cmake --build olm/build --target install
        echo "QUOTEST_ORIGIN=$QUOTEST_ORIGIN with E2EE" >>$GITHUB_ENV

    - name: Build and install QtKeychain
      run: |
        cd ..
        git clone https://github.com/frankosterfeld/qtkeychain.git
        cmake -S qtkeychain -B qtkeychain/build $CMAKE_ARGS
        cmake --build qtkeychain/build --target install

    - name: Pull CS API and build GTAD
      if: matrix.update-api
      run: |
        cd ..
        git clone https://github.com/matrix-org/matrix-doc.git
        git clone --recursive https://github.com/KitsuneRal/gtad.git
        cmake -S gtad -B gtad $CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF
        cmake --build gtad
        echo "CMAKE_ARGS=$CMAKE_ARGS -DMATRIX_DOC_PATH=$GITHUB_WORKSPACE/../matrix-doc \
                                     -DGTAD_PATH=$GITHUB_WORKSPACE/../gtad/gtad" \
             >>$GITHUB_ENV
        echo "QUOTEST_ORIGIN=$QUOTEST_ORIGIN with API files regeneration" >>$GITHUB_ENV

    - name: Initialize CodeQL tools
      if: env.CODEQL_ANALYSIS
      uses: github/codeql-action/init@v1
      with:
        languages: cpp
        # If you wish to specify custom queries, you can do so here or in a config file.
        # By default, queries listed here will override any specified in a config file.
        # Prefix the list here with "+" to use these queries and those in the config file.
        # queries: ./path/to/local/query, your-org/your-repo/queries@main

    - name: Configure libQuotient
      run: |
        if [[ '${{ runner.os }}' == 'Windows' ]]; then
            BIN_DIR=.
        else
            BIN_DIR=bin
        fi
        echo "BIN_DIR=$BIN_DIR" >>$GITHUB_ENV
        cmake -S $GITHUB_WORKSPACE -B build $CMAKE_ARGS -DQuotient_ENABLE_E2EE=${{ matrix.e2ee }}

    - name: Regenerate API code
      if: matrix.update-api
      run: cmake --build build --target update-api

    - name: Build and install libQuotient
      run: |
        cmake --build build --target install
        ls ~/.local/$BIN_DIR/quotest

    - name: Run tests
      env:
        TEST_USER: ${{ secrets.TEST_USER }}
        TEST_PWD: ${{ secrets.TEST_PWD }}
        QT_LOGGING_RULES: 'quotient.main.debug=true;quotient.jobs.debug=true'
        QT_MESSAGE_PATTERN: '%{time h:mm:ss.zzz}|%{category}|%{if-debug}D%{endif}%{if-info}I%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}|%{message}'
      run: |
        [[ -z "$TEST_USER" ]] || $VALGRIND build/quotest/quotest "$TEST_USER" "$TEST_PWD" quotest-gha '#quotest:matrix.org' "$QUOTEST_ORIGIN"
      timeout-minutes: 4 # quotest is supposed to finish within 3 minutes, actually
    
    - name: Perform CodeQL analysis
      if: env.CODEQL_ANALYSIS
      uses: github/codeql-action/analyze@v1