Skip to content

Commit de882a4

Browse files
Bug 2015223: Rework Adding Release Branch
- Moves `app_id` to task. This gives us some flexibility without needing to update the scriptworker. Particularly, this may be scritctly neccesary while Thunderbird transitions the primary channel from ESR to Release. Otherwise, we will need to coordinate upates to our kind files with updates to scriptworker, which may be tricky. - Adds `branch` to task definition so the appropriate token can be selected without overloading `channel`
1 parent 8ec34a3 commit de882a4

File tree

10 files changed

+54
-56
lines changed

10 files changed

+54
-56
lines changed

pushflatpakscript/docker.d/init_worker.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ case $ENV in
2626
echo $REPO_TOKEN_BETA | base64 -d > $REPO_TOKEN_BETA_PATH
2727
echo $REPO_TOKEN_STABLE | base64 -d > $REPO_TOKEN_STABLE_PATH
2828

29-
30-
if [ "$COT_PRODUCT" = thunderbird ]; then
31-
# test_var_set 'REPO_TOKEN_RELEASE'
32-
# must either have REPO_TOKEN_RELEASE or REPO_TOKEN_ESR defined
33-
if [[ -z "$REPO_TOKEN_RELEASE" ]] && [[ -z "$REPO_TOKEN_ESR" ]]; then
34-
echo "error: must have token defined for release or esr channel"
35-
exit 1
36-
fi
37-
29+
if [ -n "$REPO_TOKEN_RELEASE" ]; then
3830
export REPO_TOKEN_RELEASE_PATH=$CONFIG_DIR/release_token.txt
3931
echo $REPO_TOKEN_RELEASE | base64 -d > $REPO_TOKEN_RELEASE_PATH
32+
fi
4033

34+
if [ -n "$REPO_TOKEN_ESR" ]; then
4135
export REPO_TOKEN_ESR_PATH=$CONFIG_DIR/esr_token.txt
4236
echo $REPO_TOKEN_ESR | base64 -d > $REPO_TOKEN_ESR_PATH
4337
fi
@@ -54,8 +48,6 @@ case $COT_PRODUCT in
5448
;;
5549
thunderbird)
5650
export APP_ID="org.mozilla.Thunderbird"
57-
export APP_ID_RELEASE="org.mozilla.ThunderbirdRelease"
58-
export APP_ID_ESR="org.mozilla.ThunderbirdESR"
5951
export TASKCLUSTER_SCOPE_PREFIX="project:comm:thunderbird:releng:flathub:"
6052
;;
6153
*)
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
work_dir: { "$eval": "WORK_DIR" }
22
artifact_dir: { "$eval": "ARTIFACTS_DIR" }
33
verbose: { "$eval": "VERBOSE == 'true'" }
4-
app_ids:
5-
beta: {"$eval": "APP_ID" }
6-
stable: {"$eval": "APP_ID"}
7-
release:
8-
$if: defined("APP_ID_RELEASE")
9-
then: {"$eval": "APP_ID_RELEASE"}
10-
else: ''
11-
esr:
12-
$if: defined("APP_ID_ESR")
13-
then: {"$eval": "APP_ID_ESR"}
14-
else: ''
4+
app_id: { "$eval": "APP_ID" }
155
taskcluster_scope_prefix: { "$eval": "TASKCLUSTER_SCOPE_PREFIX" }
166
push_to_flathub: { "$eval": "ENV == 'prod'" }
177
flathub_url: { "$eval": "FLATHUB_URL" }
@@ -24,11 +14,11 @@ token_locations:
2414
stable: { "$eval": "REPO_TOKEN_STABLE_PATH" }
2515
release:
2616
$if: defined("REPO_TOKEN_RELEASE_PATH")
27-
then: {"$eval": "REPO_TOKEN_RELEASE_PATH"}
17+
then: { "$eval": "REPO_TOKEN_RELEASE_PATH" }
2818
else: ''
2919
esr:
3020
$if: defined("REPO_TOKEN_ESR_PATH")
31-
then: {"$eval": "REPO_TOKEN_ESR_PATH"}
21+
then: { "$eval": "REPO_TOKEN_ESR_PATH" }
3222
else: ''
3323

3424
else: {}

