Skip to content

Commit 79e6166

Browse files
committed
Pass data to reportsizetrends module via the sketches report file
Rather than passing the sketch data via the API, it will now be passed via the report file. This change is needed to pass the data once the reportsizetrends code is moved to a separate action.
1 parent e0765ff commit 79e6166

File tree

6 files changed

+261
-187
lines changed

6 files changed

+261
-187
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ Set to `true` to cause the action to determine the change in memory usage for th
121121

122122
### `size-deltas-report-folder-name`
123123

124-
Folder to save the JSON formatted memory usage change reports to. Should be used only to store reports. It will be created under [`GITHUB_WORKSPACE`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables). The folder will be created if it doesn't already exist. Default `"size-deltas-reports"`.
125124

126125
### `enable-size-trends-report`
127126

@@ -177,6 +176,7 @@ The ID of the Google Sheets spreadsheet to write the memory usage trends data to
177176
### `size-trends-report-sheet-name`
178177

179178
The sheet name in the Google Sheets spreadsheet used for the memory usage trends report. Default `"Sheet1"`.
179+
Path in which to save a JSON formatted file containing data from the sketch compilations. Should be used only to store reports. Relative paths are relative to [`GITHUB_WORKSPACE`](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables). The folder will be created if it doesn't already exist. Default `"size-deltas-reports"`.
180180

181181
## Example usage
182182

compilesketches/compilesketches.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class RunCommandOutput(enum.Enum):
8383
board_manager_platforms_path = arduino_cli_data_directory_path.joinpath("packages")
8484

8585
report_fqbn_key = "fqbn"
86+
report_commit_hash_key = "commit_hash"
87+
report_commit_url_key = "commit_url"
8688
report_sketch_key = "sketch"
8789
report_compilation_success_key = "compilation_success"
8890
report_flash_key = "flash"
@@ -183,12 +185,12 @@ def compile_sketches(self):
183185
if self.report_sketch != "":
184186
# Make sketch reports
185187
sketch_report = self.get_sketch_report_from_sketches_report(sketches_report=sketches_report)
186-
# Make the memory usage trends report
187-
if self.do_size_trends_report():
188-
self.make_size_trends_report(sketch_report=sketch_report)
189188
# TODO: The current behavior is to only write the report for the report sketch, but the plan is to change to
190189
# reporting data for all sketches, thus the passing of sketch_report to the function
191190
self.create_sketches_report_file(sketches_report=sketch_report)
191+
# Make the memory usage trends report
192+
if self.do_size_trends_report():
193+
self.make_size_trends_report()
192194

193195
if not all_compilations_successful:
194196
print("::error::One or more compilations failed")
@@ -1009,30 +1011,19 @@ def get_sketch_report_from_sketches_report(self, sketches_report):
10091011
print("::error::size-report-sketch:", self.report_sketch, "was not found")
10101012
sys.exit(1)
10111013

1012-
def make_size_trends_report(self, sketch_report):
1014+
def make_size_trends_report(self):
10131015
"""Publish the size data for the report sketch to a Google Sheets spreadsheet.
10141016
10151017
Keyword arguments:
10161018
sketch_report -- report for the sketch report
10171019
"""
1018-
# Get the short hash of the pull request head ref
10191020
self.verbose_print("Making size trends report")
1020-
repository = git.Repo(path=os.environ["GITHUB_WORKSPACE"])
1021-
current_git_ref = repository.git.rev_parse("HEAD", short=True)
10221021

10231022
report_size_trends = reportsizetrends.ReportSizeTrends(
1023+
sketches_report_path=str(self.sketches_report_path),
10241024
google_key_file=self.google_key_file,
10251025
spreadsheet_id=self.size_trends_report_spreadsheet_id,
1026-
sheet_name=self.size_trends_report_sheet_name,
1027-
sketch_name=sketch_report[self.report_sketch_key],
1028-
commit_hash=current_git_ref,
1029-
commit_url=("https://github.com/"
1030-
+ os.environ["GITHUB_REPOSITORY"]
1031-
+ "/commit/"
1032-
+ current_git_ref),
1033-
fqbn=self.fqbn,
1034-
flash=str(sketch_report[self.report_flash_key]),
1035-
ram=str(sketch_report[self.report_ram_key])
1026+
sheet_name=self.size_trends_report_sheet_name
10361027
)
10371028

