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

Automatically update and check copied code #13

Merged

Conversation

jhernand
Copy link
Collaborator

We copy the GraphQL models from the stolostron/search-api-v2 project in order to avoid additional dependencies. This patch adds go:generate directives to automatically update that code when make generate is executed.

Related: https://issues.redhat.com/browse/MGMT-16108
Related: https://github.com/stolostron/search-v2-api/blob/main/graph/schema.graphqls
Related: https://github.com/stolostron/search-v2-api/blob/main/graph/model/models_gen.go

We copy the GraphQL models from the `stolostron/search-api-v2` project
in order to avoid additional dependencies. This patch adds `go:generate`
directives to automatically update that code when `make generate` is
executed. A wanted side effect of that is that if the copied code is
changed manually the `check-generated-code` test will fail.

Related: https://issues.redhat.com/browse/MGMT-16108
Related: https://github.com/stolostron/search-v2-api/blob/main/graph/schema.graphqls
Related: https://github.com/stolostron/search-v2-api/blob/main/graph/model/models_gen.go
Signed-off-by: Juan Hernandez <[email protected]>
@jhernand
Copy link
Collaborator Author

FYI: @danielerez

// project, but we don't want to import it because that would bring many other dependencies
// that may be problematic in the future. Instead of that we copy that code into our project.
//
//go:generate curl -Lso searchapi.go https://raw.githubusercontent.com/stolostron/search-v2-api/234de1a26d82b3de2af74cf21aa1226db8e5f26a/graph/model/models_gen.go
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't it tied to a specific commit? I.e. I would expect it would fetch from latest 'master' branch? Or is there some other mechanism for fetching the latest bits?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is tied to a specific commit on purpose. We could get the latest from the master branch with this:

https://github.com/stolostron/search-v2-api/blob/main/graph/model/models_gen.go

But that would make the build non-repeatable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not that the point here is not really to automatically update, but rather to ensure that we don't manually change this file by accident. If we did, then the check-generated-code action would detect it and fail the build. Not super important, just a tad better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not that the point here is not really to automatically update, but rather to ensure that we don't manually change this file by accident. If we did, then the check-generated-code action would detect it and fail the build. Not super important, just a tad better.

Cool, makes sense.

@danielerez
Copy link
Collaborator

/lgtm

@jhernand jhernand merged commit 1c6a488 into openshift-kni:main Nov 14, 2023
4 checks passed
@jhernand jhernand deleted the check_changes_in_copied_graphql_code branch November 14, 2023 16:54
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