Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/scriptworker/cot/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ async def populate_jsone_context(chain, parent_link, decision_link, tasks_for):
jsone_context.update(await _get_additional_github_releases_jsone_context(decision_link))
elif tasks_for == "cron":
jsone_context.update(await _get_additional_git_cron_jsone_context(decision_link))
elif tasks_for == "action":
elif tasks_for in ("action", "pr-action"):
jsone_context.update(await _get_additional_git_action_jsone_context(decision_link, parent_link))
elif tasks_for in ("github-pull-request", "github-pull-request-untrusted"):
jsone_context.update(await _get_additional_github_pull_request_jsone_context(decision_link))
Expand Down Expand Up @@ -1446,7 +1446,7 @@ def _get_action_from_actions_json(all_actions, callback_name):
raise CoTError("No action with {} callback found.".format(callback_name))


def _wrap_action_hook_with_let(tmpl, action_perm):
def _wrap_action_hook_with_let(tmpl, action_perm, tasks_for):
"""Construct the hook task template body.

Given the content of .taskcluster.yml, construct the task template that
Expand All @@ -1457,14 +1457,14 @@ def _wrap_action_hook_with_let(tmpl, action_perm):
"""
return {
"$let": {
"tasks_for": "action",
"tasks_for": tasks_for,
"action": {
"name": "${payload.decision.action.name}",
"title": "${payload.decision.action.title}",
"description": "${payload.decision.action.description}",
"taskGroupId": "${payload.decision.action.taskGroupId}",
"symbol": "${payload.decision.action.symbol}",
"repo_scope": "assume:repo:${payload.decision.repository.url[8:]}:action:" + action_perm,
"repo_scope": "assume:repo:${payload.decision.repository.url[8:]}:" + tasks_for + ":" + action_perm,
"action_perm": action_perm,
"cb_name": "${payload.decision.action.cb_name}",
},
Expand Down Expand Up @@ -1502,15 +1502,14 @@ def _get_action_perm(action_defn):
return action_perm


async def get_action_context_and_template(chain, parent_link, decision_link):
async def get_action_context_and_template(chain, parent_link, decision_link, tasks_for):
"""Get the appropriate json-e context and template for an action task.

Args:
chain (ChainOfTrust): the chain of trust.
parent_link (LinkOfTrust): the parent link to test.
decision_link (LinkOfTrust): the parent link's decision task link.
tasks_for (str): the reason the parent link was created (cron,
hg-push, action)
tasks_for (str): the reason the parent link was created (action or pr-action)

Returns:
(dict, dict): the json-e context and template.
Expand All @@ -1520,7 +1519,7 @@ async def get_action_context_and_template(chain, parent_link, decision_link):
all_actions = load_json_or_yaml(actions_path, is_path=True)["actions"]
action_name = get_action_callback_name(parent_link.task)
action_defn = _get_action_from_actions_json(all_actions, action_name)
jsone_context = await populate_jsone_context(chain, parent_link, decision_link, "action")
jsone_context = await populate_jsone_context(chain, parent_link, decision_link, tasks_for)

if action_defn.get("kind") != "hook":
raise CoTError(
Expand All @@ -1530,7 +1529,7 @@ async def get_action_context_and_template(chain, parent_link, decision_link):
# action-hook.
in_tree_tmpl = await get_in_tree_template(decision_link)
action_perm = _get_action_perm(action_defn)
tmpl = _wrap_action_hook_with_let(in_tree_tmpl, action_perm)
tmpl = _wrap_action_hook_with_let(in_tree_tmpl, action_perm, tasks_for)

# define the JSON-e context with which the hook's task template was
# rendered, defined at
Expand Down Expand Up @@ -1562,8 +1561,8 @@ async def get_jsone_context_and_template(chain, parent_link, decision_link, task
(dict, dict): the json-e context and template.

"""
if tasks_for == "action":
jsone_context, tmpl = await get_action_context_and_template(chain, parent_link, decision_link)
if tasks_for in ("action", "pr-action"):
jsone_context, tmpl = await get_action_context_and_template(chain, parent_link, decision_link, tasks_for)
else:
tmpl = await get_in_tree_template(decision_link)
jsone_context = await populate_jsone_context(chain, parent_link, decision_link, tasks_for)
Expand Down Expand Up @@ -1598,7 +1597,7 @@ async def verify_parent_task_definition(chain, parent_link):
tasks_for = get_and_check_tasks_for(chain.context, parent_link.task, "{} {}: ".format(parent_link.name, parent_link.task_id))
jsone_context, tmpl = await get_jsone_context_and_template(chain, parent_link, decision_link, tasks_for)
rebuilt_definitions = jsone.render(tmpl, jsone_context)
if tasks_for == "action":
if tasks_for in ("action", "pr-action"):
check_and_update_action_task_group_id(parent_link, decision_link, rebuilt_definitions)
except jsone.JSONTemplateError as e:
log.exception("JSON-e error while rebuilding {} task definition!".format(parent_link.name))
Expand Down
99 changes: 99 additions & 0 deletions tests/data/cotv4/pr_action_github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"provisionerId": "aws-provisioner-v1",
"workerType": "xpi-1-decision",
"schedulerId": "xpi-level-1",
"taskGroupId": "decision_task_id",
"dependencies": [],
"requires": "all-completed",
"routes": [
"checks",
"tc-treeherder.v2.xpi-manifest.1f444d8465ad7a564b230e49ccb37171271ac02b"
],
"priority": "lowest",
"retries": 5,
"created": "2019-10-21T23:36:07.490Z",
"deadline": "2019-10-22T23:36:07.490Z",
"expires": "2020-10-20T23:36:08.490Z",
"scopes": [
"assume:repo:github.com/escapewindow/xpi-manifest:pr-action:release-promotion"
],
"payload": {
"env": {
"XPI_BASE_REPOSITORY": "https://github.com/escapewindow/xpi-manifest",
"XPI_HEAD_REPOSITORY": "https://github.com/escapewindow/xpi-manifest",
"XPI_HEAD_REF": "refs/heads/master",
"XPI_HEAD_REV": "1f444d8465ad7a564b230e49ccb37171271ac02b",
"XPI_REPOSITORY_TYPE": "git",
"TASKGRAPH_BASE_REPOSITORY": "https://hg.mozilla.org/ci/taskgraph",
"TASKGRAPH_HEAD_REPOSITORY": "https://hg.mozilla.org/ci/taskgraph-try",
"TASKGRAPH_HEAD_REV": "d6f5998ed6ea2ffbb40d68451fa3b40c37fe1f62",
"TASKGRAPH_REPOSITORY_TYPE": "hg",
"REPOSITORIES": "{\"taskgraph\":\"Taskgraph\",\"xpi\":\"XPI Manifest\"}",
"HG_STORE_PATH": "/builds/worker/checkouts/hg-store",
"ACTION_TASK_GROUP_ID": "f3V--kXhQnOHjv7y7fTDFA",
"ACTION_TASK_ID": "null",
"ACTION_INPUT": "{\"build_number\":1,\"do_not_optimize\":[],\"previous_graph_ids\":[],\"rebuild_kinds\":[],\"release_promotion_flavor\":\"build\",\"version\":\"\",\"xpi_name\":\"multipreffer\"}",
"ACTION_CALLBACK": "release-promotion"
},
"features": {
"taskclusterProxy": true,
"chainOfTrust": true
},
"image": "mozillareleases/taskgraph:decision-bd477b55732fc5f5d55a78e6162355af8bc81805b415a9ea8dbe42c020f840db",
"maxRunTime": 1800,
"command": [
"/usr/local/bin/run-task",
"--xpi-checkout=/builds/worker/checkouts/src",
"--taskgraph-checkout=/builds/worker/checkouts/taskgraph",
"--task-cwd=/builds/worker/checkouts/src",
"--",
"bash",
"-cx",
"PIP_IGNORE_INSTALLED=0 pip install --user /builds/worker/checkouts/taskgraph && cd /builds/worker/checkouts/src && ln -s /builds/worker/artifacts artifacts && ~/.local/bin/taskgraph action-callback\n"
],
"artifacts": {
"public": {
"type": "directory",
"path": "/builds/worker/artifacts",
"expires": "2020-10-20T23:36:07.490Z"
}
}
},
"metadata": {
"owner": "pr-action@noreply.mozilla.org",
"source": "https://github.com/escapewindow/xpi-manifest/raw/1f444d8465ad7a564b230e49ccb37171271ac02b/.taskcluster.yml",
"name": "PR action: Promote a XPI",
"description": "Promote a XPI."
},
"tags": {
"kind": "action-callback"
},
"extra": {
"treeherder": {
"machine": {
"platform": "gecko-decision"
},
"groupName": "action-callback",
"groupSymbol": "AC",
"symbol": "build_multipreffer"
},
"parent": "f3V--kXhQnOHjv7y7fTDFA",
"action": {
"name": "release-promotion",
"context": {
"taskGroupId": "decision_task_id",
"taskId": null,
"input": {
"build_number": 1,
"do_not_optimize": [],
"previous_graph_ids": [],
"rebuild_kinds": [],
"release_promotion_flavor": "build",
"version": "",
"xpi_name": "multipreffer"
}
}
},
"tasks_for": "pr-action"
}
}
135 changes: 135 additions & 0 deletions tests/data/cotv4/pr_action_retrigger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{
"provisionerId": "aws-provisioner-v1",
"workerType": "gecko-1-decision",
"schedulerId": "gecko-level-1",
"taskGroupId": "LpCJV9wUQHSAm5SHyW4Olw",
"dependencies": [],
"requires": "all-completed",
"routes": [
"tc-treeherder.v2.try.c5429a8112e41dfabe22da0d7d0876fe05a17e67.323126",
"notify.email.taskcluster-notifications+action-task@mozilla.com.on-failed",
"notify.email.taskcluster-notifications+action-task@mozilla.com.on-exception",
"index.gecko.v2.try.pushlog-id.323126.actions.E93EolXNSRuV2gOy7yMZEA"
],
"priority": "very-low",
"retries": 5,
"created": "2018-12-19T19:26:57.706Z",
"deadline": "2018-12-20T19:26:57.706Z",
"expires": "2019-12-19T19:26:58.706Z",
"scopes": [
"assume:repo:hg.mozilla.org/try:pr-action:generic"
],
"payload": {
"env": {
"GECKO_BASE_REPOSITORY": "https://hg.mozilla.org/mozilla-unified",
"GECKO_HEAD_REPOSITORY": "https://hg.mozilla.org/try",
"GECKO_HEAD_REF": "c5429a8112e41dfabe22da0d7d0876fe05a17e67",
"GECKO_HEAD_REV": "c5429a8112e41dfabe22da0d7d0876fe05a17e67",
"HG_STORE_PATH": "/builds/worker/checkouts/hg-store",
"TASKCLUSTER_CACHES": "/builds/worker/checkouts",
"ACTION_TASK_GROUP_ID": "LpCJV9wUQHSAm5SHyW4Olw",
"ACTION_TASK_ID": "\"KkDeSaLFSq-OFo1QGc-hGQ\"",
"ACTION_INPUT": "{\"downstream\":false,\"times\":1}",
"ACTION_CALLBACK": "retrigger",
"ACTION_PARAMETERS": "{\"app_version\":\"65.0\",\"base_repository\":\"https://hg.mozilla.org/mozilla-unified\",\"build_date\":1545243227,\"build_number\":1,\"do_not_optimize\":[],\"existing_tasks\":{},\"filters\":[\"target_tasks_method\"],\"head_ref\":\"c5429a8112e41dfabe22da0d7d0876fe05a17e67\",\"head_repository\":\"https://hg.mozilla.org/try\",\"head_rev\":\"c5429a8112e41dfabe22da0d7d0876fe05a17e67\",\"hg_branch\":\"default\\n\",\"level\":\"1\",\"message\":\" \",\"moz_build_date\":\"20181219181347\",\"next_version\":null,\"optimize_target_tasks\":true,\"owner\":\"asasaki@mozilla.com\",\"project\":\"try\",\"pushdate\":1545243227,\"pushlog_id\":\"323126\",\"release_enable_emefree\":false,\"release_enable_partners\":false,\"release_eta\":\"\",\"release_history\":{},\"release_partner_build_number\":1,\"release_partner_config\":{},\"release_partners\":[],\"release_product\":null,\"release_type\":\"beta\",\"required_signoffs\":[],\"signoff_urls\":{},\"target_tasks_method\":\"staging_release_builds\",\"try_mode\":null,\"try_options\":null,\"try_task_config\":null,\"version\":\"65.0b9\"}"
},
"cache": {
"level-1-checkouts-sparse-v2": "/builds/worker/checkouts"
},
"features": {
"taskclusterProxy": true,
"chainOfTrust": true
},
"image": "taskcluster/decision:2.1.0@sha256:6db3b697d7a3c7aba440d72f04199331b872111cefff57206b8b8b1d53230360",
"maxRunTime": 1800,
"command": [
"/builds/worker/bin/run-task",
"--vcs-checkout=/builds/worker/checkouts/gecko",
"--sparse-profile=build/sparse-profiles/taskgraph",
"--",
"bash",
"-cx",
"cd /builds/worker/checkouts/gecko && ln -s /builds/worker/artifacts artifacts && ./mach --log-no-times taskgraph action-callback\n"
],
"artifacts": {
"public": {
"type": "directory",
"path": "/builds/worker/artifacts",
"expires": "2019-12-19T19:26:57.706Z"
}
}
},
"metadata": {
"owner": "pr-action@noreply.mozilla.org",
"source": "https://hg.mozilla.org/try/raw-file/c5429a8112e41dfabe22da0d7d0876fe05a17e67/.taskcluster.yml",
"name": "PR action: Retrigger",
"description": "Create a clone of the task.\nPR action triggered by clientID `mozilla-auth0/ad|Mozilla-LDAP|test`"
},
"tags": {
"createdForUser": "pr-action@noreply.mozilla.org",
"kind": "action-callback"
},
"extra": {
"treeherder": {
"machine": {
"platform": "gecko-decision"
},
"groupName": "action-callback",
"groupSymbol": "AC",
"symbol": "rt"
},
"parent": "LpCJV9wUQHSAm5SHyW4Olw",
"action": {
"name": "retrigger",
"context": {
"taskGroupId": "LpCJV9wUQHSAm5SHyW4Olw",
"taskId": "KkDeSaLFSq-OFo1QGc-hGQ",
"input": {
"downstream": false,
"times": 1
},
"parameters": {
"app_version": "65.0",
"base_repository": "https://hg.mozilla.org/mozilla-unified",
"build_date": 1545243227,
"build_number": 1,
"do_not_optimize": [],
"existing_tasks": {},
"filters": [
"target_tasks_method"
],
"head_ref": "c5429a8112e41dfabe22da0d7d0876fe05a17e67",
"head_repository": "https://hg.mozilla.org/try",
"head_rev": "c5429a8112e41dfabe22da0d7d0876fe05a17e67",
"hg_branch": "default\n",
"level": "1",
"message": " ",
"moz_build_date": "20181219181347",
"next_version": null,
"optimize_target_tasks": true,
"owner": "asasaki@mozilla.com",
"project": "try",
"pushdate": 1545243227,
"pushlog_id": "323126",
"release_enable_emefree": false,
"release_enable_partners": false,
"release_eta": "",
"release_history": {},
"release_partner_build_number": 1,
"release_partner_config": {},
"release_partners": [],
"release_product": null,
"release_type": "beta",
"required_signoffs": [],
"signoff_urls": {},
"target_tasks_method": "staging_release_builds",
"try_mode": null,
"try_options": null,
"try_task_config": null,
"version": "65.0b9"
}
}
},
"tasks_for": "pr-action"
}
}
Loading