-
Notifications
You must be signed in to change notification settings - Fork 48
[run-task] Support interpolating $TASK_WORKDIR in environment variables
#630
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1091,10 +1091,10 @@ def _display_python_version(): | |
|
|
||
|
|
||
| def main(args): | ||
| os.environ["TASK_WORKDIR"] = os.getcwd() | ||
| task_workdir = os.environ["TASK_WORKDIR"] = os.getcwd() | ||
| print_line( | ||
| b"setup", | ||
| b"run-task started in %s\n" % os.environ["TASK_WORKDIR"].encode("utf-8"), | ||
| b"run-task started in %s\n" % task_workdir.encode("utf-8"), | ||
| ) | ||
| print_line( | ||
| b"setup", | ||
|
|
@@ -1313,20 +1313,27 @@ def main(args): | |
| for repo in repositories: | ||
| vcs_checkout_from_args(repo) | ||
|
|
||
| resource_process = None | ||
|
|
||
| try: | ||
| for k in ["MOZ_FETCHES_DIR", "UPLOAD_DIR"] + [ | ||
| "{}_PATH".format(repository["project"].upper()) | ||
| for repository in repositories | ||
| ]: | ||
| if k in os.environ: | ||
| os.environ[k] = os.path.abspath(os.environ[k]) | ||
| # Interpolate environment variables with defined substitution patterns. For | ||
| # example, the variable `CACHE_DIR={task_workdir}/.cache` will be | ||
| # interpolated with the task's working directory. | ||
| env_subs = { | ||
| "task_workdir": task_workdir, | ||
|
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. I assume there's a reason that we can't use the upper-cased
Collaborator
Author
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. (see my explanation in the main thread, I think it'll make more sense then)
Collaborator
Author
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. I guess I'll expand a little bit.. My initial patch did use I think this would be a good idea, but I also worry that this could break tasks in subtle ways if it accidentally starts substituting things we didn't intend it to. There's also questions about the order environment variables are substituted and what happens if you have variables that depend on each other in a cycle or with a higher depth. Ultimately I decided that what we are doing here isn't really environment variable substitution, so it would be cleaner not to disguise it as such. I don't know if it's the right call, but I think this is the safest option. Maybe we can change it again later.
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. Sorry, I missed this earlier. Thanks for the explanation - sorry I didn't notice it in the other thread! |
||
| } | ||
| for k, v in os.environ.items(): | ||
| for subname, subval in env_subs.items(): | ||
| # We check for an exact match rather than using a format string to | ||
| # avoid accidentally trying to interpolate environment variables | ||
| # that happen to contain brackets for some other reason. | ||
| pattern = f"{{{subname}}}" | ||
| if pattern in v: | ||
| os.environ[k] = v.replace(pattern, subval) | ||
| print_line( | ||
| b"setup", | ||
| b"%s is %s\n" % (k.encode("utf-8"), os.environ[k].encode("utf-8")), | ||
| ) | ||
|
|
||
| resource_process = None | ||
| try: | ||
| if "MOZ_FETCHES" in os.environ: | ||
| fetch_artifacts() | ||
|
|
||
|
|
||
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.
It would be great to get some minimal mentions of this in the docs.
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 agree, but
run-taskand theruntransforms are entirely undocumented atm. Documenting this should be pretty high priority, but I don't want to scope bloat just to have a place to add this.