Skip to content

Skip expired workflow artifacts #10

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

Merged
merged 1 commit into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reportsizedeltas/reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def get_artifact_download_url_for_run(self, run_id):

for artifact_data in artifacts_data["artifacts"]:
# The artifact is identified by a specific name
if artifact_data["name"] == self.sketches_reports_source:
if not artifact_data["expired"] and artifact_data["name"] == self.sketches_reports_source:
return artifact_data["archive_download_url"]

page_number += 1
Expand Down
36 changes: 22 additions & 14 deletions reportsizedeltas/tests/test_reportsizedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,9 @@ def test_get_artifact_download_url_for_sha():
report_size_deltas.get_artifact_download_url_for_run.assert_called_once_with(run_id=run_id)


def test_get_artifact_download_url_for_run():
@pytest.mark.parametrize("expired", [True, False])
@pytest.mark.parametrize("artifact_name", ["test_sketches_reports_source", "incorrect-artifact-name"])
def test_get_artifact_download_url_for_run(expired, artifact_name):
repository_name = "test_name/test_repo"
sketches_reports_source = "test_sketches_reports_source"
archive_download_url = "archive_download_url"
Expand All @@ -420,29 +422,35 @@ def test_get_artifact_download_url_for_run():
report_size_deltas = get_reportsizedeltas_object(repository_name=repository_name,
sketches_reports_source=sketches_reports_source)

json_data = {"artifacts": [{"name": sketches_reports_source, "archive_download_url": archive_download_url},
{"name": "bar123", "archive_download_url": "wrong_artifact_url"}]}
json_data = {
"artifacts": [
{
"name": artifact_name,
"archive_download_url": archive_download_url,
"expired": expired
},
{
"name": "bar123",
"archive_download_url": "wrong_artifact_url",
"expired": False
}
]
}
report_size_deltas.api_request = unittest.mock.MagicMock(return_value={"json_data": json_data,
"additional_pages": False,
"page_count": 1})

# Artifact name match
assert archive_download_url == report_size_deltas.get_artifact_download_url_for_run(run_id=run_id)
download_url = report_size_deltas.get_artifact_download_url_for_run(run_id=run_id)
if not expired and artifact_name == sketches_reports_source:
assert download_url == archive_download_url
else:
assert download_url is None

report_size_deltas.api_request.assert_called_once_with(
request="repos/" + repository_name + "/actions/runs/" + str(run_id)
+ "/artifacts",
page_number=1)

json_data = {"artifacts": [{"name": "foo123", "archive_download_url": "test_artifact_url"},
{"name": "bar123", "archive_download_url": "wrong_artifact_url"}]}
report_size_deltas.api_request = unittest.mock.MagicMock(return_value={"json_data": json_data,
"additional_pages": False,
"page_count": 1})

# No artifact name match
assert report_size_deltas.get_artifact_download_url_for_run(run_id=run_id) is None


@pytest.mark.parametrize("test_artifact_name, expected_success",
[("correct-artifact-name", True),
Expand Down