10381029
report_size_trends.report_size_trends()
@@ -1044,10 +1035,21 @@ def create_sketches_report_file(self, sketches_report):
10441035
sketch_report -- report for the sketch report
10451036
"""
10461037
self.verbose_print("Creating sketch report file")
1047-
# Add the FQBN to the report
1038+
# Add the shared data to the report
10481039
# TODO: doing this here is in anticipation of the planned switch to reporting for all sketches, when it will
1049-
# make sense to only add a single fqbn key to the report
1040+
# make sense to only add a single copy of the data that's universal to all sketches to the report
10501041
sketches_report[self.report_fqbn_key] = self.fqbn
1042+
1043+
# Get the short hash of the pull request head ref
1044+
repository = git.Repo(path=os.environ["GITHUB_WORKSPACE"])
1045+
current_git_ref = repository.git.rev_parse("HEAD", short=True)
1046+
sketches_report[self.report_commit_hash_key] = current_git_ref
1047+
1048+
sketches_report[self.report_commit_url_key] = ("https://github.com/"
1049+
+ os.environ["GITHUB_REPOSITORY"]
1050+
+ "/commit/"
1051+
+ current_git_ref)
1052+
10511053
sketches_report_path = absolute_path(path=self.sketches_report_path)
10521054

10531055
# Create the report folder

compilesketches/tests/test_compilesketches.py

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,7 @@ def test_compile_sketches(mocker, compilation_success_list, expected_success, do
279279
compile_sketches.do_size_trends_report.assert_called_once()
280280

281281
if do_size_trends_report:
282-
compile_sketches.make_size_trends_report.assert_called_once_with(
283-
compile_sketches,
284-
sketch_report=sketch_report_from_sketches_report
285-
)
282+
compile_sketches.make_size_trends_report.assert_called_once_with(compile_sketches)
286283
else:
287284
compile_sketches.make_size_trends_report.assert_not_called()
288285

@@ -1485,55 +1482,43 @@ def test_get_sketch_report_from_sketches_report(report_sketch, expected_success)
14851482

14861483

14871484
def test_make_size_trends_report(monkeypatch, mocker):
1488-
current_git_ref = "fooref"
1489-
sketch_report = {compilesketches.CompileSketches.report_sketch_key: unittest.mock.sentinel.sketch_report_sketch,
1490-
compilesketches.CompileSketches.report_flash_key: unittest.mock.sentinel.sketch_report_flash,
1491-
compilesketches.CompileSketches.report_ram_key: unittest.mock.sentinel.sketch_report_ram}
1492-
14931485
# Stub
1494-
class Repo:
1495-
def __init__(self):
1496-
self.git = self
1497-
1498-
def rev_parse(self):
1499-
pass
1500-
15011486
class ReportSizeTrends:
15021487
def report_size_trends(self):
15031488
pass
15041489

1505-
monkeypatch.setenv("GITHUB_REPOSITORY", "fooRepository/fooOwner")
1506-
monkeypatch.setenv("GITHUB_WORKSPACE", "/fooWorkspace")
1490+
sketches_report_path = "foo/sketches_report_path"
15071491

1508-
compile_sketches = get_compilesketches_object()
1492+
compile_sketches = get_compilesketches_object(sketches_report_path=sketches_report_path)
15091493

1510-
mocker.patch("git.Repo", autospec=True, return_value=Repo())
1511-
mocker.patch.object(Repo, "rev_parse", return_value=current_git_ref)
15121494
mocker.patch("reportsizetrends.ReportSizeTrends", autospec=True, return_value=ReportSizeTrends())
15131495
mocker.patch.object(ReportSizeTrends, "report_size_trends")
15141496

1515-
compile_sketches.make_size_trends_report(sketch_report)
1497+
compile_sketches.make_size_trends_report()
15161498

1517-
git.Repo.assert_called_once_with(path=os.environ["GITHUB_WORKSPACE"])
1518-
Repo.rev_parse.assert_called_once_with("HEAD", short=True)
15191499
reportsizetrends.ReportSizeTrends.assert_called_once_with(
1500+
sketches_report_path=str(pathlib.PurePath(sketches_report_path)),
15201501
google_key_file=compile_sketches.google_key_file,
15211502
spreadsheet_id=compile_sketches.size_trends_report_spreadsheet_id,
1522-
sheet_name=compile_sketches.size_trends_report_sheet_name,
1523-
sketch_name=sketch_report[compilesketches.CompileSketches.report_sketch_key],
1524-
commit_hash=current_git_ref,
1525-
commit_url=("https://github.com/"
1526-
+ os.environ["GITHUB_REPOSITORY"]
1527-
+ "/commit/"
1528-
+ current_git_ref),
1529-
fqbn=compile_sketches.fqbn,
1530-
flash=str(sketch_report[compilesketches.CompileSketches.report_flash_key]),
1531-
ram=str(sketch_report[compilesketches.CompileSketches.report_ram_key])
1503+
sheet_name=compile_sketches.size_trends_report_sheet_name
15321504
)
15331505
ReportSizeTrends.report_size_trends.assert_called_once()
15341506

15351507

1536-
def test_create_sketches_report_file(tmp_path):
1508+
def test_create_sketches_report_file(monkeypatch, tmp_path, mocker):
1509+
current_git_ref = "fooref"
1510+
1511+
# Stub
1512+
class Repo:
1513+
def __init__(self):
1514+
self.git = self
1515+
1516+
def rev_parse(self):
1517+
pass
1518+
1519+
monkeypatch.setenv("GITHUB_REPOSITORY", "fooRepository/fooOwner")
1520+
monkeypatch.setenv("GITHUB_WORKSPACE", "/fooWorkspace")
1521+
15371522
sketches_report_path = tmp_path
15381523
fqbn_arg = "arduino:avr:uno"
15391524
sketches_report = {
@@ -1548,6 +1533,9 @@ def test_create_sketches_report_file(tmp_path):
15481533
"fqbn": "arduino:avr:uno"
15491534
}
15501535

1536+
mocker.patch("git.Repo", autospec=True, return_value=Repo())
1537+
mocker.patch.object(Repo, "rev_parse", return_value=current_git_ref)
1538+
15511539
compile_sketches = get_compilesketches_object(sketches_report_path=str(sketches_report_path),
15521540
fqbn_arg=fqbn_arg)
15531541

@@ -1556,6 +1544,9 @@ def test_create_sketches_report_file(tmp_path):
15561544
with open(file=str(sketches_report_path.joinpath("arduino-avr-uno.json"))) as sketch_report_file:
15571545
assert json.load(sketch_report_file) == sketches_report
15581546

1547+
git.Repo.assert_called_once_with(path=os.environ["GITHUB_WORKSPACE"])
1548+
Repo.rev_parse.assert_called_once_with("HEAD", short=True)
1549+
15591550

15601551
@pytest.mark.parametrize("verbose", ["true", "false"])
15611552
def test_verbose_print(capsys, verbose):

0 commit comments

Comments
 (0)