pushflatpakscript/examples/config.example.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"work_dir": "/some/work/dir",
33
"verbose": true,
4-
"app_ids": {
5-
"stable": "org.mozilla.firefox",
6-
"beta": "org.mozilla.firefox"
7-
},
4+
"app_id": "org.mozilla.firefox",
85
"taskcluster_scope_prefix": "project:releng:flathub:firefox:",
96
"push_to_flathub": true,
107
"flathub_url": "flathub URL location",

pushflatpakscript/examples/push_flatpak_task_schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"channel": {
2424
"type": "string"
2525
},
26+
"app_id": {
27+
"type": "string"
28+
},
29+
"branch": {
30+
"type": "string"
31+
},
2632
"upstreamArtifacts": {
2733
"type": "array",
2834
"items": {

pushflatpakscript/src/pushflatpakscript/data/config_schema.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"title": "pushflatpakscript config schema",
33
"type": "object",
44
"required": [
5-
"app_ids",
5+
"app_id",
66
"taskcluster_scope_prefix",
77
"push_to_flathub",
88
"token_locations",
@@ -11,11 +11,8 @@
1111
"taskcluster_root_url"
1212
],
1313
"properties": {
14-
"app_ids": {
15-
"type": "object",
16-
"additionalProperties": {
17-
"type": "string"
18-
}
14+
"app_id": {
15+
"type": "string"
1916
},
2017
"taskcluster_scope_prefix": {
2118
"type": "string"

pushflatpakscript/src/pushflatpakscript/data/push_flatpak_task_schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
"channel": {
2424
"type": "string"
2525
},
26+
"app_id": {
27+
"type": "string"
28+
},
29+
"branch": {
30+
"type": "string"
31+
},
2632
"upstreamArtifacts": {
2733
"type": "array",
2834
"items": {

pushflatpakscript/src/pushflatpakscript/flathub.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,30 +142,29 @@ def files(tar, path):
142142
return os.path.join(flatpak_tar_basedir, flatpak_deflated_dir)
143143

144144

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

149149
# Consolidate ostree refs into list of Flatpak IDs available in repo
150150
flatpak_refs = [ref.split("/")[1] for ref in flatpak_refs if ref.startswith("app/")]
151151

152+
app_id = task.get_flatpak_app_id(context.config, context.task)
153+
152154
# Create a list, if any, of all unexpected Flatpak IDs present in repo
153-
invalid_refs = set(flatpak_refs) - set(context.config["app_ids"].values())
155+
invalid_refs = set(flatpak_refs) - app_id
154156

155-
if context.config["app_ids"][channel] not in flatpak_refs:
156-
raise TaskVerificationError(f"Supplied app ID ({context.config['app_ids'][channel]}) is not present in Flatpak!")
157+
if app_id not in flatpak_refs:
158+
raise TaskVerificationError(f"Supplied app ID ({app_id}) is not present in Flatpak!")
157159

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

161163

162-
def check_config_for_channel(config, channel):
163-
"""Verify AppID and token location defined for supplied channel"""
164-
if channel not in config["app_ids"]:
165-
raise TaskVerificationError(f"Supplied channel ({channel}) does not have a configured appID")
166-
167-
if channel not in config["token_locations"]:
168-
raise TaskVerificationError(f"Supplied channel ({channel}) does not have a configured token")
164+
def check_config_for_branch(config, branch):
165+
"""Verify Token location defined for supplied branch"""
166+
if branch not in config["token_locations"]:
167+
raise TaskVerificationError(f"Supplied branch ({branch}) does not have a configured token")
169168

170169

171170
def sanitize_buildid(bytes_input):
@@ -183,13 +182,14 @@ def push(context, flatpak_file_path, channel):
183182
# We don't raise an error because we still want green tasks on dev instances
184183
return
185184

186-
check_config_for_channel(context.config, channel)
185+
branch = task.get_release_branch(context.config, context.task)
186+
187+
check_config_for_branch(context.config, branch)
187188

188-
token_args = ["--token-file", context.config["token_locations"][channel]]
189+
token_args = ["--token-file", context.config["token_locations"][branch]]
189190
log.info("Grab a flatpak buildid from Flathub ...")
190-
publish_channel = "beta" if channel == "beta" else "stable"
191191
publish_build_output = run_flat_manager_client_process(
192-
context, token_args + ["create", context.config["flathub_url"], publish_channel, "--build-log-url", build_log]
192+
context, token_args + ["create", context.config["flathub_url"], channel, "--build-log-url", build_log]
193193
)
194194

195195
log.info("Sanitize the buildid received from Flathub ...")
@@ -203,7 +203,7 @@ def push(context, flatpak_file_path, channel):
203203
deflated_dir = check_and_extract_tar_archive(context, flatpak_file_path)
204204

205205
log.info("Verifying supplied app ID matches flatpak app ID...")
206-
check_app_id_matches_flatpak(context, deflated_dir, channel)
206+
check_app_id_matches_flatpak(context, deflated_dir)
207207

208208
log.info(f"Pushing the flatpak to the associated {publish_build_output}")
209209
run_flat_manager_client_process(context, token_args + ["push", publish_build_output, deflated_dir])

pushflatpakscript/src/pushflatpakscript/task.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from scriptworker.exceptions import TaskVerificationError
22

3-
_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB = ("beta", "stable", "release", "esr")
3+
_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB = ("beta", "stable")
44
ALLOWED_CHANNELS = ("mock", *_CHANNELS_AUTHORIZED_TO_REACH_FLATHUB)
55

66

@@ -20,5 +20,17 @@ def get_flatpak_channel(config, task):
2020
return channel
2121

2222

23+
def get_flatpak_app_id(config, task):
24+
payload = task["payload"]
25+
26+
return payload.get("app_id", config["app_id"])
27+
28+
29+
def get_release_branch(config, task):
30+
payload = task["payload"]
31+
32+
return payload.get("branch", config["channel"])
33+
34+
2335
def is_allowed_to_push_to_flathub(config, channel):
2436
return "push_to_flathub" in config and config["push_to_flathub"] and channel in _CHANNELS_AUTHORIZED_TO_REACH_FLATHUB

pushflatpakscript/tests/test_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
"ARTIFACTS_DIR": "",
1111
"VERBOSE": "true",
1212
"APP_ID": "",
13-
"APP_ID_RELEASE": "",
14-
"APP_ID_ESR": "",
1513
"COT_PRODUCT": "firefox",
1614
"TASKCLUSTER_SCOPE_PREFIX": "",
1715
"FLATHUB_URL": "https://flat.example",

pushflatpakscript/tests/test_task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_get_flatpak_channel_without_payload_raises():
1414
@pytest.mark.parametrize("raises, channel", ((False, "stable"), (False, "beta"), (False, "mock"), (False, "beta"), (False, "beta"), (True, "bogus")))
1515
def test_get_flatpak_channel_dep(raises, channel):
1616
task = {"scopes": [], "payload": {"channel": channel}}
17-
config = {"app_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"}, "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": False}
17+
config = {"app_id": "org.mozilla.firefox", "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": False}
1818
if raises:
1919
with pytest.raises(TaskVerificationError):
2020
get_flatpak_channel(config, task)
@@ -35,7 +35,7 @@ def test_get_flatpak_channel_dep(raises, channel):
3535
)
3636
def test_get_flatpak_channel_prod(raises, scopes, channel):
3737
task = {"scopes": scopes, "payload": {"channel": channel}}
38-
config = {"app_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"},
38+
config = {"app_id": "org.mozilla.firefox",
3939
"token_locations": {"stable": "stable.txt", "beta": "beta.txt"},
4040
"taskcluster_scope_prefix": "project:releng:flathub:firefox:",
4141
"push_to_flathub": True}
@@ -58,5 +58,5 @@ def test_get_flatpak_channel_prod(raises, scopes, channel):
5858
),
5959
)
6060
def test_is_allowed_to_push_to_flathub(channel, push_to_flathub, expected):
61-
config = {"app_ids": {"stable": "org.mozilla.firefox", "beta": "org.mozilla.firefox"}, "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": push_to_flathub}
61+
config = {"app_id": "org.mozilla.firefox", "taskcluster_scope_prefix": "project:releng:flathub:firefox:", "push_to_flathub": push_to_flathub}
6262
assert is_allowed_to_push_to_flathub(config, channel) == expected

0 commit comments

Comments
 (0)