-
Notifications
You must be signed in to change notification settings - Fork 14
154 lines (134 loc) · 5.27 KB
/
testreporting.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
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
name: Test Reporting
on:
push:
paths-ignore:
- 'docs/**'
- readme.*
- README.*
- '*.md'
- '*.svg'
- .github/workflows/testwindows.yml
branches: [ "master" ]
pull_request:
paths-ignore:
- 'docs/**'
- readme.*
- README.*
- '*.md'
- '*.svg'
- .github/workflows/testwindows.yml
branches: [ "master" ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
CC: clang
CXX: clang++
jobs:
build:
env:
PUBLISH_COVERAGE: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/master' }}
strategy:
matrix:
os: [ubuntu-22.04]
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ${{matrix.os}}
steps:
- name: Display GitHub context variables
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: |
echo "PUBLISH_COVERAGE: ${PUBLISH_COVERAGE}"
echo "$GITHUB_CONTEXT"
# Get current banch name to use it as dest directory
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Prepare environment
id: coverage
run: |
# Output values to be used by other steps
echo "##[set-output name=path;]${BADGE_PATH}"
echo "##[set-output name=branch;]${BRANCH}"
env:
BADGE_PATH: ${{ steps.extract_branch.outputs.branch }}/coverage.svg
BRANCH: badges
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Install dependencies
run: |
bash ./scripts/install-dependencies-cov.sh
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: |
export CC=${{env.CC}}
export CXX=${{env.CXX}}
cmake -G Ninja -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -B build -S . -DCMAKE_INSTALL_PREFIX=/usr/local -DBAG_BUILD_TESTS:BOOL=ON -DBAG_CODE_COVERAGE:BOOL=ON
- name: Build
# Build your program with the given configuration
run: |
export CC=${{env.CC}}
export CXX=${{env.CXX}}
cmake --build build
- name: Run tests
run: |
BAG_SAMPLES_PATH=${{github.workspace}}/examples/sample-data ./build/tests/bag_tests_d -r junit -o build/tests/bag_tests-testreport.xml
- name: Test Reporter
uses: mikepenz/action-junit-report@v5
if: ${{ env.PUBLISH_COVERAGE == 'true' && (success() || failure()) }} # always run even if the previous step fails
with:
report_paths: './build/tests/*-testreport.xml'
- name: Run test coverage
# Execute C++ tests
run: |
BAG_SAMPLES_PATH=${{github.workspace}}/examples/sample-data ninja -C build ccov-all-export-lcov
- name: Test coverage reporter
uses: zgosalvez/github-actions-report-lcov@v3
if: ${{ env.PUBLISH_COVERAGE == 'true' }}
with:
coverage-files: ./build/ccov/lcov.info
minimum-coverage: 60
artifact-name: code-coverage-report
github-token: ${{ secrets.GITHUB_TOKEN }}
working-directory: ./api
- name: Update coverage badge
if: ${{ env.PUBLISH_COVERAGE == 'true' }}
run: |
source python-venv/bin/activate
llvm-cov report -instr-profile=build/ccov/all-merged.profdata `cat ./build/ccov/binaries.list` -ignore-filename-regex="tests/*" -ignore-filename-regex="bag.cpp" | tail -n 1 | awk '{ print $10 }' | xargs python ./scripts/coverage-badge.py -o /tmp/coverage.svg -c
deactivate
- name: Checkout badges branch
if: ${{ env.PUBLISH_COVERAGE == 'true' }}
# Checkout badges branch of repo so that we can commit the coverage badge there
uses: actions/checkout@v3
with:
ref: ${{ steps.coverage.outputs.branch }}
- name: Create coverage badge destination directory
if: ${{ env.PUBLISH_COVERAGE == 'true' }}
# Create the directory where badges will be saved, if needed
env:
BADGE_PATH: ${{ steps.coverage.outputs.path }}
run: mkdir -p "${BADGE_PATH%/*}"
- name: Commit badge
if: ${{ env.PUBLISH_COVERAGE == 'true' }}
continue-on-error: true
env:
BADGE: ${{ steps.coverage.outputs.path }}
run: |
mv /tmp/coverage.svg "${BADGE}"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add "${BADGE}"
git commit -m "Add/Update badge"
- name: Push badge commit
if: ${{ env.PUBLISH_COVERAGE == 'true' && success() }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.coverage.outputs.branch }}