Skip to content

Commit f9a3b95

Browse files
committed
Structure sketches report to allow compiling for multiple boards per run
Although the action does not currently support multiple boards per run, this new format makes the report structure flexible. Changes to the report structure in the future may be more likely to cause breakage for uses of the report beyond the official report actions, so it's worth trying to finalize the structure now.
1 parent 882d768 commit f9a3b95

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

compilesketches/compilesketches.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class RunCommandOutput(enum.Enum):
8080
board_manager_platforms_path = arduino_cli_data_directory_path.joinpath("packages")
8181

8282
class ReportKeys:
83+
boards = "boards"
8384
board = "board"
8485
commit_hash = "commit_hash"
8586
commit_url = "commit_url"
@@ -957,26 +958,33 @@ def get_size_report(self, current_size, previous_size):
957958
return size_report
958959

959960
def get_sketches_report(self, sketch_report_list):
960-
"""Return the dictionary containing data on all sketch compilations
961+
"""Return the dictionary containing data on all sketch compilations for each board
961962
962963
Keyword arguments:
963964
sketch_report_list -- list of reports from each sketch compilation
964965
"""
965966
current_git_ref = get_head_commit_hash()
966967

967968
sketches_report = {
968-
self.ReportKeys.board: self.fqbn,
969969
self.ReportKeys.commit_hash: current_git_ref,
970970
self.ReportKeys.commit_url: ("https://github.com/"
971971
+ os.environ["GITHUB_REPOSITORY"]
972972
+ "/commit/"
973973
+ current_git_ref),
974-
self.ReportKeys.sketches: sketch_report_list
974+
# The action is currently designed to only compile for one board per run, so the boards list will only have
975+
# a single element, but this provides a report format that can accommodate the possible addition of multiple
976+
# boards support
977+
self.ReportKeys.boards: [
978+
{
979+
self.ReportKeys.board: self.fqbn,
980+
self.ReportKeys.sketches: sketch_report_list
981+
}
982+
]
975983
}
976984

977985
sizes_summary_report = self.get_sizes_summary_report(sketch_report_list=sketch_report_list)
978986
if sizes_summary_report:
979-
sketches_report[self.ReportKeys.sizes] = sizes_summary_report
987+
sketches_report[self.ReportKeys.boards][0][self.ReportKeys.sizes] = sizes_summary_report
980988

981989
return sketches_report
982990

compilesketches/tests/test_compilesketches.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,14 +1559,18 @@ def test_get_sketches_report(monkeypatch, mocker):
15591559
compile_sketches = get_compilesketches_object(fqbn_arg=fqbn_arg)
15601560

15611561
assert compile_sketches.get_sketches_report(sketch_report_list=sketch_report_list) == {
1562-
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
15631562
compilesketches.CompileSketches.ReportKeys.commit_hash: current_git_ref,
15641563
compilesketches.CompileSketches.ReportKeys.commit_url: ("https://github.com/"
15651564
+ github_repository
15661565
+ "/commit/"
15671566
+ current_git_ref),
1568-
compilesketches.CompileSketches.ReportKeys.sizes: sizes_summary_report,
1569-
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1567+
compilesketches.CompileSketches.ReportKeys.boards: [
1568+
{
1569+
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
1570+
compilesketches.CompileSketches.ReportKeys.sizes: sizes_summary_report,
1571+
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1572+
}
1573+
]
15701574
}
15711575

15721576
compile_sketches.get_sizes_summary_report.assert_called_once_with(compile_sketches,
@@ -1576,13 +1580,17 @@ def test_get_sketches_report(monkeypatch, mocker):
15761580
compilesketches.CompileSketches.get_sizes_summary_report.return_value = []
15771581

15781582
assert compile_sketches.get_sketches_report(sketch_report_list=sketch_report_list) == {
1579-
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
15801583
compilesketches.CompileSketches.ReportKeys.commit_hash: current_git_ref,
15811584
compilesketches.CompileSketches.ReportKeys.commit_url: ("https://github.com/"
15821585
+ github_repository
15831586
+ "/commit/"
15841587
+ current_git_ref),
1585-
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1588+
compilesketches.CompileSketches.ReportKeys.boards: [
1589+
{
1590+
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
1591+
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1592+
}
1593+
]
15861594
}
15871595

15881596

@@ -1816,7 +1824,7 @@ def test_get_sizes_summary_report():
18161824

18171825
def test_create_sketches_report_file(monkeypatch, tmp_path):
18181826
sketches_report_path = tmp_path
1819-
sketches_report = {
1827+
sketches_report = [{
18201828
"sketch": "examples/Foo",
18211829
"compilation_success": True,
18221830
"flash": 444,
@@ -1826,7 +1834,7 @@ def test_create_sketches_report_file(monkeypatch, tmp_path):
18261834
"flash_delta": -994,
18271835
"ram_delta": -175,
18281836
"fqbn": "arduino:avr:uno"
1829-
}
1837+
}]
18301838

18311839
compile_sketches = get_compilesketches_object(sketches_report_path=str(sketches_report_path),
18321840
fqbn_arg="arduino:avr:uno")

0 commit comments

Comments
 (0)