Skip to content

Commit a529f70

Browse files
committed
Rearrange lcov scripts
1 parent 6d64660 commit a529f70

File tree

7 files changed

+126
-217
lines changed

7 files changed

+126
-217
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- develop
9+
- feature/**
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Install pre-reqs
18+
run: |
19+
sudo apt-get update
20+
sudo apt-get install black
21+
- name: Shellcheck
22+
run: |
23+
shellcheck scripts/lcov-jenkins-gcc-13.sh
24+
- name: Black
25+
run: |
26+
black scripts/gcov-compare.py

scripts/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

22
## GCOV/LCOV PROCESSING
33

4-
- lcov-jenkins.sh: a script used by Jenkins jobs to process test coverage, and output lcov/gcov results.
5-
- lcov-development.sh: almost identical to lcov-jenkins.sh. However the purpose of this script is to test locally in a container, and possibly use this as a location to add new features that will eventually be migrated into the live production in lcov-jenkins.sh. Submit proposed updates here.
4+
- lcov-jenkins-gcc-13.sh: a script used by Jenkins jobs to process test coverage, and output lcov/gcov results.
65
- gcov-compare.py: Compares the coverage changes of a pull request, and displays a sort of "chart" indicating if coverage has increased or decreased.
76

7+
Pull requests are welcome. It's always required to directly modify lcov-jenkins-gcc-13.sh since that affects all current jobs. Rather, when testing new jobs, it's possible to add new scripts such as lcov-jenkins-gcc-16-experimental.sh, etc.
88

9+
See docs/README.md for instructions about running lcov in a local test environment.

scripts/docs/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
### lcov and govr scripts
3+
4+
Run lcov and gcovr reports on a pull request, generating coverage reports.
5+
6+
Here are instructions about testing gcovr locally.
7+
8+
Run in a docker container such as ubuntu:24.04, or the latest LTS Ubuntu.
9+
10+
Configuring a few variables and settings that would already be available in a Jenkins job but
11+
if run in standalone mode would need to be set. The following code might be manually
12+
copied into the script, or run in a shell first.
13+
14+
```
15+
apt-get update
16+
apt-get install sudo
17+
18+
mkdir -p test
19+
cd test
20+
21+
REPONAME=url
22+
ORGANIZATION=cppalliance
23+
ghprbTargetBranch=develop
24+
JOBFOLDER="${REPONAME}_job_folder"
25+
26+
echo "Initial cleanup. Remove job folder"
27+
rm -rf ${JOBFOLDER}
28+
echo "Remove target folder"
29+
rm -rf ${REPONAME}
30+
echo "Remove boost-root"
31+
rm -rf boost-root
32+
33+
git clone https://github.com/$ORGANIZATION/$REPONAME ${JOBFOLDER}
34+
cd ${JOBFOLDER}
35+
36+
# Then proceed with the lcov processing
37+
38+
. ./lcov-jenkins-gcc-13.sh # or the name of the current script, which may be gcc-16, etc.
39+
40+
41+
```
42+
43+

scripts/gcov-compare.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,71 @@
88
from collections import defaultdict
99

1010
if len(sys.argv) >= 2:
11-
newcoveragefile=sys.argv[1]
11+
newcoveragefile = sys.argv[1]
1212
# print("newcoveragefile is " + newcoveragefile)
1313
else:
14-
# a default
15-
newcoveragefile="summary.pr.json"
14+
# a default
15+
newcoveragefile = "summary.pr.json"
1616
# print("newcoveragefile is using a default value of summary.pr.json")
1717

1818
if len(sys.argv) >= 3:
19-
targetbranchcoveragefile=sys.argv[2]
19+
targetbranchcoveragefile = sys.argv[2]
2020
# print("targetbranchcoveragefile is " + targetbranchcoveragefile)
2121
else:
2222
# a default
23-
targetbranchcoveragefile="summary.develop.json"
23+
targetbranchcoveragefile = "summary.develop.json"
2424
# print("targetbranchcoveragefile is using a default value of summary.targetbranch.json")
2525

26-
json_file = open(newcoveragefile, 'r')
26+
json_file = open(newcoveragefile, "r")
2727
newcoveragedata = json.load(json_file)
2828
json_file.close()
29-
json_file = open(targetbranchcoveragefile, 'r')
29+
json_file = open(targetbranchcoveragefile, "r")
3030
targetbranchcoveragedata = json.load(json_file)
3131
json_file.close()
3232

33-
new_files={}
33+
new_files = {}
3434

3535
for filedict in newcoveragedata["files"]:
36-
filename=filedict["filename"]
37-
new_files[filename]=filedict
36+
filename = filedict["filename"]
37+
new_files[filename] = filedict
3838

39-
targetbranch_files={}
39+
targetbranch_files = {}
4040
for filedict in targetbranchcoveragedata["files"]:
41-
filename=filedict["filename"]
42-
targetbranch_files[filename]=filedict
41+
filename = filedict["filename"]
42+
targetbranch_files[filename] = filedict
4343

44-
diff_files=defaultdict(dict)
44+
diff_files = defaultdict(dict)
4545

4646
for file in new_files:
4747
if file in targetbranch_files:
48-
diff_line_percent=new_files[file]["line_percent"] - targetbranch_files[file]["line_percent"]
49-
diff_line_percent=round(diff_line_percent, 2)
50-
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
51-
diff_line_percent=int(diff_line_percent)
48+
diff_line_percent = (
49+
new_files[file]["line_percent"] - targetbranch_files[file]["line_percent"]
50+
)
51+
diff_line_percent = round(diff_line_percent, 2)
52+
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
53+
diff_line_percent = int(diff_line_percent)
5254
# print(new_files[file]["line_percent"],targetbranch_files[file]["line_percent"],diff_line_percent)
5355
else:
54-
diff_line_percent=new_files[file]["line_percent"] - 100
55-
diff_line_percent=round(diff_line_percent, 2)
56-
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
57-
diff_line_percent=int(diff_line_percent)
56+
diff_line_percent = new_files[file]["line_percent"] - 100
57+
diff_line_percent = round(diff_line_percent, 2)
58+
if isinstance(diff_line_percent, float) and diff_line_percent.is_integer():
59+
diff_line_percent = int(diff_line_percent)
5860
# print(diff_line_percent)
5961

60-
diff_files[file]["diff_line_percent"]=diff_line_percent
62+
diff_files[file]["diff_line_percent"] = diff_line_percent
6163

6264
# Output results
6365

6466
print("")
65-
print('Each number represents a percentage line coverage difference of one file. For example "0" means 0% change in a file, "-7" is 7% less coverage, etc.')
67+
print(
68+
'Each number represents a percentage line coverage difference of one file. For example "0" means 0% change in a file, "-7" is 7% less coverage, etc.'
69+
)
6670
print("")
6771

68-
formatter=0
72+
formatter = 0
6973
for file in diff_files:
7074
print(str(diff_files[file]["diff_line_percent"]).rjust(4) + " ", end="")
71-
formatter=formatter+1
75+
formatter = formatter + 1
7276
if formatter % 20 == 0:
7377
print("")
7478
print("")

scripts/lcov-development.sh

Lines changed: 0 additions & 171 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)