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
13 changes: 11 additions & 2 deletions pushflatpakscript/docker.d/init_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ 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 [[$COT_PRODUCT == 'thunderbird']]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[$COT_PRODUCT == 'thunderbird']]; then
if [ $COT_PRODUCT = thunderbird ]; then

test_var_set 'REPO_TOKEN_ESR'
export REPO_TOKEN_ESR_PATH=$CONFIG_DIR/esr_token.txt
echo $REPO_TOKEN_ESR | base64 -d > $REPO_TOKEN_ESR_PATH
fi
;;
*)
exit 1
Expand All @@ -33,11 +39,14 @@ esac

case $COT_PRODUCT in
firefox)
export APP_ID="org.mozilla.firefox"
export APP_ID_BETA="org.mozilla.firefox"
export APP_ID_STABLE="org.mozilla.firefox"
export TASKCLUSTER_SCOPE_PREFIX="project:releng:flathub:firefox:"
;;
thunderbird)
export APP_ID="org.mozilla.Thunderbird"
export APP_ID_BETA="org.mozilla.Thunderbird"
export APP_ID_STABLE="org.mozilla.ThunderbirdRelease"
export APP_ID_ESR="org.mozilla.Thunderbird"
export TASKCLUSTER_SCOPE_PREFIX="project:comm:thunderbird:releng:flathub:"
;;
*)
Expand Down
12 changes: 11 additions & 1 deletion pushflatpakscript/docker.d/worker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
work_dir: { "$eval": "WORK_DIR" }
artifact_dir: { "$eval": "ARTIFACTS_DIR" }
verbose: { "$eval": "VERBOSE == 'true'" }
app_id: { "$eval": "APP_ID" }
app_ids:
beta: {"$eval": "APP_ID_BETA" }
stable: {"$eval": "APP_ID_STABLE"}
esr:
$if: 'COT_PRODUCT == "thunderbird"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: instead of hardcoding thunderbird, maybe use $if: defined("APP_ID_ESR"), and similar below

then: { "$eval": "APP_ID_ESR"}
else: ''
taskcluster_scope_prefix: { "$eval": "TASKCLUSTER_SCOPE_PREFIX" }
push_to_flathub: { "$eval": "ENV == 'prod'" }
flathub_url: { "$eval": "FLATHUB_URL" }
Expand All @@ -12,4 +18,8 @@ token_locations:
then:
beta: { "$eval": "REPO_TOKEN_BETA_PATH" }
stable: { "$eval": "REPO_TOKEN_STABLE_PATH" }
esr:
$if: 'COT_PRODUCT == "thunderbird"'
then: { "$eval": "REPO_TOKEN_ESR_PATH" }
else: ''
else: {}
5 changes: 4 additions & 1 deletion pushflatpakscript/examples/config.example.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"work_dir": "/some/work/dir",
"verbose": true,
"app_id": "org.mozilla.firefox",
"app_ids": {
"stable": "org.mozilla.firefox",
"beta": "org.mozilla.firefox"
},
"taskcluster_scope_prefix": "project:releng:flathub:firefox:",
"push_to_flathub": true,
"flathub_url": "flathub URL location",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"title": "pushflatpakscript config schema",
"type": "object",
"required": [
"app_id",
"app_ids",
"taskcluster_scope_prefix",
"push_to_flathub",
"token_locations",
Expand All @@ -11,8 +11,11 @@
"taskcluster_root_url"
],
"properties": {
"app_id": {
"type": "string"
"app_ids": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"taskcluster_scope_prefix": {
"type": "string"
Expand Down
10 changes: 5 additions & 5 deletions pushflatpakscript/src/pushflatpakscript/flathub.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,18 @@ def files(tar, path):
return os.path.join(flatpak_tar_basedir, flatpak_deflated_dir)


def check_app_id_matches_flatpak(context, flatpak_path):
def check_app_id_matches_flatpak(context, flatpak_path, channel):
# Extract all ostree refs from the supplied Flatpak repo
flatpak_refs = subprocess.check_output(["ostree", "refs"], cwd=flatpak_path).decode().splitlines()

# 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/")]

# 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) - {context.config["app_ids"]}

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 context.config["app_ids"][channel] not in flatpak_refs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check that channel in context.config["app_ids"], since the channel is supplied by the payload?

raise TaskVerificationError(f"Supplied app ID ({context.config['app_ids'][channel]}) is not present in Flatpak!")

if len(invalid_refs) > 0:
raise TaskVerificationError("One or more invalid app IDs are present in Flatpak!")
Expand Down Expand Up @@ -191,7 +191,7 @@ def push(context, flatpak_file_path, channel):
deflated_dir = check_and_extract_tar_archive(context, flatpak_file_path)

log.info("Verifying supplied app ID matches flatpak app ID...")
check_app_id_matches_flatpak(context, deflated_dir)
check_app_id_matches_flatpak(context, deflated_dir, channel)

log.info(f"Pushing the flatpak to the associated {publish_build_output}")
run_flat_manager_client_process(context, token_args + ["push", publish_build_output, deflated_dir])
Expand Down
2 changes: 1 addition & 1 deletion pushflatpakscript/src/pushflatpakscript/task.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from scriptworker.exceptions import TaskVerificationError

_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB = ("beta", "stable")
_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB = ("beta", "stable", "esr")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this effectively config["app_ids"].keys()?

ALLOWED_CHANNELS = ("mock", *_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB)


Expand Down
4 changes: 3 additions & 1 deletion pushflatpakscript/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"WORK_DIR": "",
"ARTIFACTS_DIR": "",
"VERBOSE": "true",
"APP_ID": "",
"APP_ID_STABLE": "",
"APP_ID_BETA": "",
"COT_PRODUCT": "firefox",
"TASKCLUSTER_SCOPE_PREFIX": "",
"FLATHUB_URL": "https://flat.example",
"FLAT_MANAGER_CLIENT": "/app/bin/flat-manager-client",
Expand Down
6 changes: 3 additions & 3 deletions pushflatpakscript/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_flatpak_channel_without_payload_raises():
@pytest.mark.parametrize("raises, channel", ((False, "stable"), (False, "beta"), (False, "mock"), (False, "beta"), (False, "beta"), (True, "bogus")))
def test_get_flatpak_channel_dep(raises, channel):
task = {"scopes": [], "payload": {"channel": channel}}
config = {"app_id": "org.mozilla.firefox", "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": False}
config = {"app_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"}, "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": False}
if raises:
with pytest.raises(TaskVerificationError):
get_flatpak_channel(config, task)
Expand All @@ -35,7 +35,7 @@ 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_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"}, "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": True}
if raises:
with pytest.raises(TaskVerificationError):
get_flatpak_channel(config, task)
Expand All @@ -55,5 +55,5 @@ def test_get_flatpak_channel_prod(raises, scopes, channel):
),
)
def test_is_allowed_to_push_to_flathub(channel, push_to_flathub, expected):
config = {"app_id": "org.mozilla.firefox", "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": push_to_flathub}
config = {"app_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"}, "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": push_to_flathub}
assert is_allowed_to_push_to_flathub(config, channel) == expected