Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Add CLI and Write support to Tekton Generators #564

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

YolandaDu1997
Copy link
Contributor

@YolandaDu1997 YolandaDu1997 commented Jun 22, 2020

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:

  1. To help users interact with generators, add the CLI command show to it.
  2. Add support for writing output to disk.

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.

@tekton-robot tekton-robot requested review from dibyom and wlynch June 22, 2020 19:07
@tekton-robot tekton-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 22, 2020
@YolandaDu1997 YolandaDu1997 reopened this Jun 22, 2020
@wlynch
Copy link
Member

wlynch commented Jun 22, 2020

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!

@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 22, 2020
generators/cmd/cli/cmd/root.go Outdated Show resolved Hide resolved
generators/cmd/cli/cmd/show.go Show resolved Hide resolved
generators/cmd/cli/cmd/show.go Outdated Show resolved Hide resolved
generators/pkg/writer/write.go Outdated Show resolved Hide resolved
generators/pkg/writer/write.go Show resolved Hide resolved
generators/pkg/writer/write.go Outdated Show resolved Hide resolved
generators/pkg/writer/write_test.go Outdated Show resolved Hide resolved
@YolandaDu1997
Copy link
Contributor Author

I have updated the parser and it now can parse the GithubSpec. Also, I have made changes to the cli command.

Copy link
Member

@wlynch wlynch left a 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/cmd/cli/cmd/write.go Outdated Show resolved Hide resolved
generators/cmd/cli/cmd/write.go Outdated Show resolved Hide resolved
generators/cmd/cli/cmd/write.go Outdated Show resolved Hide resolved
generators/pkg/writer/output/gen-task.yaml Outdated Show resolved Hide resolved
generators/pkg/writer/write.go Outdated Show resolved Hide resolved
func WriteToDisk(filename string, writer io.Writer) error {
file, err := os.Open(filename)
if err != nil {
return err
Copy link
Member

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.

Copy link
Contributor Author

@YolandaDu1997 YolandaDu1997 Jun 24, 2020

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 != "" {
Copy link
Member

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)

Copy link
Contributor Author

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

@YolandaDu1997
Copy link
Contributor Author

Done.

Copy link
Member

@wlynch wlynch left a 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/writer/write_test.go Outdated Show resolved Hide resolved
generators/pkg/writer/write_test.go Outdated Show resolved Hide resolved
generators/pkg/writer/write.go Show resolved Hide resolved
generators/pkg/parser/parser.go Outdated Show resolved Hide resolved
res := products{}
err := reader.Decode(&res)
func Parse(r io.Reader) (generator.GitHubSpec, error) {
res := generator.GitHubSpec{}
Copy link
Member

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.

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 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.

Copy link
Member

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)


got, err := ioutil.ReadFile(tempF.Name())
if err != nil {
t.Fatal(err)
Copy link
Member

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.

@dibyom
Copy link
Member

dibyom commented Jun 26, 2020

This is looking good to me! Just need to squash up the commits :)

Copy link
Member

@wlynch wlynch left a 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! :)

res := products{}
err := reader.Decode(&res)
func Parse(r io.Reader) (generator.GitHubSpec, error) {
res := generator.GitHubSpec{}
Copy link
Member

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)

}
res := generator.GitHubSpec{}
if err = yaml.Unmarshal(spec, &res); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if err = yaml.Unmarshal(spec, &res); err != nil {
if err := yaml.Unmarshal(spec, &res); err != nil {

Comment on lines 19 to 20
err := writer.WriteToDisk(filename, os.Stdout)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
err := writer.WriteToDisk(filename, os.Stdout)
if err != nil {
if err := writer.WriteToDisk(filename, os.Stdout); err != nil {

Copy link
Contributor Author

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:(

@tekton-robot tekton-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Jun 26, 2020
@wlynch
Copy link
Member

wlynch commented Jun 26, 2020

/approve cancel

@tekton-robot tekton-robot removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2020
@wlynch
Copy link
Member

wlynch commented Jun 26, 2020

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.

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Jun 26, 2020
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.
@YolandaDu1997
Copy link
Contributor Author

Done.

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 26, 2020
@tekton-robot
Copy link

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 26, 2020
@tekton-robot tekton-robot merged commit f63e91d into tektoncd:master Jun 26, 2020
@YolandaDu1997 YolandaDu1997 deleted the generators-cli branch June 26, 2020 20:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants