Skip to content

Commit 0deacdf

Browse files
committed
Add enable-warnings-report option
It's necessary to clear the cache between each compilation to get a true compiler warning count, otherwise only the first sketch compilation's warning count would reflect warnings from cached code. However, deleting the cache means the code must be completely compiled every time. This increases the duration of the compilations, so it should only be done when the compiler warnings count is wanted. For this reason, it was necessary to add an input to control this behavior.
1 parent 6b7abc0 commit 0deacdf

File tree

4 files changed

+139
-28
lines changed

4 files changed

+139
-28
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ GitHub access token used to get information from the GitHub API. Only needed for
118118

119119
### `enable-deltas-report`
120120

121-
Set to `true` to cause the action to determine the change in memory usage and compiler warnings of the compiled sketches. If the workflow is triggered by a `pull_request` event, the comparison is between the pull request branch and the tip of the pull request's base branch. If the workflow is triggered by a `push` event, the comparison is between the pushed commit and its immediate parent. This may be used with the [`arduino/actions/libraries/report-size-deltas` action](https://github.com/arduino/actions/tree/master/libraries/report-size-deltas). Default `false`.
121+
Set to `true` to cause the action to determine the change in memory usage and compiler warnings of the compiled sketches. If the workflow is triggered by a `pull_request` event, the comparison is between the pull request branch and the tip of the pull request's base branch. If the workflow is triggered by a `push` event, the comparison is between the pushed commit and its immediate parent. The deltas will be displayed in the GitHub Actions build log. This may be used with the [`arduino/actions/libraries/report-size-deltas` action](https://github.com/arduino/actions/tree/master/libraries/report-size-deltas). Default `false`.
122+
123+
### `enable-warnings-report`
124+
125+
Set to `true` to cause the action to record the compiler warning count for each sketch compilation in the sketches report. Default `false`.
122126

123127
## Example usage
124128

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ inputs:
2828
enable-deltas-report:
2929
description: 'Set to true to cause the action to determine the change in memory usage and compiler warnings of the compiled sketches between the head and base refs of a PR and the immediate parent commit of a push'
3030
default: false
31+
enable-warnings-report:
32+
description: 'Set to true to cause the action to record the compiler warning count for each sketch compilation in the sketches report'
33+
default: false
34+
3135
runs:
3236
using: 'docker'
3337
image: 'Dockerfile'

compilesketches/compilesketches.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def main():
4646
verbose=os.environ["INPUT_VERBOSE"],
4747
github_token=os.environ["INPUT_GITHUB-TOKEN"],
4848
enable_deltas_report=os.environ["INPUT_ENABLE-DELTAS-REPORT"],
49+
enable_warnings_report=os.environ["INPUT_ENABLE-WARNINGS-REPORT"],
4950
sketches_report_path=os.environ["INPUT_SKETCHES-REPORT-PATH"]
5051
)
5152

@@ -67,6 +68,8 @@ class CompileSketches:
6768
github_token -- GitHub access token
6869
enable_deltas_report -- set to "true" to cause the action to determine the change in memory usage
6970
("true", "false")
71+
enable_warnings_report -- set to "true" to cause the action to add compiler warning count to the sketches report
72+
("true", "false")
7073
sketches_report_path -- folder to save the sketches report to
7174
"""
7275

@@ -112,7 +115,7 @@ class ReportKeys:
112115
latest_release_indicator = "latest"
113116

114117
def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, verbose, github_token,
115-
enable_deltas_report, sketches_report_path):
118+
enable_deltas_report, enable_warnings_report, sketches_report_path):
116119
"""Process, store, and validate the action's inputs."""
117120
self.cli_version = cli_version
118121

@@ -141,6 +144,12 @@ def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, ve
141144
print("::error::Invalid value for enable-deltas-report input")
142145
sys.exit(1)
143146

147+
self.enable_warnings_report = parse_boolean_input(boolean_input=enable_warnings_report)
148+
# The enable-deltas-report input has a default value so it should always be either True or False
149+
if self.enable_warnings_report is None:
150+
print("::error::Invalid value for enable-warnings-report input")
151+
sys.exit(1)
152+
144153
if self.enable_deltas_report:
145154
self.deltas_base_ref = self.get_deltas_base_ref()
146155
else:
@@ -191,7 +200,9 @@ def compile_sketches(self):
191200

192201
sketch_list = self.find_sketches()
193202
for sketch in sketch_list:
194-
compilation_result = self.compile_sketch(sketch_path=sketch)
203+
# It's necessary to clear the cache between each compilation to get a true compiler warning count, otherwise
204+
# only the first sketch compilation's warning count would reflect warnings from cached code
205+
compilation_result = self.compile_sketch(sketch_path=sketch, clean_build_cache=self.enable_warnings_report)
195206
if not compilation_result.success:
196207
all_compilations_successful = False
197208

