Skip to content

Add porter mixin create command#1602

Merged
carolynvs merged 12 commits intogetporter:release/v1from
joshuabezaleel:porter-mixin-create-command
Sep 28, 2021
Merged

Add porter mixin create command#1602
carolynvs merged 12 commits intogetporter:release/v1from
joshuabezaleel:porter-mixin-create-command

Conversation

@joshuabezaleel
Copy link
Contributor

@joshuabezaleel joshuabezaleel commented May 23, 2021

What does this change

Introduce porter mixin create command which clone the getporter/skeletor repo and modify the skeletor's file's content according to the argument and flags supplied by the user when running the command according to the skeletor's README instruction.

The structure of the command is as follows as @carolynvs mentioned here.
porter mixin create NAME --author YOURNAME [--dir /path/to/mixin/dir]

What issue does it fix

Closes #1512

Notes for the reviewer

I attached a short video demo of running the command below.

porter.mixin.create.mp4

Checklist

  • Unit Tests
  • Documentation
  • Schema (porter.yaml)

@joshuabezaleel
Copy link
Contributor Author

Hi @carolynvs , I'm truly sorry for a really late PR. Looking forward to the review! 🙂

@joshuabezaleel joshuabezaleel force-pushed the porter-mixin-create-command branch 2 times, most recently from 621ad3a to 530463b Compare May 25, 2021 11:34
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Wonderful! 🙏🏼 Thank you for putting this together. There are just two things that I'd like to include in this pull request as well:

  • Mention the command and how to use it on our website so that people know about it. https://porter.sh/mixin-dev-guide/ right now points people to the skeletor repo. Can you add a quick sentence or two and a example command showing someone how to use porter mixins create?
  • This doesn't have any tests and it would be easy for us to miss if anything broke. Can you write a test that does the following?
    1. Run the create command in a temp directory. You can mimic a test like this one to do it
    2. Run make build using exec.Command in that directory and check that it doesn't return an error.

}

