Skip to content
Open
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
10 changes: 10 additions & 0 deletions pushflatpakscript/docker.d/init_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ case $ENV in
export REPO_TOKEN_STABLE_PATH=$CONFIG_DIR/stable_token.txt
echo $REPO_TOKEN_BETA | base64 -d > $REPO_TOKEN_BETA_PATH
echo $REPO_TOKEN_STABLE | base64 -d > $REPO_TOKEN_STABLE_PATH

if [ -n "$REPO_TOKEN_RELEASE" ]; then
export REPO_TOKEN_RELEASE_PATH=$CONFIG_DIR/release_token.txt
echo $REPO_TOKEN_RELEASE | base64 -d > $REPO_TOKEN_RELEASE_PATH
fi

if [ -n "$REPO_TOKEN_ESR" ]; then
export REPO_TOKEN_ESR_PATH=$CONFIG_DIR/esr_token.txt
echo $REPO_TOKEN_ESR | base64 -d > $REPO_TOKEN_ESR_PATH
fi
;;
*)
exit 1
Expand Down
11 changes: 10 additions & 1 deletion pushflatpakscript/docker.d/worker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
work_dir: { "$eval": "WORK_DIR" }
artifact_dir: { "$eval": "ARTIFACTS_DIR" }
verbose: { "$eval": "VERBOSE == 'true'" }
app_id: { "$eval": "APP_ID" }
app_id: {"$eval": "APP_ID" }
taskcluster_scope_prefix: { "$eval": "TASKCLUSTER_SCOPE_PREFIX" }
push_to_flathub: { "$eval": "ENV == 'prod'" }
flathub_url: { "$eval": "FLATHUB_URL" }
Expand All @@ -12,4 +12,13 @@ token_locations:
then:
beta: { "$eval": "REPO_TOKEN_BETA_PATH" }
stable: { "$eval": "REPO_TOKEN_STABLE_PATH" }
release:
$if: defined("REPO_TOKEN_RELEASE_PATH")
then: {"$eval": "REPO_TOKEN_RELEASE_PATH"}
else: ''
esr:
$if: defined("REPO_TOKEN_ESR_PATH")
then: {"$eval": "REPO_TOKEN_ESR_PATH"}
else: ''

else: {}
6 changes: 6 additions & 0 deletions pushflatpakscript/examples/push_flatpak_task_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"channel": {
"type": "string"
},
"app_id": {
"type": "string"
},
"branch": {
"type": "string"
},
"upstreamArtifacts": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"channel": {
"type": "string"
},
"app_id": {
"type": "string"
},
"branch": {
"type": "string"
},
"upstreamArtifacts": {
"type": "array",
"items": {
Expand Down
20 changes: 16 additions & 4 deletions pushflatpakscript/src/pushflatpakscript/flathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,24 @@ def check_app_id_matches_flatpak(context, flatpak_path):
# Consolidate ostree refs into list of Flatpak IDs available in repo
flatpak_refs = [ref.split("/")[1] for ref in flatpak_refs if ref.startswith("app/")]

app_id = task.get_flatpak_app_id(context.config, context.task)

# Create a list, if any, of all unexpected Flatpak IDs present in repo
invalid_refs = set(flatpak_refs) - {context.config["app_id"]}
invalid_refs = set(flatpak_refs) - app_id

if context.config["app_id"] not in flatpak_refs:
raise TaskVerificationError(f"Supplied app ID ({context.config['app_id']}) is not present in Flatpak!")
if app_id not in flatpak_refs:
raise TaskVerificationError(f"Supplied app ID ({app_id}) is not present in Flatpak!")

if len(invalid_refs) > 0:
raise TaskVerificationError("One or more invalid app IDs are present in Flatpak!")


def check_config_for_branch(config, branch):
"""Verify Token location defined for supplied branch"""
if branch not in config["token_locations"]:
raise TaskVerificationError(f"Supplied branch ({branch}) does not have a configured token")


def sanitize_buildid(bytes_input):
"""Flathub API returns bytes to we're decoding that to unicode string"""
return bytes_input.decode().strip()
Expand All @@ -174,7 +182,11 @@ def push(context, flatpak_file_path, channel):
# 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]]
branch = task.get_release_branch(context.config, context.task)

check_config_for_branch(context.config, branch)

token_args = ["--token-file", context.config["token_locations"][branch]]
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, "--build-log-url", build_log]
Expand Down
12 changes: 12 additions & 0 deletions pushflatpakscript/src/pushflatpakscript/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,17 @@ def get_flatpak_channel(config, task):
return channel


def get_flatpak_app_id(config, task):
payload = task["payload"]

return payload.get("app_id", config["app_id"])


def get_release_branch(config, task):
payload = task["payload"]

return payload.get("branch", config["channel"])


def is_allowed_to_push_to_flathub(config, channel):
return "push_to_flathub" in config and config["push_to_flathub"] and channel in _CHANNELS_AUTHORIZED_TO_REACH_FLATHUB
1 change: 1 addition & 0 deletions pushflatpakscript/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"ARTIFACTS_DIR": "",
"VERBOSE": "true",
"APP_ID": "",
"COT_PRODUCT": "firefox",
"TASKCLUSTER_SCOPE_PREFIX": "",
"FLATHUB_URL": "https://flat.example",
"FLAT_MANAGER_CLIENT": "/app/bin/flat-manager-client",
Expand Down
5 changes: 4 additions & 1 deletion pushflatpakscript/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def test_get_flatpak_channel_dep(raises, channel):
)
def test_get_flatpak_channel_prod(raises, scopes, channel):
task = {"scopes": scopes, "payload": {"channel": channel}}
config = {"app_id": "org.mozilla.firefox", "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": True}
config = {"app_id": "org.mozilla.firefox",
"token_locations": {"stable": "stable.txt", "beta": "beta.txt"},
"taskcluster_scope_prefix": "project:releng:flathub:firefox:",
"push_to_flathub": True}
if raises:
with pytest.raises(TaskVerificationError):
get_flatpak_channel(config, task)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
"FLATHUB_URL": "https://flathub.example.com",
"REPO_TOKEN_BETA": "Zm9vYmFyCg==",
"REPO_TOKEN_STABLE": "Zm9vYmFyCg==",
"REPO_TOKEN_RELEASE": "Zm9vYmFyCg==",
"REPO_TOKEN_ESR": "Zm9vYmFyCg==",
},
re.compile(r"pushmsix:.*"): {
"TENANT_ID": "Zm9vYmFyCg==",
Expand Down