-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
110 lines (99 loc) · 3.81 KB
/
action.yml
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
name: Run C/C++ tests
description: Run tests, check for memory leaks, report code coverage
inputs:
source-path:
description: Path containing the CMakeLists.txt for the tests.
required: true
default: ${{ github.workspace }}/extras/test
build-path:
description: Path of the top-level folder for build output.
required: true
default: ${{ github.workspace }}/extras/test/build
runtime-paths:
description: YAML format list of paths to runtime binaries generated by building the tests.
required: true
default: "- ${{ github.workspace }}/extras/test/build/bin/unit-test-binary"
coverage-exclude-paths:
description: YAML format list of paths to remove from coverage data.
required: true
default: |
- '*/extras/test/*'
- '/usr/*'
- '*/src/lib/*'
coverage-data-path:
description: Path to save the coverage data file to.
required: true
default: ${{ github.workspace }}/extras/test/build/coverage.info
runs:
using: composite
steps:
- name: Build tests
shell: bash
run: |
echo "::group::Run CMake on ${{ inputs.source-path }}"
cmake -S "${{ inputs.source-path }}" -B "${{ inputs.build-path }}"
echo "::endgroup::"
echo "::group::Run Make on ${{ inputs.build-path }}"
make --directory="${{ inputs.build-path }}"
echo "::endgroup::"
- name: Install yq
shell: bash
run: |
sudo snap install yq > /dev/null
- name: Update APT package lists
shell: bash
run: |
sudo apt-get update > /dev/null
- name: Install Valgrind
shell: bash
run: |
sudo apt-get --assume-yes install valgrind > /dev/null
- name: Run tests
shell: bash
run: |
if [[ -n "${{ inputs.runtime-path }}" ]]; then
echo "::warning::The runtime-path input is deprecated. Please use runtime-paths instead."
RUNTIME_PATHS="- ${{ inputs.runtime-path }}"
else
RUNTIME_PATHS="${{ inputs.runtime-paths }}"
fi
EXIT_STATUS=0
set +o errexit
while IFS='' read -r runtimePath && [[ -n "$runtimePath" ]]; do
echo "::group::Run $runtimePath with Valgrind"
if ! valgrind --tool=memcheck --leak-check=yes --error-exitcode=1 "$runtimePath"; then
EXIT_STATUS=1
echo "::error file=$runtimePath::While running $runtimePath"
fi
echo "::endgroup::"
done <<<"$(echo "$RUNTIME_PATHS" | yq eval '.[]' -)"
exit $EXIT_STATUS
- name: Parse coverage-exclude-paths input
id: parse-coverage-exclude-paths
shell: bash
run: |
while IFS='' read -r excludePath && [[ -n "$excludePath" ]]; do
excludePaths="$excludePaths $excludePath"
done <<<"$(echo "${{ inputs.coverage-exclude-paths }}" | yq eval '.[]' -)"
# Make the parsed paths an output so it can be used by the next step
echo "::set-output name=paths::$excludePaths"
- name: Install LCOV
shell: bash
run: |
sudo apt-get --assume-yes install lcov > /dev/null
- name: Generate code coverage data
shell: bash
run: |
echo "::group::Generate code coverage data from ${{ inputs.build-path }}"
mkdir --parents "$(dirname -- "${{ inputs.coverage-data-path }}")"
lcov --directory "${{ inputs.build-path }}" --capture --output-file "${{ inputs.coverage-data-path }}"
set -o noglob
lcov --quiet --remove "${{ inputs.coverage-data-path }}" ${{ steps.parse-coverage-exclude-paths.outputs.paths }} --output-file "${{ inputs.coverage-data-path }}"
set +o noglob
echo "::endgroup::"
- name: Display coverage report in log
shell: bash
run: |
echo "::group::Report code coverage"
lcov --list "${{ inputs.coverage-data-path }}"
echo "::endgroup::"