Skip to content
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

pushflatpak: pass flatpak-repackage log url to flat-manager-client (bug 1859510) #861

Merged
merged 4 commits into from
Nov 14, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions pushflatpakscript/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ RUN python -m venv /app \
&& /app/configloader_venv/bin/pip install . \
&& python -m venv /app/flat_manager_venv \
&& /app/flat_manager_venv/bin/pip install -r /app/pushflatpakscript/requirements/flat-manager.txt \
&& curl -s \
https://raw.githubusercontent.com/flatpak/flat-manager/a0005a8046a290590ccb53b631b9949ba52fd8cd/flat-manager-client | \
&& curl -Ls \
https://github.com/flatpak/flat-manager/raw/d9d7972b24de6022c7079f8721fd8335c3319dc5/flat-manager-client | \
sed -e '1i#!/app/flat_manager_venv/bin/python' -e '1d' > /app/flat_manager_venv/bin/flat-manager-client \
&& chmod 755 /app/flat_manager_venv/bin/flat-manager-client \
&& echo "5024c853d7529e82fc4a9fb9b982e561598df033545187238c9be8c791a6797c /app/flat_manager_venv/bin/flat-manager-client" | sha256sum -c \
&& cd /app


Expand Down
1 change: 1 addition & 0 deletions pushflatpakscript/docker.d/init_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test_var_set() {
}

test_var_set 'FLATHUB_URL'
test_var_set 'TASKCLUSTER_ROOT_URL'

export FLAT_MANAGER_CLIENT=/app/flat_manager_venv/bin/flat-manager-client

Expand Down
1 change: 1 addition & 0 deletions pushflatpakscript/docker.d/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ verbose: { "$eval": "VERBOSE == 'true'" }
push_to_flathub: { "$eval": "ENV == 'prod'" }
flathub_url: { "$eval": "FLATHUB_URL" }
flat_manager_client: { "$eval": "FLAT_MANAGER_CLIENT" }
taskcluster_root_url: { "$eval": "TASKCLUSTER_ROOT_URL" }
token_locations:
$if: 'ENV == "prod"'
then:
Expand Down
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")
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"push_to_flathub",
"token_locations",
"flathub_url",
"flat_manager_client"
"flat_manager_client",
"taskcluster_root_url"
],
"properties": {
"push_to_flathub": {
Expand All @@ -22,6 +23,9 @@
"additionalProperties": {
"type": "string"
}
},
"taskcluster_root_url": {
"type": "string"
}
}
}
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