Skip to content

Commit d4ae92e

Browse files
committed
Use more concise input name
I decided the "-name" part of the input name was superfluous. This is part of a single PR, so no further backwards compatibility measures are necessary. I just don't feel like making the effort to fixup the previous name change commit and deal with all the conflicts while rebasing.
1 parent 30810a6 commit d4ae92e

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This action comments on the pull request with a report on the resulting change i
88

99
## Inputs
1010

11-
### `sketches-reports-source-name`
11+
### `sketches-reports-source`
1212

1313
**Default**: "size-deltas-reports"
1414

@@ -20,7 +20,7 @@ Recommended for public repositories.
2020

2121
The use of a scheduled workflow is necessary in order for the action to have the [write permissions required to comment on pull requests submitted from forks](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token).
2222

23-
In this usage, the `sketches-reports-source-name` defines the name of the workflow artifact that contains the memory usage data, as specified to the [`actions/upload-artifact`](https://github.com/actions/upload-artifact) action via its `name` input.
23+
In this usage, the `sketches-reports-source` defines the name of the workflow artifact that contains the memory usage data, as specified to the [`actions/upload-artifact`](https://github.com/actions/upload-artifact) action via its `name` input.
2424

2525
#### Run from the same workflow as the [`arduino/compile-sketches`](https://github.com/arduino/compile-sketches) action
2626

@@ -32,7 +32,7 @@ In order to get reports for pull requests from forks, the ["Send write tokens to
3232

3333
If the "Send write tokens to workflows from fork pull requests" setting is not enabled but the ["Run workflows from fork pull requests" setting](https://docs.github.com/en/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository#enabling-workflows-for-private-repository-forks) is enabled, the workflow should be configured to only run the action when the pull request is not from a fork (`if: github.event.pull_request.head.repo.full_name == github.repository`). This will prevent workflow job failures that would otherwise be caused when the report creation failed due to not having the necessary write permissions.
3434

35-
In this usage, the `sketches-reports-source-name` defines the path to the folder containing the memory usage data, as specified to the [`actions/download-artifact`](https://github.com/actions/download-artifact) action via its `path` input.
35+
In this usage, the `sketches-reports-source` defines the path to the folder containing the memory usage data, as specified to the [`actions/download-artifact`](https://github.com/actions/download-artifact) action via its `path` input.
3636

3737
### `github-token`
3838

@@ -110,7 +110,7 @@ jobs:
110110
if: github.event_name == 'pull_request' # Only run the job when the workflow is triggered by a pull request
111111
runs-on: ubuntu-latest
112112
steps:
113-
# This step is needed to get the size data produced by the compile job
113+
# This step is needed to get the size data produced by the compile jobs
114114
- name: Download sketches reports artifact
115115
uses: actions/download-artifact@v2
116116
with:
@@ -119,5 +119,5 @@ jobs:
119119
120120
- uses: arduino/report-size-deltas@main
121121
with:
122-
sketches-reports-source-name: ${{ env.SKETCHES_REPORTS_PATH }}
122+
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
123123
```

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Report Arduino Sketch Size Deltas'
22
description: 'Comments on the pull request with a report on the resulting change in memory usage of Arduino sketches'
33
inputs:
4-
sketches-reports-source-name:
4+
sketches-reports-source:
55
description: 'When run from scheduled workflow, name of the workflow artifact that contains sketches reports. When run from a pull request triggered workflow, path to the folder containing sketches reports.'
66
default: 'size-deltas-reports'
77
github-token:

reportsizedeltas/reportsizedeltas.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ def main():
2222

2323
if "INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME" in os.environ:
2424
print("::warning::The size-deltas-report-artifact-name input is deprecated. Use the equivalent input: "
25-
"sketches-reports-source-name instead.")
26-
os.environ["INPUT_SKETCHES-REPORTS-SOURCE-NAME"] = os.environ["INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME"]
25+
"sketches-reports-source instead.")
26+
os.environ["INPUT_SKETCHES-REPORTS-SOURCE"] = os.environ["INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME"]
2727

2828
report_size_deltas = ReportSizeDeltas(repository_name=os.environ["GITHUB_REPOSITORY"],
29-
sketches_reports_source_name=os.environ["INPUT_SKETCHES-REPORTS-SOURCE-NAME"],
29+
sketches_reports_source=os.environ["INPUT_SKETCHES-REPORTS-SOURCE"],
3030
token=os.environ["INPUT_GITHUB-TOKEN"])
3131

3232
report_size_deltas.report_size_deltas()
@@ -79,9 +79,9 @@ class ReportKeys:
7979
sketches = "sketches"
8080
compilation_success = "compilation_success"
8181

82-
def __init__(self, repository_name, sketches_reports_source_name, token):
82+
def __init__(self, repository_name, sketches_reports_source, token):
8383
self.repository_name = repository_name
84-
self.sketches_reports_source_name = sketches_reports_source_name
84+
self.sketches_reports_source = sketches_reports_source
8585
self.token = token
8686

8787
def report_size_deltas(self):
@@ -96,7 +96,7 @@ def report_size_deltas(self):
9696

9797
def report_size_deltas_from_local_reports(self):
9898
"""Comment a report of memory usage change to the pull request."""
99-
sketches_reports_folder = pathlib.Path(os.environ["GITHUB_WORKSPACE"], self.sketches_reports_source_name)
99+
sketches_reports_folder = pathlib.Path(os.environ["GITHUB_WORKSPACE"], self.sketches_reports_source)
100100
sketches_reports = self.get_sketches_reports(artifact_folder_object=sketches_reports_folder)
101101

102102
if sketches_reports:
@@ -239,7 +239,7 @@ def get_artifact_download_url_for_run(self, run_id):
239239

240240
for artifact_data in artifacts_data["artifacts"]:
241241
# The artifact is identified by a specific name
242-
if artifact_data["name"] == self.sketches_reports_source_name:
242+
if artifact_data["name"] == self.sketches_reports_source:
243243
return artifact_data["archive_download_url"]
244244

245245
page_number += 1
@@ -258,13 +258,13 @@ def get_artifact(self, artifact_download_url):
258258
artifact_folder_object = tempfile.TemporaryDirectory(prefix="reportsizedeltas-")
259259
try:
260260
# Download artifact
261-
with open(file=artifact_folder_object.name + "/" + self.sketches_reports_source_name + ".zip",
261+
with open(file=artifact_folder_object.name + "/" + self.sketches_reports_source + ".zip",
262262
mode="wb") as out_file:
263263
with self.raw_http_request(url=artifact_download_url) as fp:
264264
out_file.write(fp.read())
265265

266266
# Unzip artifact
267-
artifact_zip_file = artifact_folder_object.name + "/" + self.sketches_reports_source_name + ".zip"
267+
artifact_zip_file = artifact_folder_object.name + "/" + self.sketches_reports_source + ".zip"
268268
with zipfile.ZipFile(file=artifact_zip_file, mode="r") as zip_ref:
269269
zip_ref.extractall(path=artifact_folder_object.name)
270270
os.remove(artifact_zip_file)

reportsizedeltas/tests/test_reportsizedeltas.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919

2020

2121
def get_reportsizedeltas_object(repository_name="FooOwner/BarRepository",
22-
sketches_reports_source_name="foo-artifact-name",
22+
sketches_reports_source="foo-artifact-name",
2323
token="foo token"):
2424
"""Return a reportsizedeltas.ReportSizeDeltas object to use in tests.
2525
2626
Keyword arguments:
2727
repository_name -- repository owner and name e.g., octocat/Hello-World
28-
sketches_reports_source_name -- name of the workflow artifact that contains the memory usage data
28+
sketches_reports_source -- name of the workflow artifact that contains the memory usage data
2929
token -- GitHub access token
3030
"""
3131
return reportsizedeltas.ReportSizeDeltas(repository_name=repository_name,
32-
sketches_reports_source_name=sketches_reports_source_name, token=token)
32+
sketches_reports_source=sketches_reports_source, token=token)
3333

3434

3535
def directories_are_same(left_directory, right_directory):
@@ -99,11 +99,11 @@ def setup_environment_variables(monkeypatch):
9999
class ActionInputs:
100100
"""A container for the values of the environment variables"""
101101
repository_name = "GoldenOwner/GoldenRepository"
102-
sketches_reports_source_name = "golden-artifact-name"
102+
sketches_reports_source = "golden-source-name"
103103
token = "golden-github-token"
104104

105105
monkeypatch.setenv("GITHUB_REPOSITORY", ActionInputs.repository_name)
106-
monkeypatch.setenv("INPUT_SKETCHES-REPORTS-SOURCE-NAME", ActionInputs.sketches_reports_source_name)
106+
monkeypatch.setenv("INPUT_SKETCHES-REPORTS-SOURCE", ActionInputs.sketches_reports_source)
107107
monkeypatch.setenv("INPUT_GITHUB-TOKEN", ActionInputs.token)
108108

109109
return ActionInputs()
@@ -125,7 +125,7 @@ def report_size_deltas(self):
125125
reportsizedeltas.set_verbosity.assert_called_once_with(enable_verbosity=False)
126126
reportsizedeltas.ReportSizeDeltas.assert_called_once_with(
127127
repository_name=setup_environment_variables.repository_name,
128-
sketches_reports_source_name=setup_environment_variables.sketches_reports_source_name,
128+
sketches_reports_source=setup_environment_variables.sketches_reports_source,
129129
token=setup_environment_variables.token
130130
)
131131
ReportSizeDeltas.report_size_deltas.assert_called_once()
@@ -140,9 +140,9 @@ def test_main_size_deltas_report_artifact_name_deprecation_warning(capsys,
140140

141141
if use_size_deltas_report_artifact_name:
142142
monkeypatch.setenv("INPUT_SIZE-DELTAS-REPORTS-ARTIFACT-NAME", size_deltas_report_artifact_name)
143-
expected_sketches_reports_source_name = size_deltas_report_artifact_name
143+
expected_sketches_reports_source = size_deltas_report_artifact_name
144144
else:
145-
expected_sketches_reports_source_name = setup_environment_variables.sketches_reports_source_name
145+
expected_sketches_reports_source = setup_environment_variables.sketches_reports_source
146146

147147
class ReportSizeDeltas:
148148
"""Stub"""
@@ -162,12 +162,12 @@ def report_size_deltas(self):
162162
expected_output = (
163163
expected_output
164164
+ "::warning::The size-deltas-report-artifact-name input is deprecated. Use the equivalent input: "
165-
"sketches-reports-source-name instead."
165+
"sketches-reports-source instead."
166166
)
167167

168168
assert capsys.readouterr().out.strip() == expected_output
169169

170-
assert os.environ["INPUT_SKETCHES-REPORTS-SOURCE-NAME"] == expected_sketches_reports_source_name
170+
assert os.environ["INPUT_SKETCHES-REPORTS-SOURCE"] == expected_sketches_reports_source
171171

172172

173173
def test_set_verbosity():
@@ -200,9 +200,9 @@ def test_report_size_deltas(mocker, monkeypatch):
200200

201201

202202
def test_report_size_deltas_from_local_reports(mocker, monkeypatch):
203-
sketches_reports_source_name = "golden-sketches-reports-source-path"
203+
sketches_reports_source = "golden-sketches-reports-source-path"
204204
github_workspace = "golden-github-workspace"
205-
sketches_reports_folder = pathlib.Path(github_workspace, sketches_reports_source_name)
205+
sketches_reports_folder = pathlib.Path(github_workspace, sketches_reports_source)
206206
sketches_reports = unittest.mock.sentinel.sketches_reports
207207
report = "golden report"
208208

@@ -214,7 +214,7 @@ def test_report_size_deltas_from_local_reports(mocker, monkeypatch):
214214
mocker.patch("reportsizedeltas.ReportSizeDeltas.generate_report", autospec=True, return_value=report)
215215
mocker.patch("reportsizedeltas.ReportSizeDeltas.comment_report", autospec=True)
216216

217-
report_size_deltas = get_reportsizedeltas_object(sketches_reports_source_name=sketches_reports_source_name)
217+
report_size_deltas = get_reportsizedeltas_object(sketches_reports_source=sketches_reports_source)
218218

219219
# Test handling of no sketches reports data available
220220
reportsizedeltas.ReportSizeDeltas.get_sketches_reports.return_value = None
@@ -413,14 +413,14 @@ def test_get_artifact_download_url_for_sha():
413413

414414
def test_get_artifact_download_url_for_run():
415415
repository_name = "test_name/test_repo"
416-
sketches_reports_source_name = "test_sketches_reports_source_name"
416+
sketches_reports_source = "test_sketches_reports_source"
417417
archive_download_url = "archive_download_url"
418418
run_id = "1234"
419419

420420
report_size_deltas = get_reportsizedeltas_object(repository_name=repository_name,
421-
sketches_reports_source_name=sketches_reports_source_name)
421+
sketches_reports_source=sketches_reports_source)
422422

423-
json_data = {"artifacts": [{"name": sketches_reports_source_name, "archive_download_url": archive_download_url},
423+
json_data = {"artifacts": [{"name": sketches_reports_source, "archive_download_url": archive_download_url},
424424
{"name": "bar123", "archive_download_url": "wrong_artifact_url"}]}
425425
report_size_deltas.api_request = unittest.mock.MagicMock(return_value={"json_data": json_data,
426426
"additional_pages": False,

0 commit comments

Comments
 (0)