-
-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (125 loc) · 4.1 KB
/
tests.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
name: Challenges
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
CC: clang
CXX: clang++
BUILD_TYPE: Release
BUILD_DIRECTORY: cmake-build
ASAN_OPTIONS: alloc_dealloc_mismatch=0
jobs:
build-targets:
name: Build targets
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y clang cmake
- name: Create build directory
run: cmake -E make_directory "${BUILD_DIRECTORY}"
- name: Download cache files
uses: actions/cache@v3
with:
path: |
"${BUILD_DIRECTORY}/_deps"
key: ${{ runner.os }}-build
- name: Build ${{ env.TARGET }} library
run: |
cmake -S . -B "${BUILD_DIRECTORY}" -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
cmake --build "${BUILD_DIRECTORY}" --config ${BUILD_TYPE} -- -j$(nproc)
- name: Create tar.gz file with cmake-build
run: tar -czf cmake-build.tar.gz "${BUILD_DIRECTORY}"
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: cmake-build
path: cmake-build.tar.gz
unit-tests:
name: Unit tests
runs-on: ubuntu-latest
needs: [ build-targets ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends llvm
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: cmake-build
- name: Extract cmake-build files
run: tar -xf cmake-build.tar.gz
- name: Run unit tests
env:
TARGET_DIR: ${{ env.BUILD_DIRECTORY }}/tests/unit
run: |
${TARGET_DIR}/project-euler-unit-tests \
--gtest_color=yes \
--gtest_brief=1 \
--gtest_output=xml:unit_test_details.xml
- name: Generate coverage
run: |
mkdir -p coverage
while IFS= read -r file; do
llvm-cov gcov -abcfulp "${BUILD_DIRECTORY}/CMakeFiles/project-euler-library.dir/${file}"
done < <(find lib tests -not -path '*/tests/benchmark/*' -type f | egrep --color=never -i '\.(c|cpp)$')
mv *.gcov coverage
# https://about.codecov.io/blog/how-to-set-up-codecov-with-c-and-github-actions/
- name: Upload coverage results to codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage
flags: project-euler-library
fail_ci_if_error: true
verbose: true
dry_run: github.actor == 'dependabot[bot]'
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: unit_test_details.xml
benchmark-tests:
name: Benchmark tests
runs-on: ubuntu-latest
needs: [ build-targets ]
if: github.actor != 'dependabot[bot]'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: cmake-build
- name: Extract cmake-build files
run: tar -xf cmake-build.tar.gz
- name: Run benchmark tests
env:
TARGET_DIR: ${{ env.BUILD_DIRECTORY }}/tests/benchmark
run: |
${TARGET_DIR}/project-euler-benchmark-tests \
--benchmark_format=json \
| tee benchmark-results.json
- name: Download previous benchmark results
uses: actions/cache@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Store benchmark results
uses: benchmark-action/github-action-benchmark@v1
with:
tool: googlecpp
output-file-path: benchmark-results.json
external-data-json-path: ./cache/benchmark-data.json
github-token: ${{ secrets.GITHUB_TOKEN }}
comment-on-alert: true
fail-on-alert: true