Add porter mixin create command#1602
Conversation
b377f17 to
dccb2fb
Compare
|
Hi @carolynvs , I'm truly sorry for a really late PR. Looking forward to the review! 🙂 |
621ad3a to
530463b
Compare
carolynvs
left a comment
There was a problem hiding this comment.
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?
- Run the create command in a temp directory. You can mimic a test like this one to do it
- Run
make buildusing exec.Command in that directory and check that it doesn't return an error.
pkg/porter/mixins.go
Outdated
| } | ||
|
|
||
| replacementList := map[string]string{ | ||
| "get.porter.sh/mixin/skeletor": fmt.Sprintf("github.com/%s/%s", opts.AuthorName, opts.MixinName), |
There was a problem hiding this comment.
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?
cmd/porter/mixins.go
Outdated
| 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 |
There was a problem hiding this comment.
| 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).
|
@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! |
1fa711b to
8e8f394
Compare
|
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 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
left a comment
There was a problem hiding this comment.
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/" |
There was a problem hiding this comment.
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.
pkg/porter/mixins_test.go
Outdated
| func TestPorter_CreateMixin(t *testing.T) { | ||
| p := NewTestPorter(t) | ||
|
|
||
| homeDir, err := os.UserHomeDir() |
There was a problem hiding this comment.
I'm not immediately seeing why you didn't use p.FileSystem.TempDir here? Is there a requirement that I'm missing?
pkg/porter/mixins_test.go
Outdated
| gotOutput := p.TestConfig.TestContext.GetOutput() | ||
| assert.Contains(t, wantOutput, gotOutput) | ||
|
|
||
| err = os.RemoveAll(porterTempDir) |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
cmd/porter/mixins.go
Outdated
| f.StringVar(&opts.AuthorName, "author", "", "Name of the mixin's author.") | ||
| f.StringVar(&opts.AuthorUsername, "username", "", "GitHub's username of the mixin's author.") |
There was a problem hiding this comment.
Here's a suggestion for an easier to read flag description:
| 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") |
pkg/porter/mixins.go
Outdated
| } | ||
| } | ||
|
|
||
| fmt.Fprintf(p.Out, "Created %s mixin", opts.MixinName) |
There was a problem hiding this comment.
This ensures that after the command is run, the shell prompt isn't printed on the same line as your last output:
| fmt.Fprintf(p.Out, "Created %s mixin", opts.MixinName) | |
| fmt.Fprintf(p.Out, "Created %s mixin\n", opts.MixinName) |
c1a46c8 to
01a8bcc
Compare
|
@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 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. |
01a8bcc to
deed09e
Compare
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>
deed09e to
7532aff
Compare
|
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>
carolynvs
left a comment
There was a problem hiding this comment.
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.
|
This will go out in the next alpha release of Porter! 🎉 |
|
Ah sorry that I missed and just read about this, thank you lots for the commit of removing the files and merging it @carolynvs ! 😄 |
|
No worries! This PR is now included in v1.0.0-alpha.4 for anyone who wants to try it out! |
What does this change
Introduce
porter mixin createcommand which clone thegetporter/skeletorrepo 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