diff --git a/pushflatpakscript/src/pushflatpakscript/artifacts.py b/pushflatpakscript/src/pushflatpakscript/artifacts.py index 68dc1c7a7..0a150ab2e 100644 --- a/pushflatpakscript/src/pushflatpakscript/artifacts.py +++ b/pushflatpakscript/src/pushflatpakscript/artifacts.py @@ -1,6 +1,7 @@ from scriptworker import artifacts from scriptworker.exceptions import TaskVerificationError from scriptworker.utils import get_single_item_from_sequence +from taskcluster import Queue def get_flatpak_file_path(context): @@ -15,3 +16,11 @@ def get_flatpak_file_path(context): no_item_error_message="No upstream artifact is a tar.xz", too_many_item_error_message="Too many flatpaks detected", ) + + +def get_flatpak_build_log_url(context): + upstream_artifacts = context.task["payload"]["upstreamArtifacts"] + task_ids_and_relative_paths = ((artifact_definition["taskId"], artifact_definition["paths"]) for artifact_definition in upstream_artifacts) + task_id, paths = get_single_item_from_sequence(task_ids_and_relative_paths, lambda t: any(p.endswith(".flatpak.tar.xz") for p in t[1]), ErrorClass=TaskVerificationError) + queue = Queue(options={"rootUrl": context.config["taskcluster_root_url"]}) + return queue.buildUrl("getLatestArtifact", task_id, "public/logs/live_backing.log") diff --git a/pushflatpakscript/src/pushflatpakscript/flathub.py b/pushflatpakscript/src/pushflatpakscript/flathub.py index fd8492c85..f8cb2b633 100644 --- a/pushflatpakscript/src/pushflatpakscript/flathub.py +++ b/pushflatpakscript/src/pushflatpakscript/flathub.py @@ -7,6 +7,7 @@ from scriptworker.exceptions import TaskVerificationError from pushflatpakscript import task +from pushflatpakscript.artifacts import get_flatpak_build_log_url from pushflatpakscript.constants import TAR_MAX_SIZE_IN_MB log = logging.getLogger(__name__) @@ -145,6 +146,9 @@ def sanitize_buildid(bytes_input): def push(context, flatpak_file_path, channel): """Publishes a flatpak into a given channel.""" + + build_log = get_flatpak_build_log_url(context) + if not task.is_allowed_to_push_to_flathub(context.config, channel=channel): log.warning("Not allowed to push to Flathub. Skipping push...") # We don't raise an error because we still want green tasks on dev instances @@ -152,7 +156,7 @@ def push(context, flatpak_file_path, channel): token_args = ["--token-file", context.config["token_locations"][channel]] log.info("Grab a flatpak buildid from Flathub ...") - publish_build_output = run_flat_manager_client_process(context, token_args + ["create", context.config["flathub_url"], channel]) + publish_build_output = run_flat_manager_client_process(context, token_args + ["create", context.config["flathub_url"], channel, "--build-log-url", build_log]) log.info("Sanitize the buildid received from Flathub ...") publish_build_output = sanitize_buildid(publish_build_output) diff --git a/pushflatpakscript/tests/test_artifacts.py b/pushflatpakscript/tests/test_artifacts.py index 2c736d217..a3b9e0881 100644 --- a/pushflatpakscript/tests/test_artifacts.py +++ b/pushflatpakscript/tests/test_artifacts.py @@ -1,8 +1,10 @@ import pytest +from unittest.mock import MagicMock + from scriptworker import artifacts from scriptworker.exceptions import TaskVerificationError -from pushflatpakscript.artifacts import get_flatpak_file_path +from pushflatpakscript.artifacts import get_flatpak_file_path, get_flatpak_build_log_url @pytest.mark.parametrize( @@ -25,3 +27,10 @@ def test_get_flatpak_file_path(monkeypatch, raises, returned, expected): get_flatpak_file_path(context) else: assert get_flatpak_file_path(context) == expected + + +def test_get_flatpak_build_url(): + context = MagicMock() + context.config = {"taskcluster_root_url": "http://taskcluster"} + context.task = {"payload": {"upstreamArtifacts": [{"taskId": "deadbeef", "paths": ["/path/to/file.flatpak.tar.xz"]}]}} + assert get_flatpak_build_log_url(context) == "http://taskcluster/api/queue/v1/task/deadbeef/artifacts/public%2Flogs%2Flive_backing.log" diff --git a/pushflatpakscript/tests/test_config.py b/pushflatpakscript/tests/test_config.py index 79631191c..95283a116 100644 --- a/pushflatpakscript/tests/test_config.py +++ b/pushflatpakscript/tests/test_config.py @@ -11,6 +11,7 @@ "VERBOSE": "true", "FLATHUB_URL": "https://flat.example", "FLAT_MANAGER_CLIENT": "/app/bin/flat-manager-client", + "TASKCLUSTER_ROOT_URL": "http://taskcluster", }