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

on:
  push:
    paths-ignore:
    - '.devcontainer/**'
    - 'examples/**'
    - 'lib/**'
    - 'man/**'
    - 'priv/**'
    - '**.md'
  pull_request:
    paths-ignore:
    - '.devcontainer/**'
    - 'examples/**'
    - 'lib/**'
    - 'man/**'
    - 'priv/**'
    - '**.md'

jobs:

  tests:
    name: Tests
    strategy:
      fail-fast: false
      matrix:
        otp: ['19.3', '24']
        include:
        - otp: '19.3'
          rebar: 2
          os: ubuntu-18.04
        - otp: '24'
          rebar: 3
          os: ubuntu-20.04
    runs-on: ${{ matrix.os }}
    services:
      redis:
        image: redis
        ports:
        - 6379:6379

    steps:

    - uses: actions/checkout@v2

    - name: Test shell scripts
      if: matrix.otp == 24
      run: |
        shellcheck test/ejabberd_SUITE_data/gencerts.sh
        shellcheck tools/captcha.sh
        shellcheck ejabberd.init.template
        shellcheck -x ejabberdctl.template

    - name: Get previous Erlang/OTP
      uses: ErlGang/setup-erlang@master
      if: matrix.otp != 24
      with:
        otp-version: ${{ matrix.otp }}

    - name: Prepare databases
      run: |
        sudo systemctl start mysql.service
        sudo systemctl start postgresql.service
        mysql -u root -proot -e "CREATE USER 'ejabberd_test'@'localhost'
                                 IDENTIFIED BY 'ejabberd_test';"
        mysql -u root -proot -e "CREATE DATABASE ejabberd_test;"
        mysql -u root -proot -e "GRANT ALL ON ejabberd_test.*
                                 TO 'ejabberd_test'@'localhost';"
        mysql -u root -proot ejabberd_test < sql/mysql.sql
        pg_isready
        sudo -u postgres psql -c "CREATE USER ejabberd_test
                                  WITH PASSWORD 'ejabberd_test';"
        sudo -u postgres psql -c "CREATE DATABASE ejabberd_test;"
        sudo -u postgres psql ejabberd_test -f sql/pg.sql
        sudo -u postgres psql -c "GRANT ALL PRIVILEGES
                                  ON DATABASE ejabberd_test TO ejabberd_test;"
        sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
                                                TABLES IN SCHEMA public
                                                TO ejabberd_test;"
        sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
                                                SEQUENCES IN SCHEMA public
                                                TO ejabberd_test;"

    - name: Prepare libraries
      run: |
        sudo apt-get -qq update
        sudo apt-get -qq install libexpat1-dev libgd-dev libpam0g-dev \
                                 libsqlite3-dev libwebp-dev libyaml-dev

    - name: Prepare rebar
      run: |
        echo '{xref_ignores, [{eldap_filter_yecc, return_error, 2}
                             ]}.' >>rebar.config
        echo '{xref_checks, [deprecated_function_calls, deprecated_functions,
              locals_not_used, undefined_function_calls, undefined_functions]}.
              % Disabled: exports_not_used,' >>rebar.config
        echo '{dialyzer, [{get_warnings, true}, {plt_extra_apps, [cache_tab,
              eimp, epam, esip, ezlib, fast_tls, fast_xml, fast_yaml,
              mqtree, p1_acme, p1_mysql, p1_oauth2, p1_pgsql, p1_utils, pkix,
              sqlite3, stringprep, stun, xmpp, yconf]} ]}.' >>rebar.config
        echo '{ct_extra_params, "-verbosity 20"}.' >>rebar.config
        echo "{ct_opts, [{verbosity, 20}, {keep_logs, 20}]}." >>rebar.config

    - name: Cache rebar
      uses: actions/cache@v2
      with:
        path: |
          deps/
          dialyzer/
          ebin/
          ~/.cache/rebar3/
        key: ${{matrix.otp}}-${{matrix.rebar}}-${{hashFiles('rebar.config')}}

    - name: Download test logs
      if: matrix.otp == 24 && github.repository == 'processone/ejabberd'
      continue-on-error: true
      run: |
        mkdir -p _build/test
        curl -sSL https://github.com/processone/ecil/tarball/gh-pages |
          tar -C _build/test --strip-components=1 --wildcards -xzf -
        rm -rf _build/test/logs/last/

    - name: Compile
      run: |
        ./autogen.sh
        [[ ${{ matrix.rebar }} = 2 ]] && REBAR=rebar || REBAR=`which rebar3`
        ./configure --with-rebar=$REBAR \
                    --prefix=/tmp/ejabberd \
                    --enable-all \
                    --disable-elixir \
                    --disable-mssql \
                    --disable-odbc
        make update
        make

    - run: make install -s
    - run: make hooks
    - run: make options
    - run: make xref
    - run: |
        make dialyzer
        [ ${{ matrix.rebar }} = 3 ] && true \
          || { cat dialyzer/error.log ; test ! -s dialyzer/error.log ; }

    - name: Check Production Release
      if: matrix.rebar == 3
      run: |
        make rel
        RE=_build/prod/rel/ejabberd
        $RE/bin/ejabberdctl start
        $RE/bin/ejabberdctl started
        $RE/bin/ejabberdctl stop
        $RE/bin/ejabberdctl stopped
        cat $RE/var/log/ejabberd/ejabberd.log
        grep -q "is stopped in" $RE/var/log/ejabberd/ejabberd.log

    - name: Check Development Release
      if: matrix.rebar == 3
      run: |
        make dev
        RE=_build/dev/rel/ejabberd
        $RE/bin/ejabberdctl start
        $RE/bin/ejabberdctl started
        $RE/bin/ejabberdctl stop
        $RE/bin/ejabberdctl stopped
        cat $RE/var/log/ejabberd/ejabberd.log
        grep -q "is stopped in" $RE/var/log/ejabberd/ejabberd.log

    - name: Run tests
      if: matrix.otp != 24
      run: make test
    - name: Run tests (OTP 24)
      if: matrix.otp == 24
      id: ct
      run: |
        (cd priv && ln -sf ../sql)
        COMMIT=`echo $GITHUB_SHA | cut -c 1-7`
        DATE=`date +%s`
        REF_NAME=`echo $GITHUB_REF_NAME | tr "/" "_"`
        NODENAME=$DATE@$GITHUB_RUN_NUMBER-$GITHUB_ACTOR-$REF_NAME-$COMMIT
        LABEL=`git show -s --format=%s | cut -c 1-30`
        rebar3 ct --name $NODENAME --label "$LABEL"
        rebar3 cover

    - name: Check results
      if: always()
      run: |
        [[ -d _build ]] && ln -s _build/test/logs/last/ logs || true
        ln `find logs/ -name suite.log` logs/suite.log
        grep 'TEST COMPLETE' logs/suite.log
        grep -q 'TEST COMPLETE,.* 0 failed' logs/suite.log
        test $(find logs/ -empty -name error.log)

    - name: View logs failures
      if: failure()
      run: |
        cat logs/suite.log | awk \
          'BEGIN{RS="\n=case";FS="\n"} /=result\s*failed/ {print "=case" $0}'
        find logs/ -name error.log -exec cat '{}' ';'
        find logs/ -name exunit.log -exec cat '{}' ';'

    - name: Send to coveralls
      if: matrix.otp == 24
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        DIAGNOSTIC=1 rebar3 as test coveralls send
        curl -v -k https://coveralls.io/webhook \
             --header "Content-Type: application/json" \
             --data '{"repo_name":"$GITHUB_REPOSITORY",
                      "repo_token":"$GITHUB_TOKEN",
                      "payload":{"build_num":$GITHUB_RUN_ID,
                                 "status":"done"}}'

    - name: Upload test logs
      if: always() && steps.ct.outcome == 'failure' && github.repository == 'processone/ejabberd'
      uses: peaceiris/actions-gh-pages@v3
      with:
        publish_dir: _build/test
        exclude_assets: '.github,lib,plugins'
        external_repository: processone/ecil
        deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
        keep_files: true

    - name: View ECIL address
      if: always() && steps.ct.outcome == 'failure' && github.repository == 'processone/ejabberd'
      run: |
        CTRUN=`ls -la _build/test/logs/last | sed 's|.*-> ||'`
        echo "::notice::View CT results: https://processone.github.io/ecil/logs/$CTRUN/"

    - name: Prepare new schema
      run: |
        [[ -d logs ]] && rm -rf logs
        [[ -d _build/test/logs ]] && rm -rf _build/test/logs || true
        mysql -u root -proot -e "DROP DATABASE ejabberd_test;"
        sudo -u postgres psql -c "DROP DATABASE ejabberd_test;"
        mysql -u root -proot -e "CREATE DATABASE ejabberd_test;"
        mysql -u root -proot -e "GRANT ALL ON ejabberd_test.*
                                 TO 'ejabberd_test'@'localhost';"
        mysql -u root -proot ejabberd_test < sql/mysql.new.sql
        sudo -u postgres psql -c "CREATE DATABASE ejabberd_test;"
        sudo -u postgres psql ejabberd_test -f sql/pg.new.sql
        sudo -u postgres psql -c "GRANT ALL PRIVILEGES
                                  ON DATABASE ejabberd_test TO ejabberd_test;"
        sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
                                                TABLES IN SCHEMA public
                                                TO ejabberd_test;"
        sudo -u postgres psql ejabberd_test -c "GRANT ALL PRIVILEGES ON ALL
                                                SEQUENCES IN SCHEMA public
                                                TO ejabberd_test;"
        sudo sed -i 's|new_schema, false|new_schema, true|g' test/suite.erl
    - run: CT_BACKENDS=mysql,pgsql make test
      id: ctnewschema
    - name: Check results
      if: always() && steps.ctnewschema.outcome != 'skipped'
      run: |
        [[ -d _build ]] && ln -s _build/test/logs/last/ logs || true
        ln `find logs/ -name suite.log` logs/suite.log
        grep 'TEST COMPLETE' logs/suite.log
        grep -q 'TEST COMPLETE,.* 0 failed' logs/suite.log
        test $(find logs/ -empty -name error.log)
    - name: View logs failures
      if: failure() && steps.ctnewschema.outcome != 'skipped'
      run: |
        cat logs/suite.log | awk \
          'BEGIN{RS="\n=case";FS="\n"} /=result\s*failed/ {print "=case" $0}'
        find logs/ -name error.log -exec cat '{}' ';'
        find logs/ -name exunit.log -exec cat '{}' ';'

  binaries:
    name: Binaries
    needs: [tests]
    strategy:
      fail-fast: false
      matrix:
        otp: ['21.3']
        include:
        - otp: '21.3'
          rebar: 3
          os: ubuntu-20.04
    runs-on: ${{ matrix.os }}
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: 150
    - name: Get last git tag
      run: |
        export TAGLAST=`git ls-remote --tags --refs origin 'refs/tags/2*' \
          | tail -1 | awk '{print $2}'`
        git fetch origin "$TAGLAST:$TAGLAST"
        git describe
    - name: Get previous Erlang/OTP
      uses: ErlGang/setup-erlang@master
      with:
        otp-version: ${{ matrix.otp }}
    - name: Get a compatible Rebar3
      run: |
        wget https://github.com/erlang/rebar3/releases/download/3.15.2/rebar3 \
          && chmod +x rebar3
    - name: Cache Rebar3
      uses: actions/cache@v2
      with:
        path: ~/.cache/rebar3/
        key: ${{matrix.otp}}-${{matrix.rebar}}-${{hashFiles('rebar.config')}}
    - name: Prepare libraries
      run: |
        sudo apt-get -qq update
        sudo apt-get -qq install libexpat1-dev libgd-dev libpam0g-dev \
                                 libsqlite3-dev libwebp-dev libyaml-dev
    - name: Compile
      run: |
        ./autogen.sh
        ./configure --with-rebar=./rebar3 \
                    --prefix=/tmp/ejabberd \
                    --disable-debug \
                    --enable-all \
                    --disable-elixir
        make update
        make
    - run: make install -s
    - name: Strip binaries
      run: echo 'beam_lib:strip_files(filelib:wildcard(
                "/tmp/ejabberd/lib/*/ebin/*beam")), init:stop().' \
                | erl -boot start_clean
    - name: Upload binaries
      uses: actions/upload-artifact@v2
      with:
        name: ejabberd-binaries
        path: /tmp/ejabberd/lib
        retention-days: 7