Skip to content

make extension create binary aware#4718

Merged
vilmibm merged 1 commit intotrunkfrom
bin-ext-create
Nov 30, 2021
Merged

make extension create binary aware#4718
vilmibm merged 1 commit intotrunkfrom
bin-ext-create

Conversation

@vilmibm
Copy link
Contributor

@vilmibm vilmibm commented Nov 12, 2021

It's entirely possible I have overdone this and please tell me if so.

This PR adds a small wizard to gh extension create that collects a name and "type" of extension to create: script-based, go-based, or other compiled.

It also supposed --precompiled=go and --precompiled=other to avoid interactivity.

For Go extensions, it lays out a main.go with some helper functions pre-seeded as well as a workflow file that uses https://github.com/cli/gh-extension-precompile with default arguments.

For non-Go binary extensions, it lays out a stubbed script/build.sh script as well as a workflow file that uses https://github.com/cli/gh-extension-precompile with build_override: script/build.sh passed.

Part of #4194

@vilmibm vilmibm marked this pull request as ready for review November 17, 2021 00:00
@vilmibm vilmibm requested a review from a team as a code owner November 17, 2021 00:00
@vilmibm vilmibm requested review from samcoe and removed request for a team November 17, 2021 00:00
@vilmibm vilmibm changed the title [WIP] gh extension create --precompiled make extension create binary aware Nov 17, 2021
@vilmibm vilmibm requested a review from mislav November 17, 2021 00:03
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

This is great!

I do feel, however, that embedding files inline in Go code makes the overall implementation hard to scan, even when heredocs are used, so I've proposed using a Go 1.16 feature of file embedding as an alternative.

For Go extensions:

  1. Should we generate a go.mod so that extensions are immediately buildable? We could generate the name of the module as github.com/<owner>/gh-<extension-name>
  2. Will the users know how to build and test the extension in development? Should we include instructions on how to build it, or a Makefile even to make rebuilding easier locally?

@vilmibm
Copy link
Contributor Author

vilmibm commented Nov 17, 2021

@mislav Thanks for the feedback! Agreed on all the points but wanted to discuss:

Should we generate a go.mod so that extensions are immediately buildable? We could generate the name of the module as github.com//gh-

I worried that this was assuming too much on behalf of the users, but I am definitely intrigued by doing it. Thinking about the context of all this more this actually seems pretty low risk, so yeah, let's do it.

Should we hardcode github.com though? or try and use whatever host is set?

Will the users know how to build and test the extension in development? Should we include instructions on how to build it, or a Makefile even to make rebuilding easier locally?

I'm worried about this too. I included a hint about go build after doing a local install, but that might not paint a full enough picture of what to do. I can expand that help text for go extensions.

As for make, it's an interesting idea but I'd rather punt. It isn't on Windows by default and I don't think it's worth the complexity -- especially when go build is so succinct.

@mislav
Copy link
Contributor

mislav commented Nov 18, 2021

Should we hardcode github.com though? or try and use whatever host is set?

You could read the DefaultHost from config, which would be github.com normally or the value of GH_HOST if set. But even just hardcoding github.com would be fine with me— we won't always get the module name right; it's just helpful to cover 80% of the cases. In the end, the module name doesn't need to correspond to a real repository on a GitHub instance, since gh extensions don't necessarily need to be go-gettable, and our Action to precompile Go extensions will happily build a Go module with any name.

I included a hint about go build after doing a local install, but that might not paint a full enough picture of what to do. I can expand that help text for go extensions.

We can assume that Go developers will in general know how to use go build, but they might forget that the output binary should be ./gh-<my-extension>(.exe) so that they can run gh <my-extension> while testing their extension. That's why including some hint might be really helpful for users to get started.

@vilmibm
Copy link
Contributor Author

vilmibm commented Nov 18, 2021

Sounds good re: host.

they might forget that the output binary should be ./gh-(.exe)

This is precisely what go build creates. In my hint I was over-explicit and said go build -o %s but without -o go uses the name of the directory housing main.go as the name for the output executable. on windows it appends .exe automatically. As far as I can tell, the developer literally only needs to gh install . and go build.

@vilmibm
Copy link
Contributor Author

vilmibm commented Nov 18, 2021

This is ready for re-review. Here's the current state of the user output:

image

cc @mislav

Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

Looks good! Just polish-level suggestions remain

@vilmibm
Copy link
Contributor Author

vilmibm commented Nov 23, 2021

I've:

  • changed the main.go template to invoke a REST call with go-gh
  • made it clear that we downloaded go dependencies
  • did end to end QA for all three extension types

Not going to merge immediately until we confirm whether we are ok with it quietly shipping this week or if we want to wait to merge until next week's loud ship

- add a wizard to gh extension create
- add --precompiled-go
- add --precompiled-other
- build out scaffolding for both types of binary extensions
Copy link
Contributor

@mislav mislav left a comment

Choose a reason for hiding this comment

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

I'd say merge away!!

@mislav mislav mentioned this pull request Nov 24, 2021
@vilmibm vilmibm merged commit 56faf17 into trunk Nov 30, 2021
@vilmibm vilmibm deleted the bin-ext-create branch November 30, 2021 22:36
@VictorBatta VictorBatta mentioned this pull request Dec 4, 2021
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.

2 participants