Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling version string in code generated header #3509

Closed
wants to merge 13 commits into from

Conversation

davideme
Copy link

When Updating goa version it's hard to detect the files that are only changing the version number and the ones that are changing code.
Screenshot 2024-04-16 at 17 45 42

I'm proposing adding a Meta Field "goa:version:disable" that would disable the version for this specific section.

	Meta("goa:version:disable", "true")

Remarks:

  • I can change any naming, I'm more interested in the functionality.

cmd/goa/gen.go Outdated Show resolved Hide resolved
Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

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

Thank you, this looks great! I left a few suggestions.

return &SectionTemplate{
Name: "source-header",
Source: headerT,
Data: map[string]any{
"Title": title,
"ToolVersion": goa.Version(),
"ToolVersion": toolVersion,
Copy link
Member

Choose a reason for hiding this comment

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

Just to be consistent maybe this should be disableVersion and the test in the template should be {{ if not .DisableVersion }}?

@@ -68,6 +68,16 @@ import (
package testpackage

`, goa.Version())
titleHeaderDisableVersion = `// Code generated by goa, DO NOT EDIT.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we call this titleHeaderVersionDisabled to make it a qualified name?

header := codegen.Header(service.Name+" client", svc.PkgName, imports)
value, ok := service.Meta.Last("goa:version:disable")
disableVersion := ok && value == "true"
header := codegen.Header(service.Name+" client", svc.PkgName, imports, disableVersion)
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 wondering if we wouldn't be better of passing the metadata object to codegen.Header and moving the logic that computes disableVersion there:

  • This would remove the need for having this computation spread everywhere
  • This would allow for other metadata based tweaks in the future when generating file headers

@davideme
Copy link
Author

@raphael all suggestions applied. Happy to see it's not far off what was expected.

@davideme davideme requested a review from raphael April 17, 2024 07:47
@davideme
Copy link
Author

Any update ?

@raphael
Copy link
Member

raphael commented Apr 22, 2024

Sorry for the delay, changes look great! Just one last question: I see a number of places where nil is given as argument for the metadata. This means that these files will still have the version number in the header, is that what we want?

goa "goa.design/goa/v3/pkg"
)

// Header returns a Go source file header section template.
func Header(title, pack string, imports []*ImportSpec) *SectionTemplate {
func Header(title, pack string, imports []*ImportSpec, meta expr.MetaExpr) *SectionTemplate {
value, ok := meta.Last("goa:version:disable")
Copy link
Member

Choose a reason for hiding this comment

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

Meta("goa:version:generate", "false") might be better.
It's a similar syntax to Meta("openapi:generate", "false").

Copy link
Author

Choose a reason for hiding this comment

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

Done

@davideme
Copy link
Author

@tchssk I update the Meta name.
@raphael I review all the calls to Header,

  • The ones that have a service associated are called with .Meta
  • The ones that are in example files that don't have service associated are called with nil, happy to bring another improvement in a subsequent PR if you have any suggestions on how to pass it.
  • The one in cmd/goa/gen.go could be provided by command line params but it felt like an additional feature not part of this. And could be confusing as it's not configurable via Meta tags.

@davideme davideme requested a review from tchssk April 23, 2024 08:19
@raphael
Copy link
Member

raphael commented Apr 23, 2024

The changes look great, thank you for the contribution!

@tchssk
Copy link
Member

tchssk commented Apr 24, 2024

Could you please wait a moment?
I'm worried about backward compatibility.

@davideme
Copy link
Author

@tchssk let me know which kind of scenario you are thinking? Having the meta tag in a previous version of goa?

@davideme
Copy link
Author

Before merging, we are doing some additional testing in our own codebase of around 600 goa generated files.

@tchssk
Copy link
Member

tchssk commented Apr 24, 2024

Adding arguments to codegen.Header() breaks compatibility. Normally this function is only used internally in Goa, but I'm wondering if there is another way to solve the problem if possible.

  • Adding a cli flag
  • Implement as a plugin

@raphael
Copy link
Member

raphael commented Apr 24, 2024

Adding arguments to codegen.Header() breaks compatibility. Normally this function is only used internally in Goa, but I'm wondering if there is another way to solve the problem if possible.

  • Adding a cli flag
  • Implement as a plugin

Good point! A third option could be to make the extra parameter optional (e.g. using the functional options pattern). We've avoided adding CLI flags in the past and I'm not sure this would be worth the trade-off.

@tchssk
Copy link
Member

tchssk commented Apr 25, 2024

I prefer plugins to keep the core simple, but optional parameters aren't bad either.

@davideme
Copy link
Author

After testing extensively in our code base, using Meta tag seems impractical. it will fill the design files with tag for each kind of files.
I'll explore the plugin way.

@tchssk
Copy link
Member

tchssk commented Apr 25, 2024

I created a plugin. Here you are.
https://github.com/tchssk/goaplugins/tree/master/goaversionremover

@davideme davideme closed this Apr 26, 2024
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.

None yet

3 participants