Skip to content

Commit f093526

Browse files
committed
Add comparison step to workflow
1 parent f1911e3 commit f093526

File tree

4 files changed

+83
-15
lines changed

4 files changed

+83
-15
lines changed

.github/workflows/csv-coverage.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build CSV flow coverage report
1+
name: Build/check CSV flow coverage report
22

33
on:
44
workflow_dispatch:
@@ -13,10 +13,14 @@ on:
1313
pull_request:
1414
paths:
1515
- '.github/workflows/csv-coverage.yml'
16-
- 'misc/scripts/generate-csv-coverage-report.py'
1716
- 'java/ql/src/meta/frameworks/Coverage.ql'
18-
- 'java/documentation/library-coverage/cwe-sink.csv'
19-
- 'java/documentation/library-coverage/frameworks.csv'
17+
- 'misc/scripts/library-coverage/*.py'
18+
# input data files
19+
- '*/documentation/library-coverage/cwe-sink.csv'
20+
- '*/documentation/library-coverage/frameworks.csv'
21+
# coverage report files
22+
- '*/documentation/library-coverage/flow-model-coverage.csv'
23+
- '*/documentation/library-coverage/flow-model-coverage.rst'
2024

2125
jobs:
2226
build:
@@ -54,7 +58,7 @@ jobs:
5458
run: unzip -d codeql-cli codeql-linux64.zip
5559
- name: Build modeled package list
5660
run: |
57-
PATH="$PATH:codeql-cli/codeql" python script/misc/scripts/generate-csv-coverage-report.py ci codeqlModels script
61+
PATH="$PATH:codeql-cli/codeql" python script/misc/scripts/library-coverage/generate-report.py ci codeqlModels script
5862
- name: Upload CSV package list
5963
uses: actions/upload-artifact@v2
6064
with:
@@ -65,4 +69,8 @@ jobs:
6569
with:
6670
name: rst-flow-model-coverage
6771
path: flow-model-coverage-*.rst
72+
- name: Check coverage files
73+
if: github.event.pull_request
74+
run: |
75+
python script/misc/scripts/library-coverage/compare-files.py codeqlModels
6876
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import sys
2+
import os
3+
import settings
4+
import filecmp
5+
6+
"""
7+
This script compares the generated CSV coverage files with the ones in the codebase.
8+
"""
9+
10+
11+
def check_file_exists(file):
12+
if not os.path.exists(file):
13+
print("Expected file '" + file + "' doesn't exist.", file=sys.stderr)
14+
sys.exit(1)
15+
16+
17+
languages = ['java']
18+
19+
for lang in languages:
20+
repo_output_rst = settings.repo_output_rst.format(language=lang)
21+
repo_output_csv = settings.repo_output_csv.format(language=lang)
22+
23+
generated_output_rst = settings.generated_output_rst.format(language=lang)
24+
generated_output_csv = settings.generated_output_csv.format(language=lang)
25+
26+
check_file_exists(repo_output_rst)
27+
check_file_exists(repo_output_csv)
28+
check_file_exists(generated_output_rst)
29+
check_file_exists(generated_output_csv)
30+
31+
filecmp.clear_cache()
32+
if not filecmp.cmp(repo_output_rst, generated_output_rst, shallow=False) or not filecmp.cmp(repo_output_csv, generated_output_csv, shallow=False):
33+
print("Error: The generated files for '" + lang +
34+
"' do not match the ones in the codebase. Please check and fix.", file=sys.stderr)
35+
sys.exit(1)
36+
37+
print("The generated files for '" + lang +
38+
"' match the ones in the codebase.")

misc/scripts/generate-csv-coverage-report.py renamed to misc/scripts/library-coverage/generate-report.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
import os
55
import shutil
6+
import settings
67

78
"""
89
This script runs the CSV coverage report QL query, and transforms it to a more readable format.
@@ -135,13 +136,12 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
135136
". Expected either 'dev' or 'ci'.", file=sys.stderr)
136137
exit(1)
137138

139+
# The QL model holding the CSV info can come from directly a PR or the main branch, but optionally we can use an earlier
140+
# SHA too, therefore it's checked out seperately into a dedicated subfolder.
138141
query_prefix = ""
139-
data_prefix = ""
140142
if len(sys.argv) > 2:
141143
query_prefix = sys.argv[2] + "/"
142144

143-
if len(sys.argv) > 3:
144-
data_prefix = sys.argv[3] + "/"
145145

146146
# Languages for which we want to generate coverage reports.
147147
configs = [
@@ -150,17 +150,16 @@ def __init__(self, lang, capitalized_lang, ext, ql_path):
150150
]
151151

152152
# The names of input and output files. The placeholder {language} is replaced with the language name.
153-
documentation_folder = "{language}/documentation/library-coverage/"
154153
output_ql_csv = "output-{language}.csv"
155-
input_framework_csv = data_prefix + documentation_folder + "frameworks.csv"
156-
input_cwe_sink_csv = data_prefix + documentation_folder + "cwe-sink.csv"
154+
input_framework_csv = settings.documentation_folder + "frameworks.csv"
155+
input_cwe_sink_csv = settings.documentation_folder + "cwe-sink.csv"
157156

158157
if mode == "dev":
159-
output_rst = data_prefix + documentation_folder + "flow-model-coverage.rst"
160-
output_csv = data_prefix + documentation_folder + "flow-model-coverage.csv"
158+
output_rst = settings.repo_output_rst
159+
output_csv = settings.repo_output_csv
161160
else:
162-
output_rst = "flow-model-coverage-{language}.rst"
163-
output_csv = "flow-model-coverage-{language}.csv"
161+
output_rst = settings.generated_output_rst
162+
output_csv = settings.generated_output_csv
164163

165164
for config in configs:
166165
lang = config.lang
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
3+
4+
generated_output_rst = "flow-model-coverage-{language}.rst"
5+
generated_output_csv = "flow-model-coverage-{language}.csv"
6+
7+
8+
# The CI job checks out the codebase to a subfolder
9+
data_prefix = ""
10+
11+
index = 1
12+
if sys.argv[0].endswith("generate-report.py"):
13+
index = 3
14+
15+
if len(sys.argv) > index:
16+
data_prefix = sys.argv[index] + "/"
17+
18+
19+
documentation_folder = data_prefix + \
20+
"{language}/documentation/library-coverage/"
21+
22+
repo_output_rst = documentation_folder + "flow-model-coverage.rst"
23+
repo_output_csv = documentation_folder + "flow-model-coverage.csv"

0 commit comments

Comments
 (0)