-
Notifications
You must be signed in to change notification settings - Fork 121
Add CLI and Write support to Tekton Generators #564
Conversation
Looks like this is pulling in changes from #558 can you rebase so that those diffs aren't included? Also, I think for future PRs we can stop linking to the community issue. That was primarily to create the OWNERS file. Thanks! |
I have updated the |
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.
Looking good! Just minor tweaks / cleanup.
generators/pkg/writer/write.go
Outdated
func WriteToDisk(filename string, writer io.Writer) error { | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
return err |
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.
Not sure what these errors look like in practice. Would it be clear to users what is failing, and what they would need to do to resolve?
If not, perhaps we should wrap these errors with some additional description of what was attempted.
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 added fmt.Errorf()
to provide the description of errors.
t.Fatalf("error from 'GenerateTask': %v", err) | ||
} | ||
|
||
got := GenerateTask(spec) | ||
if diff := cmp.Diff(got, want); diff != "" { |
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 should be cmp.Diff(want,got)
for the printed diff to be of the form (-want/+got)
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.
sorry I' ll fix this
Done. |
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.
Almost there! Just a few cleanups / minor changes. Core logic/structure LGTM though!
generators/pkg/parser/parser.go
Outdated
res := products{} | ||
err := reader.Decode(&res) | ||
func Parse(r io.Reader) (generator.GitHubSpec, error) { | ||
res := generator.GitHubSpec{} |
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's generally good practice to declare vars as close to where they are used. In this case, we're declaring res, but then doing nothing with in in the next statement. This would make more sense to be moved down to where the unmarshal occurs.
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 got it. But here because if ioutil.ReadAll(r)
has an error, an empty struct and the error will be returned. I could change the return value to be generator.GitHubSpec{}
instead of the var.
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.
Ah, I see! SGTM then :) (either way is fine)
generators/pkg/writer/write_test.go
Outdated
|
||
got, err := ioutil.ReadFile(tempF.Name()) | ||
if err != nil { | ||
t.Fatal(err) |
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.
Also annotate this and the other testing errors about what failed, so it's easier to see what failed from the go test logs.
This is looking good to me! Just need to squash up the commits :) |
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.
/lgtm
2 really minor things, then squash the commits and we'll approve! :)
generators/pkg/parser/parser.go
Outdated
res := products{} | ||
err := reader.Decode(&res) | ||
func Parse(r io.Reader) (generator.GitHubSpec, error) { | ||
res := generator.GitHubSpec{} |
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.
Ah, I see! SGTM then :) (either way is fine)
generators/pkg/parser/parser.go
Outdated
} | ||
res := generator.GitHubSpec{} | ||
if err = yaml.Unmarshal(spec, &res); err != nil { |
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.
if err = yaml.Unmarshal(spec, &res); err != nil { | |
if err := yaml.Unmarshal(spec, &res); err != nil { |
generators/cmd/cli/cmd/show.go
Outdated
err := writer.WriteToDisk(filename, os.Stdout) | ||
if err != nil { |
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.
err := writer.WriteToDisk(filename, os.Stdout) | |
if err != nil { | |
if err := writer.WriteToDisk(filename, os.Stdout); err != nil { |
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.
Didn't notice this, sorry:(
/approve cancel |
Did not realize that the GitHub PR approve button would trigger the Prow approve 😅 It makes sense, but I don't remember it doing this before. Sorry about the noise. |
This commit is to add CLI support to generators. The CLI includes the "show" command to print the generated task configuration and the 'write' to write the generated config to file. This CLI tool is to help users interact with generators.
ca6d7ae
to
47b8520
Compare
Done. |
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dibyom The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Changes
I am working on Tekton Generators.
This project aims at generating Tekton spec from simplified configs, which will help users bootstrap pipelines in a configurable way.
I want to make some changes to this project:
show
to it.Submitter Checklist
These are the criteria that every PR should meet, please check them off as you
review them:
See the contribution guide
for more details.