@@ -851,17 +862,22 @@ def find_sketches(self):
851862

852863
return sketch_list
853864

854-
def compile_sketch(self, sketch_path):
865+
def compile_sketch(self, sketch_path, clean_build_cache):
855866
"""Compile the specified sketch and returns an object containing the result:
856867
sketch -- the sketch path relative to the workspace
857868
success -- the success of the compilation (True, False)
858869
output -- stdout from Arduino CLI
859870
860871
Keyword arguments:
861872
sketch_path -- path of the sketch to compile
873+
clean_build_cache -- whether to delete cached compiled from previous compilations before compiling
862874
"""
863875
compilation_command = ["compile", "--warnings", "all", "--fqbn", self.fqbn, sketch_path]
864876

877+
if clean_build_cache:
878+
for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):
879+
shutil.rmtree(path=cache_path)
880+
865881
compilation_data = self.run_arduino_cli_command(
866882
command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False)
867883
# Group compilation output to make the log easy to read
@@ -887,8 +903,10 @@ def get_sketch_report(self, compilation_result):
887903
compilation_result -- object returned by compile_sketch()
888904
"""
889905
current_sizes = self.get_sizes_from_output(compilation_result=compilation_result)
890-
current_warning_count = self.get_warning_count_from_output(compilation_result=compilation_result)
891-
906+
if self.enable_warnings_report:
907+
current_warning_count = self.get_warning_count_from_output(compilation_result=compilation_result)
908+
else:
909+
current_warning_count = None
892910
previous_sizes = None
893911
previous_warning_count = None
894912
if self.do_deltas_report(compilation_result=compilation_result,
@@ -904,23 +922,30 @@ def get_sketch_report(self, compilation_result):
904922

905923
# Compile the sketch again
906924
print("Compiling previous version of sketch to determine memory usage change")
907-
previous_compilation_result = self.compile_sketch(sketch_path=compilation_result.sketch)
925+
previous_compilation_result = self.compile_sketch(sketch_path=compilation_result.sketch,
926+
clean_build_cache=self.enable_warnings_report)
908927

909928
# git checkout the head ref to return the repository to its previous state
910929
repository.git.checkout(original_git_ref, recurse_submodules=True)
911930

912931
previous_sizes = self.get_sizes_from_output(compilation_result=previous_compilation_result)
913-
previous_warning_count = self.get_warning_count_from_output(compilation_result=previous_compilation_result)
932+
if self.enable_warnings_report:
933+
previous_warning_count = (
934+
self.get_warning_count_from_output(compilation_result=previous_compilation_result)
935+
)
914936

915937
# Add global data for sketch to report
916938
sketch_report = {
917939
self.ReportKeys.name: str(path_relative_to_workspace(path=compilation_result.sketch)),
918940
self.ReportKeys.compilation_success: compilation_result.success,
919941
self.ReportKeys.sizes: self.get_sizes_report(current_sizes=current_sizes,
920942
previous_sizes=previous_sizes),
921-
self.ReportKeys.warnings: self.get_warnings_report(current_warnings=current_warning_count,
922-
previous_warnings=previous_warning_count)
923943
}
944+
if self.enable_warnings_report:
945+
sketch_report[self.ReportKeys.warnings] = (
946+
self.get_warnings_report(current_warnings=current_warning_count,
947+
previous_warnings=previous_warning_count)
948+
)
924949

925950
return sketch_report
926951

@@ -1046,7 +1071,10 @@ def do_deltas_report(self, compilation_result, current_sizes, current_warnings):
10461071
and (
10471072
any(size.get(self.ReportKeys.absolute) != self.not_applicable_indicator for
10481073
size in current_sizes)
1049-
or current_warnings != self.not_applicable_indicator
1074+
or (
1075+
current_warnings is not None
1076+
and current_warnings != self.not_applicable_indicator
1077+
)
10501078
)
10511079
)
10521080

@@ -1318,7 +1346,10 @@ def get_warnings_summary_report(self, sketch_report_list):
13181346
summary_report_minimum = None
13191347
summary_report_maximum = None
13201348
for sketch_report in sketch_report_list:
1321-
if self.ReportKeys.delta in sketch_report[self.ReportKeys.warnings]:
1349+
if (
1350+
self.ReportKeys.warnings in sketch_report
1351+
and self.ReportKeys.delta in sketch_report[self.ReportKeys.warnings]
1352+
):
13221353
sketch_report_delta = (
13231354
sketch_report[self.ReportKeys.warnings][self.ReportKeys.delta][self.ReportKeys.absolute]
13241355
)

0 commit comments

Comments
 (0)