Skip to content

Commit 8332993

Browse files
committed
Move reportsizetrends code into separate action
This makes maintenance of the compile-examples action a little easier and also makes the documentation more friendly to the users who don't have the need for the size trends report feature.
1 parent c7c38bb commit 8332993

File tree

12 files changed

+43
-1015
lines changed

12 files changed

+43
-1015
lines changed

.github/workflows/libraries_compile-examples.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ jobs:
2828
run: |
2929
python -m pip install --upgrade pip
3030
pip install --requirement "$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches/requirements.txt"
31-
pip install --requirement "$GITHUB_WORKSPACE/libraries/compile-examples/reportsizetrends/requirements.txt"
3231
3332
- name: Lint with flake8
3433
run: |
3534
pip install --quiet flake8
3635
pip install --quiet pep8-naming
3736
flake8 --config "$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches/.flake8" --show-source "$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches"
38-
flake8 --config "$GITHUB_WORKSPACE/libraries/compile-examples/reportsizetrends/.flake8" --show-source "$GITHUB_WORKSPACE/libraries/compile-examples/reportsizetrends"
3937
4038
- name: Run Python unit tests
4139
run: |
42-
export PYTHONPATH="$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches:$GITHUB_WORKSPACE/libraries/compile-examples/reportsizetrends"
40+
export PYTHONPATH="$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches"
4341
pytest "$GITHUB_WORKSPACE/libraries/compile-examples/compilesketches/tests"
44-
pytest "$GITHUB_WORKSPACE/libraries/compile-examples/reportsizetrends/tests"

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
FROM python:3.8.2
22

3-
ENV PYTHONPATH="/reportsizetrends"
4-
53
# Copies your code file from your action repository to the filesystem path `/` of the container
64
COPY compilesketches /compilesketches
7-
COPY reportsizetrends /reportsizetrends
85

96
# Install python dependencies
107
RUN pip install -r /compilesketches/requirements.txt
11-
RUN pip install -r /reportsizetrends/requirements.txt
128

13-
# Code file to execute when the docker container starts up (`entrypoint.sh`)
9+
# Code file to execute when the docker container starts up
1410
ENTRYPOINT ["python", "/compilesketches/compilesketches.py"]

README.md

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ List of paths containing sketches to compile. These paths will be searched recur
107107

108108
Set to true to show verbose output in the log. Default `false`
109109

110-
### `github-token`
111-
112-
GitHub access token used to get information from the GitHub API. Only needed if you're using the size report features with private repositories. It will be convenient to use [`${{ secrets.GITHUB_TOKEN }}`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token). Default `""`.
113-
114110
### `size-report-sketch`
115111

116112
Name of the sketch used to compare memory usage change. Default `""`.
@@ -119,65 +115,14 @@ Name of the sketch used to compare memory usage change. Default `""`.
119115

120116
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. This report is used by the `arduino/libraries/report-size-deltas` and `arduino/libraries/report-size-trends` actions. Default `"size-deltas-reports"`.
121117

118+
### `github-token`
119+
120+
GitHub access token used to get information from the GitHub API. Only needed if you're using the size report features with private repositories. It will be convenient to use [`${{ secrets.GITHUB_TOKEN }}`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token). Default `""`.
121+
122122
### `enable-size-deltas-report`
123123

