Skip to content

Commit f969b20

Browse files
authored
Merge pull request #67 from per1234/boards-report-array
Structure sketches report to allow compiling for multiple boards per run
2 parents f6f1be6 + f9a3b95 commit f969b20

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"
@@ -962,26 +963,33 @@ def get_size_report(self, current_size, previous_size):
962963
return size_report
963964

964965
def get_sketches_report(self, sketch_report_list):
965-
"""Return the dictionary containing data on all sketch compilations
966+
"""Return the dictionary containing data on all sketch compilations for each board
966967
967968
Keyword arguments:
968969
sketch_report_list -- list of reports from each sketch compilation
969970
"""
970971
current_git_ref = get_head_commit_hash()
971972

972973
sketches_report = {
973-
self.ReportKeys.board: self.fqbn,
974974
self.ReportKeys.commit_hash: current_git_ref,
975975
self.ReportKeys.commit_url: ("https://github.com/"
976976
+ os.environ["GITHUB_REPOSITORY"]
977977
+ "/commit/"
978978
+ current_git_ref),
979-
self.ReportKeys.sketches: sketch_report_list
979+
# The action is currently designed to only compile for one board per run, so the boards list will only have
980+
# a single element, but this provides a report format that can accommodate the possible addition of multiple
981+
# boards support
982+
self.ReportKeys.boards: [
983+
{
984+
self.ReportKeys.board: self.fqbn,
985+
self.ReportKeys.sketches: sketch_report_list
986+
}
987+
]
980988
}
981989

982990
sizes_summary_report = self.get_sizes_summary_report(sketch_report_list=sketch_report_list)
983991
if sizes_summary_report:
984-
sketches_report[self.ReportKeys.sizes] = sizes_summary_report
992+
sketches_report[self.ReportKeys.boards][0][self.ReportKeys.sizes] = sizes_summary_report
985993

986994
return sketches_report
987995

compilesketches/tests/test_compilesketches.py

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

15651565
assert compile_sketches.get_sketches_report(sketch_report_list=sketch_report_list) == {
1566-
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
15671566
compilesketches.CompileSketches.ReportKeys.commit_hash: current_git_ref,
15681567
compilesketches.CompileSketches.ReportKeys.commit_url: ("https://github.com/"
15691568
+ github_repository
15701569
+ "/commit/"
15711570
+ current_git_ref),
1572-
compilesketches.CompileSketches.ReportKeys.sizes: sizes_summary_report,
1573-
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1571+
compilesketches.CompileSketches.ReportKeys.boards: [
1572+
{
1573+
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
1574+
compilesketches.CompileSketches.ReportKeys.sizes: sizes_summary_report,
1575+
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1576+
}
1577+
]
15741578
}
15751579

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

15821586
assert compile_sketches.get_sketches_report(sketch_report_list=sketch_report_list) == {
1583-
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
15841587
compilesketches.CompileSketches.ReportKeys.commit_hash: current_git_ref,
15851588
compilesketches.CompileSketches.ReportKeys.commit_url: ("https://github.com/"
15861589
+ github_repository
15871590
+ "/commit/"
15881591
+ current_git_ref),
1589-
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1592+
compilesketches.CompileSketches.ReportKeys.boards: [
1593+
{
1594+
compilesketches.CompileSketches.ReportKeys.board: compile_sketches.fqbn,
1595+
compilesketches.CompileSketches.ReportKeys.sketches: sketch_report_list
1596+
}
1597+
]
15901598
}
15911599

15921600

@@ -1820,7 +1828,7 @@ def test_get_sizes_summary_report():
18201828

18211829
def test_create_sketches_report_file(monkeypatch, tmp_path):
18221830
sketches_report_path = tmp_path
1823-
sketches_report = {
1831+
sketches_report = [{
18241832
"sketch": "examples/Foo",
18251833
"compilation_success": True,
18261834
"flash": 444,
@@ -1830,7 +1838,7 @@ def test_create_sketches_report_file(monkeypatch, tmp_path):
18301838
"flash_delta": -994,
18311839
"ram_delta": -175,
18321840
"fqbn": "arduino:avr:uno"
1833-
}
1841+
}]
18341842

18351843
compile_sketches = get_compilesketches_object(sketches_report_path=str(sketches_report_path),
18361844
fqbn_arg="arduino:avr:uno")

0 commit comments

Comments
 (0)