Skip to content
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

Add --env to comment trigger phrase #2583

Merged

Conversation

Frawless
Copy link
Contributor

Checklist:

  • Write new tests or update the old ones to cover new functionality.
  • Update doc-strings where appropriate.
  • Update or write new documentation in packit/packit.dev.

This PR adds possibility to specify --env parameters in manual trigger command.

User can specify multiple env variables in format like --env MY_ENV_VAR=value --env MY_ENV_VAR2=value2. Every env var has to have it's own --env keyword.

Env variables specified with this option has the highest priority when building TF payload.

Fixes #2200

RELEASE NOTES BEGIN

Packit now supports --env parameters in manual trigger command.

RELEASE NOTES END

Copy link
Contributor

Copy link
Member

@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

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

really nice work, thanks for looking into it so quickly!!

Just few comments, and could you please fix the commits history (there is one in the PR that's already in main)?

packit_service/worker/helpers/testing_farm.py Outdated Show resolved Hide resolved
Comment on lines 562 to 566
env_variables = {
k: v
for k, v in self.comment_arguments.envs.items()
if v is not None
}
Copy link
Member

Choose a reason for hiding this comment

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

what about a use-case of "unsetting" env var via comment arg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't think about this one. You mean something like --env MY_ENV_VAR="" will unset it or do you have something else how should look like? It shouldn't be a problem to implement it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or you mean if value is None then unset it?

Copy link
Member

Choose a reason for hiding this comment

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

yes, practically both, like if someone passes --env ENV_VAR_TO_UNSET= --env OTHER_ENV_VAR=value, which would lead to the value being None

Comment on lines 91 to 96
# Set up argparse
parser = argparse.ArgumentParser()
parser.add_argument("packit_command")
parser.add_argument("--identifier", "--id", "-i")
parser.add_argument("--labels")
parser.add_argument("--env", action="append") # Allows multiple --env arguments
Copy link
Member

Choose a reason for hiding this comment

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

maybe we could create property out of this, or at least separate the creation of the parser

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not python expert so maybe my changes are not python compliant, but I think it is better now

Comment on lines 118 to 121
if args.env:
# Parse envs into dictionary
self.envs = dict(env.split("=") for env in args.env)
logger.debug(f"Parsed envs: {self.envs}")
Copy link
Member

Choose a reason for hiding this comment

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

I think here we should add some error handling for bad input (not key=value format)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did some changes, please take a look :)

identifier: str = None
labels: List[str] = None
pr_argument: str = None

def __init__(self, command_prefix: str, comment: str):
Copy link
Member

Choose a reason for hiding this comment

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

the __init__ method grew quite a lot with the new code, do you think it could be split up a bit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will try to split it

Copy link
Contributor

Copy link
Contributor

Copy link
Contributor

Copy link
Member

@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

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

thanks for the improvements! As for me, I would just agree on what to do with the unsetting the env var, and then after squashing the commits this could be merged! 🚀

packit_service/worker/helpers/testing_farm.py Outdated Show resolved Hide resolved
Comment on lines 562 to 566
env_variables = {
k: v
for k, v in self.comment_arguments.envs.items()
if v is not None
}
Copy link
Member

Choose a reason for hiding this comment

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

yes, practically both, like if someone passes --env ENV_VAR_TO_UNSET= --env OTHER_ENV_VAR=value, which would lead to the value being None

Copy link
Contributor

@Frawless Frawless marked this pull request as ready for review October 15, 2024 12:05
@Frawless Frawless requested review from mfocko and a team as code owners October 15, 2024 12:05
@Frawless
Copy link
Contributor Author

@lbarcziova I updated the code, please take a look if the unset functionality is fine.

Copy link
Contributor

Copy link
Member

@lbarcziova lbarcziova left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot!

let's test in staging and adjust in followup PRs if needed

@lbarcziova lbarcziova added the mergeit When set, zuul wil gate and merge the PR. label Oct 15, 2024
Copy link
Contributor

Build succeeded (gate pipeline).
https://softwarefactory-project.io/zuul/t/packit-service/buildset/b4b1089f3c9a4501911df6b4d2a03845

✔️ pre-commit SUCCESS in 2m 29s

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 5622b78 into packit:main Oct 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit When set, zuul wil gate and merge the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing Farm on-demand customized execution
3 participants