124124
Set to `true` to cause the action to determine the change in memory usage for the [`size-reports-sketch`](#size-reports-sketch) between the pull request branch and the tip of the pull request's base branch. 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`.
125125

126-
### `enable-size-trends-report`
127-
128-
Set to `true` to cause the action to record the memory usage of [`size-reports-sketch`](#size-reports-sketch) to a Google Sheets spreadsheet on every push to the repository's default branch. Default `false`.
129-
130-
### `keyfile`
131-
132-
Contents of the Google key file used to update the size trends report Google Sheets spreadsheet. This should be defined using a [GitHub secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets). Default `""`.
133-
1. Open https://console.developers.google.com/project
134-
1. Click the "Create Project" button.
135-
1. In the "Project name" field, enter the name you want for your project.
136-
1. You don't need to select anything from the "Location" menu.
137-
1. Click the button with the three horizontal lines at the top left corner of the window.
138-
1. Hover the mouse pointer over "APIs & Services".
139-
1. Click "Library".
140-
1. Make sure the name of the project you created is selected from the dropdown menu at the top of the window.
141-
1. Click 'Google Sheets API".
142-
1. Click the "Enable" button.
143-
1. Click the "Create Credentials" button.
144-
1. From the "Which API are you using?" menu, select "Google Sheets API".
145-
1. From the "Where will you be calling the API from?" menu, select "Other non-UI".
146-
1. From the "What data will you be accessing?" options, select "Application data".
147-
1. From the "Are you planning to use this API with App Engine or Compute Engine?" options, select "No, I’m not using them".
148-
1. Click the "What credentials do I need?" button.
149-
1. In the "Service account name" field, enter the name you want to use for the service account.
150-
1. From the "Role" menu, select "Project > Editor".
151-
1. From the "Key type" options, select "JSON".
152-
1. Click the "Continue" button. The .json file containing your private key will be downloaded. Save this somewhere safe.
153-
1. Open the downloaded file.
154-
1. Copy the entire contents of the file to the clipboard.
155-
1. Open the GitHub page of the repository you are configuring the GitHub Actions workflow for.
156-
1. Click the "Settings" tab.
157-
1. From the menu on the left side of the window, click "Secrets".
158-
1. Click the "Add a new secret" link.
159-
1. In the "Name" field, enter the variable name you want to use for your secret. This will be used for the `size-trends-report-key-file` argument of the `compile-examples` action in your workflow configuration file. For example, if you named the secret `GOOGLE_KEY_FILE`, you would reference it in your workflow configuration as `${{ secrets.GOOGLE_KEY_FILE }}`.
160-
1. In the "Value" field, paste the contents of the key file.
161-
1. Click the "Add secret" button.
162-
1. Open the downloaded key file again.
163-
1. Copy the email address shown in the `client_email` field.
164-
1. Open Google Sheets: https://docs.google.com/spreadsheets
165-
1. Under "Start a new spreadsheet", click "Blank".
166-
1. Click the "Share" button at the top right corner of the window.
167-
1. If you haven't already, give your spreadsheet a name.
168-
1. Paste the `client_email` email address into the "Enter names or email addresses..." field.
169-
1. Uncheck the box next to "Notify people".
170-
1. Click the "OK" button.
171-
1. In the "Skip sending invitations?" dialog, click the "OK" button.
172-
173-
### `size-trends-report-spreadsheet-id`
174-
175-
The ID of the Google Sheets spreadsheet to write the memory usage trends data to. The URL of your spreadsheet will look something like `https://docs.google.com/spreadsheets/d/15WOp3vp-6AnTnWlNWaNWNl61Fe_j8UJhIKE0rVdV-7U/edit#gid=0`. In this example, the spreadsheet ID is `15WOp3vp-6AnTnWlNWaNWNl61Fe_j8UJhIKE0rVdV-7U`. Default `""`.
176-
177-
### `size-trends-report-sheet-name`
178-
179-
The sheet name in the Google Sheets spreadsheet used for the memory usage trends report. Default `"Sheet1"`.
180-
181126
## Example usage
182127

183128
Only compiling examples:
@@ -203,13 +148,3 @@ Storing the memory usage change report as a [workflow artifact](https://help.git
203148
name: size-deltas-reports
204149
path: size-delta-reports
205150
```
206-
207-
Publishing memory usage trends data to a Google Sheets spreadsheet:
208-
```yaml
209-
- uses: arduino/actions/libraries/compile-examples@master
210-
with:
211-
size-report-sketch: Foobar
212-
enable-size-trends-report: true
213-
keyfile: ${{ secrets.GOOGLE_KEY_FILE }}
214-
size-trends-report-spreadsheet-id: 15WOp3vp-6AnTnWlNWaNWNl61Fe_j8UJhIKE0rVdV-7U
215-
```

action.yml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,18 @@ inputs:
1919
verbose:
2020
description: 'Set to true to show verbose output in the log'
2121
default: false
22-
github-token:
23-
description: 'GitHub access token used to get information from the GitHub API. Only needed if you are using the size report features with private repositories.'
24-
default: ''
2522
size-report-sketch:
2623
description: 'Name of the sketch used to compare memory usage change'
2724
default: ''
2825
sketches-report-path:
2926
description: 'Path in which to save a JSON formatted file containing data from the sketch compilations'
3027
default: 'size-deltas-reports'
28+
github-token:
29+
description: 'GitHub access token used to get information from the GitHub API. Only needed if you are using the size deltas report feature with a private repository.'
30+
default: ''
3131
enable-size-deltas-report:
3232
description: 'Set to true to cause the action to determine the change in memory usage for the size-reports-sketch'
3333
default: false
34-
enable-size-trends-report:
35-
description: 'Set to true to cause the action to record the memory usage of size-reports-sketch'
36-
default: false
37-
keyfile:
38-
description: 'Google key file used to update the size trends report Google Sheets spreadsheet.'
39-
default: ''
40-
size-trends-report-spreadsheet-id:
41-
description: 'The ID of the Google Sheets spreadsheet to write the memory usage trends data to'
42-
default: ''
43-
size-trends-report-sheet-name:
44-
description: 'The sheet name in the Google Sheets spreadsheet used for the memory usage trends report'
45-
default: 'Sheet1'
4634
runs:
4735
using: 'docker'
4836
image: 'Dockerfile'

compilesketches/compilesketches.py

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
import yaml
1919
import yaml.parser
2020

21-
import reportsizetrends
22-
2321

2422
def main():
2523
if "INPUT_SIZE-DELTAS-REPORT-FOLDER-NAME" in os.environ:
2624
print("::warning::The size-deltas-report-folder-name input is deprecated. Use the equivalent input: "
2725
"sketches-report-path instead.")
2826
os.environ["INPUT_SKETCHES-REPORT-PATH"] = os.environ["INPUT_SIZE-DELTAS-REPORT-FOLDER-NAME"]
2927

28+
if "INPUT_ENABLE-SIZE-TRENDS-REPORT" in os.environ:
29+
print("::warning::The size trends report feature has been moved to a dedicated action. See the documentation "
30+
"at https://github.com/arduino/actions/tree/report-size-trends-action/libraries/report-size-trends")
31+
3032
compile_sketches = CompileSketches(
3133
cli_version=os.environ["INPUT_CLI-VERSION"],
3234
fqbn_arg=os.environ["INPUT_FQBN"],
@@ -37,11 +39,7 @@ def main():
3739
github_token=os.environ["INPUT_GITHUB-TOKEN"],
3840
report_sketch=os.environ["INPUT_SIZE-REPORT-SKETCH"],
3941
enable_size_deltas_report=os.environ["INPUT_ENABLE-SIZE-DELTAS-REPORT"],
40-
sketches_report_path=os.environ["INPUT_SKETCHES-REPORT-PATH"],
41-
enable_size_trends_report=os.environ["INPUT_ENABLE-SIZE-TRENDS-REPORT"],
42-
google_key_file=os.environ["INPUT_KEYFILE"],
43-
size_trends_report_spreadsheet_id=os.environ["INPUT_SIZE-TRENDS-REPORT-SPREADSHEET-ID"],
44-
size_trends_report_sheet_name=os.environ["INPUT_SIZE-TRENDS-REPORT-SHEET-NAME"]
42+
sketches_report_path=os.environ["INPUT_SKETCHES-REPORT-PATH"]
4543
)
4644

4745
compile_sketches.compile_sketches()
@@ -64,13 +62,6 @@ class CompileSketches:
6462
enable_size_deltas_report -- set to "true" to cause the action to determine the change in memory usage for the
6563
report_sketch ("true", "false")
6664
sketches_report_path -- folder to save the sketches report to
67-
enable_size_trends_report -- whether to record the memory usage of report_sketch
68-
("true", "false")
69-
google_key_file -- Google key file used to update the size trends report Google Sheets spreadsheet
70-
size_trends_report_spreadsheet_id -- the ID of the Google Sheets spreadsheet to write the memory usage trends data
71-
to
72-
size_trends_report_sheet_name -- the sheet name in the Google Sheets spreadsheet used for the memory usage trends
73-
report
7465
"""
7566

7667
class RunCommandOutput(enum.Enum):
@@ -108,8 +99,7 @@ class RunCommandOutput(enum.Enum):
10899
latest_release_indicator = "latest"
109100

110101
def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, verbose, github_token, report_sketch,
111-
enable_size_deltas_report, sketches_report_path, enable_size_trends_report, google_key_file,
112-
size_trends_report_spreadsheet_id, size_trends_report_sheet_name):
102+
enable_size_deltas_report, sketches_report_path):
113103
"""Process, store, and validate the action's inputs."""
114104
self.cli_version = cli_version
115105

@@ -142,25 +132,7 @@ def __init__(self, cli_version, fqbn_arg, platforms, libraries, sketch_paths, ve
142132

143133
self.sketches_report_path = pathlib.PurePath(sketches_report_path)
144134

145-
self.enable_size_trends_report = parse_boolean_input(boolean_input=enable_size_trends_report)
146-
# The enable-size-trends-report input has a default value so it should always be either True or False
147-
if self.enable_size_trends_report is None:
148-
print("::error::Invalid value for enable-size-trends-report input")
149-
sys.exit(1)
150-
151-
self.google_key_file = google_key_file
152-
if self.enable_size_trends_report and self.google_key_file == "":
153-
print("::error::keyfile input was not defined")
154-
sys.exit(1)
155-
156-
self.size_trends_report_spreadsheet_id = size_trends_report_spreadsheet_id
157-
if self.enable_size_trends_report and self.size_trends_report_spreadsheet_id == "":
158-
print("::error::size-trends-report-spreadsheet-id input was not defined")
159-
sys.exit(1)
160-
161-
self.size_trends_report_sheet_name = size_trends_report_sheet_name
162-
163-
if (self.enable_size_deltas_report or self.enable_size_trends_report) and self.report_sketch == "":
135+
if self.enable_size_deltas_report and self.report_sketch == "":
164136
print("::error::size-report-sketch input was not defined")
165137
sys.exit(1)
166138

@@ -193,9 +165,6 @@ def compile_sketches(self):
193165
# TODO: The current behavior is to only write the report for the report sketch, but the plan is to change to
194166
# reporting data for all sketches, thus the passing of sketch_report to the function
195167
self.create_sketches_report_file(sketches_report=sketch_report)
196-
# Make the memory usage trends report
197-
if self.do_size_trends_report():
198-
self.make_size_trends_report()
199168

200169
if not all_compilations_successful:
201170
print("::error::One or more compilations failed")
@@ -973,32 +942,6 @@ def get_size_deltas(self, current_sketch_report, previous_sketch_report):
973942

974943
return sketch_report
975944

976-
def do_size_trends_report(self):
977-
"""Return whether the size trends report is enabled"""
978-
return (
979-
self.enable_size_trends_report
980-
and os.environ["GITHUB_EVENT_NAME"] == "push"
981-
and self.is_default_branch()
982-
)
983-
984-
def is_default_branch(self):
985-
"""Return whether the current branch is the repository's default branch"""
986-
current_branch_name = os.environ["GITHUB_REF"].rpartition("/")[2]
987-
988-
try:
989-
default_branch_name = self.github_api.get_repo(os.environ["GITHUB_REPOSITORY"]).default_branch
990-
except github.UnknownObjectException:
991-
print("::error::Unable to access repository data. Please specify the github-token input in your workflow"
992-
" configuration.")
993-
sys.exit(1)
994-
995-
if current_branch_name != default_branch_name:
996-
is_default_branch = False
997-
else:
998-
is_default_branch = True
999-
1000-
return is_default_branch
1001-
1002945
def get_sketch_report_from_sketches_report(self, sketches_report):
1003946
"""Return the report for the report sketch
1004947
@@ -1016,23 +959,6 @@ def get_sketch_report_from_sketches_report(self, sketches_report):
1016959
print("::error::size-report-sketch:", self.report_sketch, "was not found")
1017960
sys.exit(1)
1018961

1019-
def make_size_trends_report(self):
1020-
"""Publish the size data for the report sketch to a Google Sheets spreadsheet.
1021-
1022-
Keyword arguments:
1023-
sketch_report -- report for the sketch report
1024-
"""
1025-
self.verbose_print("Making size trends report")
1026-
1027-
report_size_trends = reportsizetrends.ReportSizeTrends(
1028-
sketches_report_path=str(self.sketches_report_path),
1029-
google_key_file=self.google_key_file,
1030-
spreadsheet_id=self.size_trends_report_spreadsheet_id,
1031-
sheet_name=self.size_trends_report_sheet_name
1032-
)
1033-
1034-
report_size_trends.report_size_trends()
1035-
1036962
def create_sketches_report_file(self, sketches_report):
1037963
"""Write the report for the report sketch to a file.
1038964

0 commit comments

Comments
 (0)