Skip to content

Commit 8563c4b

Browse files
authored
Merge pull request #25 from threeal/audit-code
Audit Code
2 parents ed32932 + 207ea88 commit 8563c4b

File tree

4 files changed

+81
-93
lines changed

4 files changed

+81
-93
lines changed

.github/workflows/test.yml

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,164 +3,141 @@ on:
33
workflow_dispatch:
44
push:
55
jobs:
6-
use-action:
6+
standard-usage:
77
runs-on: ${{ matrix.os }}-latest
88
strategy:
99
fail-fast: false
1010
matrix:
1111
os: [windows, ubuntu, macos]
1212
steps:
13-
- name: Checkout repository
13+
- name: Checkout this repository
1414
uses: actions/[email protected]
1515

16-
- name: Configure and build the example project
16+
- name: Configure and build the test project
1717
uses: threeal/[email protected]
1818
with:
1919
source-dir: test
2020
generator: Ninja
2121
cxx-compiler: g++
2222

23-
- name: Test the example project
23+
- name: Test the test project
2424
run: ctest --test-dir build
2525

2626
- name: Use this action
2727
uses: ./
2828

29-
use-action-llvm:
29+
llvm-usage:
3030
runs-on: ${{ matrix.os }}-latest
3131
strategy:
3232
fail-fast: false
3333
matrix:
3434
os: [windows, ubuntu, macos]
3535
steps:
36-
- name: Checkout repository
36+
- name: Checkout this repository
3737
uses: actions/[email protected]
3838

39-
- name: Configure and build the example project
39+
- name: Configure and build the test project
4040
uses: threeal/[email protected]
4141
with:
4242
source-dir: test
4343
generator: Ninja
4444
c-compiler: clang
4545
cxx-compiler: clang++
4646

47-
- name: Test the example project
47+
- name: Test the test project
4848
run: ctest --test-dir build
4949

50-
- name: Use this action with specified gcov executable
50+
- name: Use this action with llvm-cov as the gcov executable
5151
uses: ./
5252
with:
5353
gcov-executable: ${{ matrix.os == 'macos' && 'xcrun ' || '' }}llvm-cov gcov
5454

55-
use-action-from-different-root:
56-
runs-on: ubuntu-latest
55+
exclusion-usage:
56+
runs-on: ${{ matrix.os }}-latest
57+
strategy:
58+
fail-fast: false
59+
matrix:
60+
os: [windows, ubuntu, macos]
5761
steps:
58-
- name: Checkout repository
62+
- name: Checkout this repository
5963
uses: actions/[email protected]
6064

61-
- name: Build and test example project
62-
working-directory: test
63-
run: |
64-
cmake . -B build
65-
cmake --build build
66-
ctest --test-dir build
67-
68-
- name: Use this action from build root
69-
id: failed_step
70-
continue-on-error: true
71-
uses: ./
72-
with:
73-
root: test/build
74-
fail-under-line: 100
75-
76-
- name: Check if previous step is failing
77-
run: ${{ steps.failed_step.outcome == 'failure' && true || false }}
78-
79-
- name: Use this action from build root but without fail threshold
80-
uses: ./
81-
with:
82-
root: test/build
83-
84-
- name: Use this action from project root
85-
uses: ./
65+
- name: Configure and build the test project
66+
uses: threeal/[email protected]
8667
with:
87-
root: test
88-
fail-under-line: 100
89-
90-
use-action-with-exclusion:
91-
runs-on: ubuntu-latest
92-
steps:
93-
- name: Checkout repository
94-
uses: actions/[email protected]
68+
source-dir: test
69+
build-dir: test/build
70+
generator: Ninja
71+
cxx-compiler: g++
72+
args: -DTEST_EVEN=OFF -DTEST_ODD=OFF
9573

96-
- name: Build and test example project
97-
working-directory: test
98-
run: |
99-
cmake . -B build -DTEST_EVEN=OFF -DTEST_ODD=OFF
100-
cmake --build build
101-
ctest --test-dir build
74+
- name: Test the test project
75+
run: ctest --test-dir test/build
10276

103-
- name: Use this action without exclusion
77+
- name: Use this action without an exclusion
10478
id: failed_step
10579
continue-on-error: true
10680
uses: ./
10781
with:
82+
root: test
10883
fail-under-line: 100
10984

110-
- name: Check if previous step is failing
85+
- name: Check if the previous step did fail
11186
run: ${{ steps.failed_step.outcome == 'failure' && true || false }}
11287

