-
Notifications
You must be signed in to change notification settings - Fork 39
Adjust CoT verification for new action and cron roles #823
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
Draft
ahal
wants to merge
2
commits into
mozilla-releng:main
Choose a base branch
from
ahal:ahal/pyooluolywvt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import logging | ||
| import os | ||
| import pprint | ||
| import re | ||
| import sys | ||
| import tempfile | ||
| from copy import deepcopy | ||
|
|
@@ -1022,7 +1023,7 @@ async def get_pushlog_info(decision_link): | |
|
|
||
|
|
||
| # get_scm_level {{{1 | ||
| async def get_scm_level(context, project): | ||
| async def get_scm_level(context, project, branch=None): | ||
| """Get the scm level for a project from ``projects.yml``. | ||
|
|
||
| We define all known projects in ``projects.yml``. Let's make sure we have | ||
|
|
@@ -1034,6 +1035,7 @@ async def get_scm_level(context, project): | |
| Args: | ||
| context (scriptworker.context.Context): the scriptworker context | ||
| project (str): the project to get the scm level for. | ||
| branch (str, optional): the branch to get the level for (Git only) | ||
|
|
||
| Returns: | ||
| str: the level of the project, as a string. | ||
|
|
@@ -1044,12 +1046,11 @@ async def get_scm_level(context, project): | |
| if config["repo_type"] == "hg": | ||
| return config["access"].replace("scm_level_", "") | ||
| elif config["repo_type"] == "git": | ||
| # TODO: we should be using the branch that the task is actually | ||
| # being run on | ||
| default_branch = config.get("default_branch", "main") | ||
| for branch in config["branches"]: | ||
| if branch["name"] == default_branch: | ||
| return str(branch["level"]) | ||
| if branch is None: | ||
| branch = config.get("default_branch", "main") | ||
| for b in config["branches"]: | ||
| if fnmatch.fnmatch(branch, b["name"]): | ||
| return str(b["level"]) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I got a bit confused at first glance here. |
||
|
|
||
| raise ValueError("Can't find level for project {}".format(project)) | ||
|
|
||
|
|
@@ -1181,7 +1182,7 @@ async def _get_additional_git_cron_jsone_context(decision_link): | |
| "sender": {"login": user}, | ||
| }, | ||
| # Taskgraph cron contexts mirror hg-push contexts | ||
| "repository": {"url": repo, "project": repo_name, "level": await get_scm_level(decision_link.context, repo_name), "type": "git"}, | ||
| "repository": {"url": repo, "project": repo_name, "level": await get_scm_level(decision_link.context, repo_name, branch), "type": "git"}, | ||
| "push": {"revision": revision, "branch": branch}, | ||
| } | ||
|
|
||
|
|
@@ -1457,14 +1458,16 @@ 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, tasks_for): | ||
| def _wrap_action_hook_with_let(tmpl, action_perm, tasks_for, level): | ||
| """Construct the hook task template body. | ||
|
|
||
| Given the content of .taskcluster.yml, construct the task template that | ||
| would appear in the corresponding hook definition. This is an attempt to | ||
| duplicate the logic here: | ||
| https://hg.mozilla.org/ci/ci-admin/file/edad9f8/ciadmin/generate/in_tree_actions.py#l154 | ||
| https://github.com/mozilla-releng/fxci-config/blob/main/src/ciadmin/generate/in_tree_actions.py | ||
|
|
||
| `level` must be derived from the hook that produced this action task, not | ||
| the triggering push | ||
| """ | ||
| return { | ||
| "$let": { | ||
|
|
@@ -1475,7 +1478,7 @@ def _wrap_action_hook_with_let(tmpl, action_perm, tasks_for): | |
| "description": "${payload.decision.action.description}", | ||
| "taskGroupId": "${payload.decision.action.taskGroupId}", | ||
| "symbol": "${payload.decision.action.symbol}", | ||
| "repo_scope": "assume:repo:${payload.decision.repository.url[8:]}:" + tasks_for + ":" + action_perm, | ||
| "repo_scope": "assume:repo:${payload.decision.repository.url[8:]}:" + tasks_for + "-" + str(level) + ":" + action_perm, | ||
| "action_perm": action_perm, | ||
| "cb_name": "${payload.decision.action.cb_name}", | ||
| }, | ||
|
|
@@ -1513,6 +1516,14 @@ def _get_action_perm(action_defn): | |
| return action_perm | ||
|
|
||
|
|
||
| def _get_action_level(action_defn): | ||
| hook_id = action_defn.get("hookId", "") | ||
| match = re.match(r"in-tree-(?:pr-)?action-(\d+)-", hook_id) | ||
| if not match: | ||
| raise CoTError("Can't find level in action hookId `{}`.".format(hook_id)) | ||
| return int(match.group(1)) | ||
|
|
||
|
|
||
| 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. | ||
|
|
||
|
|
@@ -1540,7 +1551,8 @@ async def get_action_context_and_template(chain, parent_link, decision_link, tas | |
| # 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, tasks_for) | ||
| action_level = _get_action_level(action_defn) | ||
| tmpl = _wrap_action_hook_with_let(in_tree_tmpl, action_perm, tasks_for, action_level) | ||
|
|
||
| # define the JSON-e context with which the hook's task template was | ||
| # rendered, defined at | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we should crash if a
default_branchis not set on the repo.No need to fix this here, we can fix this in the future.