Skip to content

Commit

Permalink
pushflatpak: pass build log url to flat-manager-client (bug 1859510)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcristau committed Oct 30, 2023
1 parent 16d0260 commit d717f34
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions pushflatpakscript/src/pushflatpakscript/artifacts.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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")
6 changes: 5 additions & 1 deletion pushflatpakscript/src/pushflatpakscript/flathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -145,14 +146,17 @@ 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
return

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)
Expand Down
11 changes: 10 additions & 1 deletion pushflatpakscript/tests/test_artifacts.py
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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"
1 change: 1 addition & 0 deletions pushflatpakscript/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"VERBOSE": "true",
"FLATHUB_URL": "https://flat.example",
"FLAT_MANAGER_CLIENT": "/app/bin/flat-manager-client",
"TASKCLUSTER_ROOT_URL": "http://taskcluster",
}


Expand Down

0 comments on commit d717f34

Please sign in to comment.