Skip to content

feat: allow resolving keys in task context#968

Merged
bhearsum merged 1 commit into
taskcluster:mainfrom
bhearsum:feat-allow-resolving-keys-in-t
Jun 2, 2026
Merged

feat: allow resolving keys in task context#968
bhearsum merged 1 commit into
taskcluster:mainfrom
bhearsum:feat-allow-resolving-keys-in-t

Conversation

@bhearsum
Copy link
Copy Markdown
Contributor

@bhearsum bhearsum commented Jun 1, 2026

This extends task-context to allow for calling resolve_keyed_by is a generic way. Combined with task-context's existing support for pulling context from parameters it removes the need for transforms for many usages of resolve_keyed_by (I counted at least a dozen or so in Gecko alone, and there's probably many more.)

Mostly for simplicitly I chose to re-use substitution-fields as a source for what resolve_keyed_by should be called on. I could be convinced to maintain a separate list for that (although it might introduce repetition in certain cases). I'm honestly not sure which is preferable.

@bhearsum bhearsum marked this pull request as ready for review June 1, 2026 01:38
@bhearsum bhearsum requested a review from a team as a code owner June 1, 2026 01:38
@bhearsum bhearsum requested a review from hneiva June 1, 2026 01:38
Copy link
Copy Markdown
Collaborator

@ahal ahal left a comment

Choose a reason for hiding this comment

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

Thanks, lgtm modulo some nits

Comment thread docs/reference/transforms/task_context.rst
Comment thread docs/reference/transforms/task_context.rst Outdated
Comment thread src/taskgraph/transforms/task_context.py Outdated
@ahal
Copy link
Copy Markdown
Collaborator

ahal commented Jun 2, 2026

Oh and you'll want to rebase on main to get the new pre-commit-v1 task to unblock landing

This extends task-context to allow for calling `resolve_keyed_by` is a generic way. Combined with `task-context's` existing support for pulling context from parameters it removes the need for transforms for many usages of `resolve_keyed_by` (I counted at least a dozen or so in Gecko alone, and there's probably many more.)

Mostly for simplicitly I chose to re-use `substitution-fields` as a source for what `resolve_keyed_by` should be called on. I could be convinced to maintain a separate list for that (although it might introduce repetition in certain cases). I'm honestly not sure which is preferable.
@bhearsum bhearsum force-pushed the feat-allow-resolving-keys-in-t branch from 48a1735 to 6be4256 Compare June 2, 2026 20:26
@bhearsum bhearsum merged commit 2f0c609 into taskcluster:main Jun 2, 2026
23 checks passed
bhearsum added a commit to bhearsum/taskgraph that referenced this pull request Jun 3, 2026
This is somewhat of a continuation to taskcluster#968 in that it would allow for more `resolve_keyed_by` calls to be replaced by `task-context`. As a concrete example, we use [`by-release-level` in many places in gecko](https://searchfox.org/firefox-main/search?q=by-release-level&path=&case=false&regexp=false). Its value is [derived from parameters and some constants](https://searchfox.org/firefox-main/source/taskcluster/gecko_taskgraph/util/attributes.py#157). With this patch, we could register it as custom context and replace a whole bunch of `resolve_keyed_by` calls in transforms, eg:

In some python code that's called at taskgraph registration:
```
@custom_context("release-level")
def release_level_context(config, task):
    """Provide ``release-level`` ("production" or "staging"), derived from
    parameters, so ``by-release-level`` fields can be resolved declaratively."""
    return {"release-level": release_level(config.params)}
```

And in various kinds we'd end up with things like:
```
transforms:
    - taskgraph.transforms.task_context

task-defaults:
    task-context:
        from-custom:
            - release-level
        substitution-fields:
            - scopes

    scopes:
        by-release-level:
            production:
                - project:releng:ship-it:server:production
                - project:releng:ship-it:action:create-new-release
            staging:
                - project:releng:ship-it:server:staging
                - project:releng:ship-it:action:create-new-release
```
bhearsum added a commit to bhearsum/taskgraph that referenced this pull request Jun 3, 2026
This is somewhat of a continuation to taskcluster#968 in that it would allow for more `resolve_keyed_by` calls to be replaced by `task-context`. As a concrete example, we use [`by-release-level` in many places in gecko](https://searchfox.org/firefox-main/search?q=by-release-level&path=&case=false&regexp=false). Its value is [derived from parameters and some constants](https://searchfox.org/firefox-main/source/taskcluster/gecko_taskgraph/util/attributes.py#157). With this patch, we could register it as custom context and replace a whole bunch of `resolve_keyed_by` calls in transforms, eg:

In some python code that's called at taskgraph registration:
```
@custom_context("release-level")
def release_level_context(config, task):
    """Provide ``release-level`` ("production" or "staging"), derived from
    parameters, so ``by-release-level`` fields can be resolved declaratively."""
    return {"release-level": release_level(config.params)}
```

And in various kinds we'd end up with things like:
```
transforms:
    - taskgraph.transforms.task_context

task-defaults:
    task-context:
        from-custom:
            - release-level
        substitution-fields:
            - scopes

    scopes:
        by-release-level:
            production:
                - project:releng:ship-it:server:production
                - project:releng:ship-it:action:create-new-release
            staging:
                - project:releng:ship-it:server:staging
                - project:releng:ship-it:action:create-new-release
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants