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

Use Go version from go.mod in basic-checks #5154

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

bestbeforetoday
Copy link
Member

The expected Go version was hard-coded in the Makefile, and this needed to be manually kept in sync with the CI and go.mod files. Since the go.mod entry needs to be accurate, this change uses the version from the go.mod file in the Makefile and no longer requires the Makefile to be manually kept up-to-date.

@bestbeforetoday bestbeforetoday marked this pull request as ready for review February 24, 2025 11:41
@bestbeforetoday bestbeforetoday requested a review from a team as a code owner February 24, 2025 11:41
@@ -77,7 +77,8 @@ METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)

GO_VER = 1.24.0
GO_VER := $(shell grep '^go[ \t]' < go.mod)
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this cannot use go list -m to obtain the version from the go directive since it will fail to parse the module file if the local Go version is behind the module's required Go version. This results in a less helpful error message from check_go_version.sh:

ERROR:  is required to build Fabric and you are using 1.23.5. Please update go.

Using the approach implemented here, the error message is more helpful:

ERROR: 1.24.0 is required to build Fabric and you are using 1.23.5. Please update go.

@denyeart
Copy link
Contributor

I like the idea of specifying Go version in a single place (go.mod file). Do you think it would make sense for the github action workflows to reference the go.mod as well?

@@ -77,7 +77,8 @@ METADATA_VAR += CommitSHA=$(EXTRA_VERSION)
METADATA_VAR += BaseDockerLabel=$(BASE_DOCKER_LABEL)
METADATA_VAR += DockerNamespace=$(DOCKER_NS)

GO_VER = 1.24.0
GO_VER := $(shell grep '^go[ \t]' < go.mod)
Copy link
Contributor

Choose a reason for hiding this comment

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

For people newer to Go and scripting, it may be nice to add a comment like:
Go version maintained in the go.mod file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

The expected Go version was hard-coded in the Makefile, and this needed
to be manually kept in sync with the CI and go.mod files. Since the
go.mod entry needs to be accurate, this change uses the version from the
go.mod file in the Makefile and no longer requires the Makefile to be
manually kept up-to-date.

Signed-off-by: Mark S. Lewis <[email protected]>
@bestbeforetoday
Copy link
Member Author

I like the idea of specifying Go version in a single place (go.mod file). Do you think it would make sense for the github action workflows to reference the go.mod as well?

It seems like that should be possible. After checking out the code, either:

  1. actions/setup-go at stable version (i.e. latest).
  2. Extract the Go version from go.mod using go list -m -f '{{.Version}}' go.
  3. actions/setup-go again using the extracted version.

or:

  1. Extract the Go version from go.mod using shell commands (similar to this PR).
  2. actions/setup-go using the extracted version.

Either approach could probably be rolled into a composite action (similar to the ones in fabric-samples) so it only appears as a single step in the existing workflows.

@denyeart
Copy link
Contributor

I like the idea of specifying Go version in a single place (go.mod file). Do you think it would make sense for the github action workflows to reference the go.mod as well?

It seems like that should be possible. After checking out the code, either:

  1. actions/setup-go at stable version (i.e. latest).
  2. Extract the Go version from go.mod using go list -m -f '{{.Version}}' go.
  3. actions/setup-go again using the extracted version.

or:

  1. Extract the Go version from go.mod using shell commands (similar to this PR).
  2. actions/setup-go using the extracted version.

Either approach could probably be rolled into a composite action (similar to the ones in fabric-samples) so it only appears as a single step in the existing workflows.

I would probably lean towards the latter for consistency. Also the double setup-go may confuse people, not to mention it takes about 20 seconds each time. I'll merge this one for now.

@denyeart denyeart merged commit a23e7b8 into hyperledger:main Feb 24, 2025
15 checks passed
@bestbeforetoday bestbeforetoday deleted the makefile-go-version branch February 25, 2025 14:11
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