113-
- name: Use this action without exclusion but with lower fail threshold
88+
- name: Use this action without an exclusion but with a lower fail threshold
11489
uses: ./
11590
with:
91+
root: test
11692
fail-under-line: 50
11793

118-
- name: Use this action with exclusion
94+
- name: Use this action with an exclusion
11995
uses: ./
12096
with:
97+
root: test
12198
exclude: test/include/*
12299
fail-under-line: 100
123100

124-
use-action-generate-coveralls:
101+
coveralls-usage:
125102
runs-on: ${{ matrix.os }}-latest
126103
strategy:
127104
fail-fast: false
128105
matrix:
129106
os: [windows, ubuntu, macos]
130107
steps:
131-
- name: Checkout repository
108+
- name: Checkout this repository
132109
uses: actions/[email protected]
133110

134-
- name: Configure and build the example project
111+
- name: Configure and build the test project
135112
uses: threeal/[email protected]
136113
with:
137114
source-dir: test
138115
generator: Ninja
139116
cxx-compiler: g++
140117

141-
- name: Test the example project
118+
- name: Test the test project
142119
run: ctest --test-dir build
143120

144-
- name: Use this action to generate Coveralls report
121+
- name: Use this action to generate a Coveralls report
145122
uses: ./
146123
with:
147124
coveralls-out: coveralls.json
148125

149-
- name: Check if Coveralls report exist
126+
- name: Check if that Coveralls report does exist
150127
run: cat coveralls.json
151128

152-
- name: Use this action to generate and send Coveralls report
129+
- name: Use this action to generate and send another Coveralls report
153130
uses: ./
154131
with:
155132
coveralls-send: true
156133
github-token: ${{ secrets.GITHUB_TOKEN }}
157134

158-
- name: Use this action to generate and send Coveralls report on specified output
135+
- name: Use this action to generate and send another Coveralls report on a specified output
159136
uses: ./
160137
with:
161138
coveralls-out: coveralls-2.json
162139
coveralls-send: true
163140
github-token: ${{ secrets.GITHUB_TOKEN }}
164141

165-
- name: Check if Coveralls report exist
142+
- name: Check if that Coveralls report does exist
166143
run: cat coveralls-2.json

README.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@
44
[![license](https://img.shields.io/github/license/threeal/gcovr-action)](./LICENSE)
55
[![test status](https://img.shields.io/github/actions/workflow/status/threeal/gcovr-action/test.yml?label=test&branch=main)](https://github.com/threeal/gcovr-action/actions/workflows/test.yml)
66

7-
Generate code coverage report for C++ project on [GitHub Actions](https://github.com/features/actions) using [gcovr](https://gcovr.com/en/stable/).
7+
Generate code coverage reports for a C++ project on [GitHub Actions](https://github.com/features/actions) using [gcovr](https://gcovr.com/en/stable/).
8+
9+
## Features
10+
11+
- Generate code coverage reports using [gcovr](https://gcovr.com/en/stable/).
12+
- Generate and send reports in [Coveralls API](https://docs.coveralls.io/api-introduction) format.
13+
- Auto detect and install required dependencies.
14+
- Support coverage report on [GCC](https://gcc.gnu.org/) and [LLVM Clang](https://clang.llvm.org/).
15+
- Support files exclusion and fail if coverage is below a specific thresold.
816

917
## Usage
1018

11-
For more information, see [action.yml](./action.yml) and the [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions).
19+
For more information, see [action.yml](./action.yml) and [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions).
1220

1321
### Inputs
1422

15-
> Note: All inputs are optional.
16-
1723
| Name | Value Type | Description |
1824
| --- | --- | --- |
19-
| `root` | Path | The root directory of your source files. Defaults to current directory. File names are reported relative to this root. |
20-
| `gcov-executable` | Executable name with optional arguments | Use a particular gcov executable. Must match the compiler you are using, e.g. `llvm-cov gcov` for [LLVM](https://llvm.org/). See [this](https://docs.coveralls.io/api-introduction). |
25+
| `root` | Path | Root directory of your source files. Defaults to current directory. File names are reported relative to this directory. |
26+
| `gcov-executable` | Executable name with optional arguments | Use a particular [gcov](https://gcc.gnu.org/onlinedocs/gcc/Gcov.html) executable. Must match the compiler you are using, e.g. `llvm-cov gcov` for [LLVM Clang](https://clang.llvm.org/). See [this](https://gcovr.com/en/stable/guide/compiling.html#choosing-the-right-gcov-executable). |
2127
| `exclude` | Regular expression | Exclude source files that match this filter. |
2228
| `fail-under-line` | 0 - 100 | Fail if the total line coverage is less than this value. |
23-
| `coveralls-out` | Path | Output file of generated Coveralls API coverage report. |
24-
| `coveralls-send` | `true` or `false` | Send Coveralls API coverage report to it's endpoint (default: `false`). |
25-
| `github-token` | Token | GitHub token of this project. Must be set to `${{ secrets.GITHUB_TOKEN }}`. Required for sending Coveralls API coverage report successfully. |
29+
| `coveralls-out` | Path | Output file of the generated [Coveralls API](https://docs.coveralls.io/api-introduction) coverage report. |
30+
| `coveralls-send` | `true` or `false` | Send the generated Coveralls API coverage report to it's endpoint. Defaults to `false`. |
31+
| `github-token` | Token | [GitHub token](https://docs.github.com/en/actions/security-guides/automatic-token-authentication) of your project. Should be set to `secrets.GITHUB_TOKEN`. Required for sending Coveralls API coverage report successfully. |
2632

27-
### Standard Example
33+
> Note: All inputs are optional.
34+
35+
### Examples
2836

2937
```yaml
3038
name: test
@@ -34,38 +42,40 @@ jobs:
3442
test-coverage:
3543
runs-on: ubuntu-latest
3644
steps:
37-
- name: Checkout repository
45+
- name: Check out this repository
3846
uses: actions/[email protected]
3947

40-
- name: Build and test project
48+
- name: Build and test this project
4149
run: |
4250
cmake . -B build
4351
cmake --build build
4452
ctest --test-dir build
4553
46-
- name: Generate code coverage report
54+
- name: Generate a code coverage report
4755
uses: threeal/gcovr-action@latest
4856
```
4957
50-
### Using LLVM
58+
> Note: You can replace `@latest` with any version you like. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
59+
60+
#### Using LLVM Clang
5161

5262
```yaml
53-
- name: Build and test project
63+
- name: Build and test this project
5464
run: |
5565
cmake . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
5666
cmake --build build
5767
ctest --test-dir build
5868
59-
- name: Generate code coverage report
69+
- name: Generate a code coverage report
6070
uses: threeal/gcovr-action@latest
6171
with:
6272
gcov-executable: llvm-cov gcov
6373
```
6474

65-
### Send to Coveralls
75+
#### Send to Coveralls
6676

6777
```yaml
68-
- name: Generate and send code coverage report to Coveralls
78+
- name: Generate and send a code coverage report to Coveralls
6979
uses: threeal/gcovr-action@latest
7080
with:
7181
coveralls-send: true
@@ -74,4 +84,6 @@ jobs:
7484

7585
## License
7686

77-
This project is maintained by [Alfi Maulana](https://github.com/threeal) and licensed under the [MIT License](./LICENSE).
87+
This project is licensed under the terms of the [MIT License](./LICENSE).
88+
89+
Copyright © 2022-2023 [Alfi Maulana](https://github.com/threeal/)

action.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: Gcovr Action
2-
description: Generate code coverage report for C++ project using gcovr
2+
description: Generate code coverage reports for a C++ project using gcovr
33
author: Alfi Maulana
44
branding:
55
color: green
66
icon: check-circle
77
inputs:
88
root:
9-
description: The root directory of your source files
9+
description: Root directory of your source files
1010
required: false
1111
gcov-executable:
1212
description: Use a particular gcov executable
@@ -18,10 +18,10 @@ inputs:
1818
description: Fail if the total line coverage is less than this value
1919
required: false
2020
coveralls-out:
21-
description: Output file of generated Coveralls API coverage report
21+
description: Output file of the generated Coveralls API coverage report
2222
required: false
2323
coveralls-send:
24-
description: Send Coveralls API coverage report to it's endpoint (true/false)
24+
description: Send the generated Coveralls API coverage report to it's endpoint (true/false)
2525
required: false
2626
default: false
2727
github-token:

test/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -O0")
88

99
add_executable(main main.cpp)
1010
target_include_directories(main PRIVATE include)
11-
if(TEST_EVEN)
12-
target_compile_definitions(main PRIVATE TEST_EVEN)
13-
endif()
14-
if(TEST_ODD)
15-
target_compile_definitions(main PRIVATE TEST_ODD)
16-
endif()
11+
target_compile_definitions(
12+
main PRIVATE
13+
$<$<BOOL:${TEST_EVEN}>:TEST_EVEN>
14+
$<$<BOOL:${TEST_ODD}>:TEST_ODD>
15+
)
1716

1817
enable_testing()
1918
add_test(NAME main COMMAND $<TARGET_FILE:main>)

0 commit comments

Comments
 (0)