Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sketches reports with missing size data #31

Merged
merged 4 commits into from
Mar 31, 2023
Merged

Handle sketches reports with missing size data #31

merged 4 commits into from
Mar 31, 2023

Conversation

per1234
Copy link
Collaborator

@per1234 per1234 commented Mar 31, 2023

Previously, the action's code assumed that the sketches reports artifacts would always contain size deltas data. If a report was present that did not contain this data, the action would fail with a KeyError error for keys missing from the report.

For example:

Traceback (most recent call last):
  File "/reportsizedeltas/reportsizedeltas.py", line 737, in <module>
    main()  # pragma: no cover
  File "/reportsizedeltas/reportsizedeltas.py", line 32, in main
    report_size_deltas.report_size_deltas()
  File "/reportsizedeltas/reportsizedeltas.py", line 95, in report_size_deltas
    self.report_size_deltas_from_workflow_artifacts()
  File "/reportsizedeltas/reportsizedeltas.py", line 149, in report_size_deltas_from_workflow_artifacts
    sketches_reports = self.get_sketches_reports(artifact_folder_object=artifact_folder_object)
  File "/reportsizedeltas/reportsizedeltas.py", line 295, in get_sketches_reports
    not in report_data[self.ReportKeys.boards][0][self.ReportKeys.sizes][0])
KeyError: 'sizes'

The most common cause of a compilation not producing size data is a compilation error. In this case the default arduino/compile-sketches workflow configuration would not upload a sketches report workflow artifact (because the upload is done in a subsequent step and GitHub Actions exits the job immediately when a step fails) so the arduino/report-size-deltas action's inability to handle the resulting report format was only an issue in unusual workflow configurations.

There is another cause of a compilation not producing size data: the boards platform was not configured to produce the data. Previously, all known Arduino boards platforms produced at least some size data so the problem of the action's lack of compatibility with these boards was only hypothetical. However, the "Arduino Mbed OS Portenta Boards" platform now contains two boards which are missing the configuration to produce the size data:

This meant that the action is broken by any sketches reports produced by compiling for either of those boards.

One possible fix would be to make the arduino/compile-sketches action add all expected objects to the sketches report even when the compilation does not produce any data to populated them with. But this seems like the wrong approach. So the alternative approach was taken of making the arduino/report-size-deltas action check for the presence of the data. If it is not present, a "N/A" is added to the report in place of the data.

In addition to the per-sketch memory usage data, the sketches report includes per-board data that summarizes the
per-sketch data.

Previous versions of the arduino/compile-sketches action did not add the key for the summary data to the report when
none of the compilations produced size data. When the arduino/report-size-deltas action attempted to parse a sketches
report with this format, it would error:

```
Traceback (most recent call last):
  File "/reportsizedeltas/reportsizedeltas.py", line 737, in <module>
    main()  # pragma: no cover
  File "/reportsizedeltas/reportsizedeltas.py", line 32, in main
    report_size_deltas.report_size_deltas()
  File "/reportsizedeltas/reportsizedeltas.py", line 95, in report_size_deltas
    self.report_size_deltas_from_workflow_artifacts()
  File "/reportsizedeltas/reportsizedeltas.py", line 149, in report_size_deltas_from_workflow_artifacts
    sketches_reports = self.get_sketches_reports(artifact_folder_object=artifact_folder_object)
  File "/reportsizedeltas/reportsizedeltas.py", line 295, in get_sketches_reports
    not in report_data[self.ReportKeys.boards][0][self.ReportKeys.sizes][0])
KeyError: 'sizes'
```

The most common cause of a compilation not producing size data is a compilation error. In this case the default
arduino/compile-sketches workflow configuration would not upload a sketches report workflow artifact (because the upload
is done in a subsequent step and GitHub Actions exits the job immediately when a step fails) so the
arduino/report-size-deltas action's inability to handle the resulting report format was only an issue in unusual
workflow configurations.

There is another cause of a compilation not producing size data: the boards platform was not configured to produce the
data. Previously, all known Arduino boards platforms produced at least some size data so the problem of the action's
lack of compatibility with these boards was only hypothetical. However, the "Arduino Mbed OS Portenta Boards" platform
now contains two boards which are missing the configuration to produce the size data:

- Portenta H7
- Portenta X8

This meant that the action is broken by any sketches reports produced by compiling for either of those boards.

The arduino/compile-sketches action was changed to always add a `boards[*].sizes` object to the sketches report, even
when it doesn't have any size data to fill it. So the problem will no longer occur with sketches reports produced by the
new version of that action. However, repositories may still contain sketches report artifacts with the old format so the
arduino/report-size-deltas action must be able to continue to work in the presence of these reports. That is
accomplished by skipping any report that is missing a `boards[*].sizes` key.
Previously, the action's code assumed that the sketches reports artifacts would always contain size deltas data. If a
report was present that did not contain this data, the action would fail with a `KeyError` error for the missing report
key.

The most common cause of a compilation not producing size data is a compilation error. In this case the default
arduino/compile-sketches workflow configuration would not upload a sketches report workflow artifact (because the upload
is done in a subsequent step and GitHub Actions exits the job immediately when a step fails) so the
arduino/report-size-deltas action's inability to handle the resulting report format was only an issue in unusual
workflow configurations.

There is another cause of a compilation not producing size data: the boards platform was not configured to produce the
data. Previously, all known Arduino boards platforms produced at least some size data so the problem of the action's
lack of compatibility with these boards was only hypothetical. However, the "Arduino Mbed OS Portenta Boards" platform
now contains two boards which are missing the configuration to produce the size data:

- Portenta H7
- Portenta X8

This meant that the action is broken by any sketches reports produced by compiling for either of those boards.

One possible fix would be to make the arduino/compile-sketches action add deltas data objects to the sketches report
even when the compilation does not produce any data to calculate data from. But this seems like the wrong approach. So
the alternative approach was taken of making the arduino/report-size-deltas action check for the presence of the data.
If it is not present, a "N/A" is added to the report in place of the data.
Flake8 is configured to enforce a cyclomatic complexity limit of 10 on the project.

The recent changes caused an increase of the cyclomatic complexity in ReportSizeDeltas.generate_report to 12. In order
to reduce this, code was moved into dedicated functions.
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Mar 31, 2023
@per1234 per1234 self-assigned this Mar 31, 2023
@codecov-commenter
Copy link

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (1cb4a4f) 100.00% compared to head (d7b275e) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #31   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          707       726   +19     
=========================================
+ Hits           707       726   +19     
Impacted Files Coverage Δ
reportsizedeltas/reportsizedeltas.py 100.00% <100.00%> (ø)
reportsizedeltas/tests/test_reportsizedeltas.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@per1234 per1234 merged commit 239ce6d into arduino:main Mar 31, 2023
@per1234 per1234 deleted the handle-missing-deltas branch March 31, 2023 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants