Migrate Tests from Travis CI to Github Workflows (#8331)
* Migrate Tests from Travis CI to Github Workflows * Use GHA path filters * Make a unit test fail * Run new cmocka based unit tests * Revert "Make a unit test fail" This reverts commit 15500c59e4d49cb478ef27289de0366a543815c5. * Make a cmocka unit test fail * Work around a bug in libbson-1.0 on Ubuntu 18.04 * Add DCMAKE_BUILD_TYPE=Debug to make dbengine tests pass * Upload LastTest.log to GHA Artifact storage * Revert "Make a cmocka unit test fail" This reverts commit 920f56a03d0479bec1a67dc8c242df189f702177. * Remove Artifacts Validation stage
James Mills committed
Mar 14, 2020 at 16:22 UTC
c999f89754072128d7efcf5581ad145ad8af5026
4 files changed
+125
-96
.github/workflows/tests.yml
new
+86
@@ -0,0 +1,86 @@
1
+---
2
+# Runs Tests on Pushes to `master` and Pull Requests
3
+name: Tests
4
+on:
5
+ push:
6
+ branches:
7
+ - master
8
+ paths:
9
+ - '**.c'
10
+ - '**.h'
11
+ pull_request:
12
+ paths:
13
+ - '**.c'
14
+ - '**.h'
15
+jobs:
16
+ unit-tests-legacy:
17
+ name: Unit Tests (legacy)
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v2
22
+ - name: Prepare environment
23
+ run: |
24
+ ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata-all
25
+ sudo apt-get install -y libjson-c-dev libipmimonitoring-dev libcups2-dev libsnappy-dev \
26
+ libprotobuf-dev libprotoc-dev libssl-dev protobuf-compiler \
27
+ libnetfilter-acct-dev
28
+ - name: Run ./tests/run-unit-tests.sh
29
+ env:
30
+ CFLAGS: "-O1 -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1"
31
+ run: |
32
+ ./tests/run-unit-tests.sh
33
+
34
+ unit-tests-cmocka:
35
+ name: Unit Tests (cmocka)
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - name: Checkout
39
+ uses: actions/checkout@v2
40
+ - name: Prepare environment
41
+ run: |
42
+ ./packaging/installer/install-required-packages.sh --dont-wait --non-interactive netdata-all
43
+ sudo apt-get install -y libjson-c-dev libipmimonitoring-dev libcups2-dev libsnappy-dev \
44
+ libprotobuf-dev libprotoc-dev libssl-dev protobuf-compiler \
45
+ libnetfilter-acct-dev libmongoc-dev libcmocka-dev
46
+ - name: Configure
47
+ run: |
48
+ autoreconf -ivf
49
+ ./configure
50
+ # XXX: Work-around for bug with libbson-1.0 in Ubuntu 18.04
51
+ # See: https://bugs.launchpad.net/ubuntu/+source/libmongoc/+bug/1790771
52
+ # https://jira.mongodb.org/browse/CDRIVER-2818
53
+ - name: Fix libbson
54
+ run: |
55
+ pushd /usr/lib || exit 1
56
+ sudo ln -s /usr/include .
57
+ popd || exit 1
58
+ - name: Build
59
+ run: |
60
+ mkdir build-tmp
61
+ cd build-tmp
62
+ cmake \
63
+ -D UNIT_TESTING=1 \
64
+ -D BUILD_TESTING=1 \
65
+ -D CMAKE_BUILD_TYPE="Debug" \
66
+ -D BSON_LIBRARY=/usr/lib/x86_64-linux-gnu/libbson-1.0.so \
67
+ -D MONGOC_LIBRARY=/usr/lib/x86_64-linux-gnu/libmongoc-1.0.so \
68
+ ..
69
+ make
70
+ - name: Run ctest
71
+ run: |
72
+ cd build-tmp
73
+ ctest
74
+ - name: Prepare Artifacts
75
+ if: always()
76
+ run: |
77
+ mkdir logs
78
+ pushd build-tmp || exit 1
79
+ find . -type f -name '*.log' -exec cp {} ../logs/ \;
80
+ popd || exit 1
81
+ - name: Upload Artifacts
82
+ uses: actions/upload-artifact@v1
83
+ if: always()
84
+ with:
85
+ name: logs
86
+ path: logs
.travis.yml
-11
@@ -47,7 +47,6 @@ notifications:
47
stages:
48
# Mandatory runs, we always want these executed
49
- name: Build process
50
- - name: Artifacts validation
50
51
# Nightly operations
52
- name: Nightly operations
@@ -107,16 +106,6 @@ jobs:
106
env: DEVEL="true"
107
after_failure: post_message "TRAVIS_MESSAGE" "Docker build process failed"
108
110
- - stage: Artifacts validation
111
- name: Unit Testing
112
- script:
113
- - .travis/run-unit-tests.sh
114
- env: CFLAGS='-O1 -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1'
115
- # We need a full deep clone for the checks done by the unit testing script to work.
116
- git:
117
- depth: false
118
- after_failure: post_message "TRAVIS_MESSAGE" "Unit testing failed"
119
-
109
- name: Build/Install for ubuntu 18.04 (not containerized)
110
script: fakeroot ./netdata-installer.sh --dont-wait --dont-start-it --install $HOME
111
after_failure: post_message "TRAVIS_MESSAGE" "Build/Install failed on ubuntu 18.04"
.travis/run-unit-tests.sh
deleted
-85
@@ -1,85 +0,0 @@
1
-#!/usr/bin/env bash
2
-#
3
-# Unit-testing script
4
-#
5
-# This script does the following:
6
-# 1. Check whether any files were modified that would necessitate unit testing (using the `TRAVIS_COMMIT_RANGE` environment variable).
7
-# 2. If there are no changed files that require unit testing, exit successfully.
8
-# 3. Otherwise, run all the unit tests.
9
-#
10
-# We do things this way because our unit testing takes a rather long
11
-# time (average 18-19 minutes as of the original creation of this script),
12
-# so skipping it when we don't actually need it can significantly speed
13
-# up the CI process.
14
-#
15
-# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
16
-#
17
-# Author: Austin S. Hemmelgarn <austin@netdata.cloud>
18
-#
19
-# shellcheck disable=SC2230
20
-
21
-install_netdata() {
22
- echo "Installing Netdata"
23
- fakeroot ./netdata-installer.sh --install $HOME --dont-wait --dont-start-it --enable-plugin-nfacct --enable-plugin-freeipmi --disable-lto
24
-}
25
-
26
-c_unit_tests() {
27
- echo "Running C code unit tests"
28
- $HOME/netdata/usr/sbin/netdata -W unittest
29
-}
30
-
31
-run_c_unit_tests=
32
-
33
-if [ -z ${TRAVIS_COMMIT_RANGE} ] ; then
34
- # Travis gave us no commit range, so just run all the unit tests.
35
- # Per the docs, this is the case when a new branch is pushed for the first time.
36
- echo "No commit range supplied, assuming the worst case and running all unit tests."
37
- run_c_unit_tests=1
38
-else
39
- changed_paths=
40
-
41
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ] ; then
42
- # This is not a PR build.
43
- COMMIT1="$(echo ${TRAVIS_COMMIT_RANGE} | cut -f 1 -d '.')"
44
- COMMIT2="$(echo ${TRAVIS_COMMIT_RANGE} | cut -f 4 -d '.')"
45
-
46
- if [ "$(git cat-file -t ${COMMIT1} 2>/dev/null)" = commit -a "$(git cat-file -t ${COMMIT2} 2>/dev/null)" = commit ] ; then
47
- # Examine the exact set of commits passed by Travis.
48
- echo "Checking commits:"
49
- git log --format=oneline --abbrev-commit ${COMMIT1}..${COMMIT2}
50
- changed_paths="$(git diff --name-only ${COMMIT1}..${COMMIT2} --)"
51
- else
52
- # We couldn't find at least one of the changesets, so this build
53
- # was probably triggered by a history rewrite. Since we can't
54
- # figure out what chnaged, we need to just run all the tests anyway.
55
- echo "Cannot determine which commits we are testing, running all unit tests."
56
- run_c_unit_tests=1
57
- fi
58
- else
59
- # This is a PR build, look at all commits from the target branch
60
- # to HEAD.
61
- echo "Checking commits:"
62
- git log --format=oneline --abbrev-commit ${TRAVIS_BRANCH}..HEAD
63
- changed_paths="$(git diff --name-only ${TRAVIS_BRANCH}..HEAD --)"
64
- fi
65
-
66
- if [ -n "${changed_paths}" ] ; then
67
- # Check for changes that would require the C code to be re-tested
68
- if (echo ${changed_paths} | grep -qE "daemon/unit_test|database") ; then
69
- echo "Commits appear to change C code with unit tests, queueing C unit tests."
70
- run_c_unit_tests=1
71
- fi
72
- fi
73
-fi
74
-
75
-if [ -z ${run_c_unit_tests} ] ; then
76
- # No tests to run, log this and exit with success
77
- echo "Commit range ${TRAVIS_COMMIT_RANGE} appears to make no changes that require unit tests, skipping unit testing."
78
- exit 0
79
-else
80
- install_netdata || exit 1
81
-
82
- if [ -n ${run_c_unit_tests} ] ; then
83
- c_unit_tests || exit 1
84
- fi
85
-fi
tests/run-unit-tests.sh
new
+39
@@ -0,0 +1,39 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Unit-testing script
4
+#
5
+# This script does the following:
6
+# 1. Check whether any files were modified that would necessitate unit testing (using the `TRAVIS_COMMIT_RANGE` environment variable).
7
+# 2. If there are no changed files that require unit testing, exit successfully.
8
+# 3. Otherwise, run all the unit tests.
9
+#
10
+# We do things this way because our unit testing takes a rather long
11
+# time (average 18-19 minutes as of the original creation of this script),
12
+# so skipping it when we don't actually need it can significantly speed
13
+# up the CI process.
14
+#
15
+# Copyright: SPDX-License-Identifier: GPL-3.0-or-later
16
+#
17
+# Author: Austin S. Hemmelgarn <austin@netdata.cloud>
18
+#
19
+# shellcheck disable=SC2230
20
+
21
+install_netdata() {
22
+ echo "Installing Netdata"
23
+ fakeroot ./netdata-installer.sh \
24
+ --install "$HOME" \
25
+ --dont-wait \
26
+ --dont-start-it \
27
+ --enable-plugin-nfacct \
28
+ --enable-plugin-freeipmi \
29
+ --disable-lto
30
+}
31
+
32
+c_unit_tests() {
33
+ echo "Running C code unit tests"
34
+ "$HOME"/netdata/usr/sbin/netdata -W unittest
35
+}
36
+
37
+install_netdata || exit 1
38
+
39
+c_unit_tests || exit 1