replacementList := map[string]string{
"get.porter.sh/mixin/skeletor": fmt.Sprintf("github.com/%s/%s", opts.AuthorName, opts.MixinName),
Copy link
Member

Choose a reason for hiding this comment

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

We will need one more flag to collect the user's github username. --author has their full name, e.g. "Carolyn Van Slyck", which won't work as a replacement for the package name. How about --username?

A flag of --author to declare the author of the mixin is also a required input.
You can also specify where to put mixin directory. It will default to the current directory.`,
Example: ` porter mixin create MyMixin --author MyName
porter mixin create MyMixin --author MyName --dir path/to/mymixin
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
porter mixin create MyMixin --author MyName --dir path/to/mymixin
porter mixin create MyMixin --author "My Name" --username myuser --dir path/to/mymixin

Let's show them how to use a full name with spaces, and then include a new flag for the username (more on that below).

@carolynvs
Copy link
Member

@joshuabezaleel Just checking in to see if you had any questions about the review feedback, or were having trouble implementing the suggestions. I'm happy to help get this PR finished up!

@joshuabezaleel joshuabezaleel force-pushed the porter-mixin-create-command branch from 1fa711b to 8e8f394 Compare August 20, 2021 15:45
@joshuabezaleel
Copy link
Contributor Author

Hi @carolynvs , I am really sorry for taking a really long time to make an update on this PR. Life got hard for a while, some personal issues and the COVID situation here in Indonesia turns to be really overwhelming and gets the best of me, making me not to have any more energy outside work especially on open source.

It's getting better and I think I am ready to get back to contributing to Porter. Thank you lots for the great review, I totally skipped about it while implementing and your points on flag --username and adding unit test is spot on. I've added the flag, test, and also description that you might want to look for its wording on the docs since English isn't my first and day-to-day language.

Looking forward to further review, and many more Porter issues to tackle 💪 Hope you all Porter folks are also doing well in these times ❤️

@carolynvs carolynvs changed the base branch from main to release/v1 August 26, 2021 18:38
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

This looks great! I have some small changes to polish it up and then we can merge.

I have changed the target branch for your pull request to release/v1 as we are no longer adding new features to the main branch while we work on v1. Let me know if that causes you any trouble. I will resolve the merge conflict on that doc page once all of your changes are in so that I don't get in your way.

Makefile Outdated
# Wait for the documentation web server to finish rendering
@until docker logs porter-docs | grep -m 1 "Web Server is available"; do : ; done
@open "http://localhost:1313/docs/"
# @open "http://localhost:1313/docs/"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you were either having trouble with this line, or testing something and left this change in? Let's revert the changes to this file.

func TestPorter_CreateMixin(t *testing.T) {
p := NewTestPorter(t)

homeDir, err := os.UserHomeDir()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not immediately seeing why you didn't use p.FileSystem.TempDir here? Is there a requirement that I'm missing?

gotOutput := p.TestConfig.TestContext.GetOutput()
assert.Contains(t, wantOutput, gotOutput)

err = os.RemoveAll(porterTempDir)
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 a good practice to cleanup temp files using a defer statement immediately after you create it (so on line 74).

defer os.RemoveAll(porterTempDir)

That way if the test stops prematurely for any reason, for example if CreateMixin panicked, we can be certain that the directory will be cleaned up.

@@ -0,0 +1,4 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you ran the smoke tests locally. There was a bug for a bit in porter where temporary files from running the smoke tests (like this file and .gitignore, dockerfile.tmp, etc) were written to the tests/smoke directory. Can you remove these from your PR? They shouldn't be checked in.

Use: "create NAME --author \"My Name\" --username mygithubusername [--dir /path/to/mixin/dir]",
Short: "Create a new mixin project based on the getporter/skeletor repository",
Long: `Create a new mixin project based on the getporter/skeletor repository.
The first argument is the name of the mixin to create and is required.
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: add a newline here so that when they print out the help it's not a giant paragraph. It will print a description of the command in the first paragraph and then details about how to use it in the second. I think that will be a bit easier for people to read.

Comment on lines 225 to 226
f.StringVar(&opts.AuthorName, "author", "", "Name of the mixin's author.")
f.StringVar(&opts.AuthorUsername, "username", "", "GitHub's username of the mixin's author.")
Copy link
Member

Choose a reason for hiding this comment

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

Here's a suggestion for an easier to read flag description:

Suggested change
f.StringVar(&opts.AuthorName, "author", "", "Name of the mixin's author.")
f.StringVar(&opts.AuthorUsername, "username", "", "GitHub's username of the mixin's author.")
f.StringVar(&opts.AuthorName, "author", "", "Your full name")
f.StringVar(&opts.AuthorUsername, "username", "", "Your GitHub username")

}
}

fmt.Fprintf(p.Out, "Created %s mixin", opts.MixinName)
Copy link
Member

Choose a reason for hiding this comment

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

This ensures that after the command is run, the shell prompt isn't printed on the same line as your last output:

Suggested change
fmt.Fprintf(p.Out, "Created %s mixin", opts.MixinName)
fmt.Fprintf(p.Out, "Created %s mixin\n", opts.MixinName)

@joshuabezaleel joshuabezaleel force-pushed the porter-mixin-create-command branch from c1a46c8 to 01a8bcc Compare September 19, 2021 18:08
@carolynvs
Copy link
Member

@joshuabezaleel Looks like this is ready for another review! I'll try to get to this today.

Only one of your commits has a line that says "signed-off-by ... Josh", which is why the DCO check is failing. If you are comfortable with git, you can fix that yourself with git rebase release/v1 --signoff. If you run into trouble signing your commits, leave a comment here that it's okay for me to squash your commits into a single one and use the signoff from your first commit.

Also there is a merge conflict on one of the files. If you can fix that, great, if not I'll resolve it when I merge your PR.

@joshuabezaleel joshuabezaleel force-pushed the porter-mixin-create-command branch from 01a8bcc to deed09e Compare September 20, 2021 13:43
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
…ate with author's GitHub username flag later

Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
2. Add unit test for `porter mixin create` command
3. Add content for `porter mixin create` command to mixin dev guide on docs

Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
…ular directory

Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
…st locally

Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
…r reading

Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
Signed-off-by: joshuabezaleel <joshua.bezaleel@gmail.com>
@joshuabezaleel joshuabezaleel force-pushed the porter-mixin-create-command branch from deed09e to 7532aff Compare September 20, 2021 13:58
@joshuabezaleel
Copy link
Contributor Author

Hi @carolynvs , sorry for the late update! Thank you so much for the really helpful inputs on the review and sorry for the unintentional changes that I've made on the last PR. I've tried to rebase the branch, resolve the conflict, and sign-off all of my commits, hopefully it doesn't cause any problems. 😅

Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Copy link
Member

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

I have added a commit to your PR that removes some files that should not have been checked into the tests/smoke directory.

@carolynvs carolynvs merged commit 9b87b62 into getporter:release/v1 Sep 28, 2021
@carolynvs
Copy link
Member

This will go out in the next alpha release of Porter! 🎉

@joshuabezaleel
Copy link
Contributor Author

Ah sorry that I missed and just read about this, thank you lots for the commit of removing the files and merging it @carolynvs ! 😄

@carolynvs
Copy link
Member

No worries! This PR is now included in v1.0.0-alpha.4 for anyone who wants to try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add porter mixin create command

2 participants