-
Notifications
You must be signed in to change notification settings - Fork 66
PROTOTYPE: Add support for templated campaign specs #334
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
Conversation
This is really cool! I love it |
5052c18
to
4271c04
Compare
d38c9ac
to
4022b92
Compare
I love how this is coming together! Thoughts on the drawbacks you mentioned:
|
Are there any drawbacks to how that's implemented? If it supports the full range of functionality the default Go template syntax does, I feel like we should just make that the standard and be done with it, since I agree it's more readable.
I think our limit here is going to be 131,072 bytes on Linux, regardless of configuration, because we'll hit So, yeah, that's not a lot when you're dealing with a big vendored The ideal solution to me feels like it would be to do something sort of For now, we could probably just detect this situation independent of template expansion when running the campaign steps, and warn the user. Edit: Yeah, OK, I read this before getting to #357 in my notifications. Take it for what it's worth. |
The most obvious drawback is that we need to "manually" add aliases for fields: https://gist.github.com/mrnugget/774812fe534fb019a80ad9be2c364a57#file-lower_case_var_hierarchy-go-L36-L45 Reasonably sure, though, that we could somehow automate this by — hear me out — converting to JSON and then back to |
Closing in favor of #361. |
NOTE FOR REVIEWERS: This is a prototype and should be treated as such, which means: let's review idea/design/feasibility instead of concrete implementation details (but if you do have concrete feedback on the implementation, feel free to leave it as such).
This is a prototype to add templating to the
steps
definitions in a campaign spec YAML file.It's similar to the templating allowed in GitHub Actions.
Here is an excerpt from a campaign spec that uses templating. It runs comby only over the search results found in the repository by the
repositoriesMatchingQuery
(that's the${{ .Repository.SearchResultPaths }}
in the spec) and then runsgoimports
only over the files modified by comby (the${{ .PreviousStep.ModifiedFiles }}
):Screenshot
Details
This is a tested prototype that works. Executing campaigns like this is much faster because comby only has to look at and touch the files it needs to modify, same goes for goimports.
What else is available in the templates? This is the definition of
StepContext
, which is passed into thestep.run
string before executing a step.That means a user can access:
${{ .Repository.SearchResultPaths }}
${{ .Repository.Name }}
and the other fields and methods on*graphql.Repository
${{ .PreviousStep.ModifiedFiles }}
${{ .PreviousStep.AddedFiles }}
${{ .PreviousStep.DeletedFiles }}
Drawbacks
${{ search_result_paths }}
for example). Why? Because I couldn't come up with a consistent naming scheme that allows us to have a hierarchy too (likeprevious_step.modified_files
etc.). That doesn't mean we shouldn't do it though, since I don't like the.Foobar
syntax of Go's templating system.*repositories*MatchingQuery
in their campaign spec. There might be a better way to define this.