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 existing go version in go mod tidy an verify #242

Closed
wants to merge 1 commit into from

Conversation

elezar
Copy link
Contributor

@elezar elezar commented Nov 25, 2024

This change ensures that running make mod-tidy doesn't update the go version specified in the mod files.

@elezar elezar requested review from klihub and bart0sh November 25, 2024 13:12
@elezar elezar self-assigned this Nov 25, 2024
Makefile Outdated
@@ -74,14 +74,14 @@ $(BINARIES): bin/%:
mod-tidy:
$(Q)for mod in $$(find . -name go.mod); do \
echo "Tidying $$mod..."; ( \
cd $$(dirname $$mod) && go mod tidy \
cd $$(dirname $$mod) && go mod tidy -go=$$(grep -E "go\s+\d\.\d+" go.mod | sed 's/go //') \
Copy link
Contributor

@klihub klihub Nov 25, 2024

Choose a reason for hiding this comment

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

nit: maybe it's just me but my gut feeling would like that 'go ' pattern to be forced to only match at the beginning of the line with "^go...".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Makefile Outdated
) || exit 1; \
done

mod-verify:
$(Q)for mod in $$(find . -name go.mod); do \
echo "Verifying $$mod..."; ( \
cd $$(dirname $$mod) && go mod verify | sed 's/^/ /g' \
cd $$(dirname $$mod) && go mod verify -go=$$(grep -E "go\s+\d\.\d+" go.mod | sed 's/go //') | sed 's/^/ /g' \
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ditto here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Copy link
Contributor

@klihub klihub left a comment

Choose a reason for hiding this comment

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

LGTM, although I have a nit-desire related to forcing the go... pattern to be matched only at the beginning of a line.

@elezar elezar requested a review from klihub November 25, 2024 15:37
Copy link
Contributor

@klihub klihub left a comment

Choose a reason for hiding this comment

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

LGTM

Makefile Outdated
@@ -74,14 +74,14 @@ $(BINARIES): bin/%:
mod-tidy:
$(Q)for mod in $$(find . -name go.mod); do \
echo "Tidying $$mod..."; ( \
cd $$(dirname $$mod) && go mod tidy \
cd $$(dirname $$mod) && go mod tidy -go=$$(grep -E "^go\s+\d\.\d+$$" go.mod | sed 's/^go //') \
Copy link
Contributor

Choose a reason for hiding this comment

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

grep -E "^go\s+\d\.\d+$$" go.mod doesn't output anything in my env:

$ grep -E "^go\s+\d\.\d+$" go.mod || echo nope
nope

I think grep doesn't understand \d pattern, does it?

Copy link
Contributor Author

@elezar elezar Nov 26, 2024

Choose a reason for hiding this comment

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

container-device-interface git:(producer-api) ✗ grep -E "^go\s+\d\.\d+$" go.mod | sed 's/^go //'
1.20
grep --version
grep (BSD grep, GNU compatible) 2.6.0-FreeBSD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

go 1.20
➜  container-device-interface git:(fix-go-mod-tidy) ✗ grep -E "^go\s+[1-9]\.[0-9]+$" go.mod
go 1.20```

@@ -74,14 +74,14 @@ $(BINARIES): bin/%:
mod-tidy:
$(Q)for mod in $$(find . -name go.mod); do \
echo "Tidying $$mod..."; ( \
cd $$(dirname $$mod) && go mod tidy \
cd $$(dirname $$mod) && go mod tidy -go=$$(grep -E "^go\s+[1-9]\.[0-9]+$$" go.mod | sed 's/^go //') \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still not sure I understand the intent of the change.
According to the go mod tidy help output

The -go flag causes tidy to update the 'go' directive in the go.mod
file to the given version

However, updating the directive to the version from the same file does nothing, doesn't it?

Makefile Outdated
) || exit 1; \
done

mod-verify:
$(Q)for mod in $$(find . -name go.mod); do \
echo "Verifying $$mod..."; ( \
cd $$(dirname $$mod) && go mod verify | sed 's/^/ /g' \
cd $$(dirname $$mod) && go mod verify -go=$$(grep -E "^go\s+[1-9]\.[0-9]+$$" go.mod | sed 's/^go //') | sed 's/^/ /g' \
Copy link
Contributor

Choose a reason for hiding this comment

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

go mod verify doesn't have -go command line option according to its help page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right! Updated.

This change ensures that running make mod-tidy doesn't update the
go version specified in the mod files.

Signed-off-by: Evan Lezar <[email protected]>
@elezar elezar requested a review from bart0sh November 26, 2024 20:43
@elezar
Copy link
Contributor Author

elezar commented Nov 26, 2024

Actually, I think I missed something here. There reason my go version was being updated was that I had inadvertently created a go.mod file in api/producer with go 1.23.2 (running go mod init). This is then propagated to modules that pull this in.

I'm going to close this PR as unneeded since setting go 1.20 in that module addresses the issue.

Sorry for the back and forth.

@elezar elezar closed this Nov 26, 2024
@elezar elezar deleted the fix-go-mod-tidy branch November 26, 2024 20: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.

3 participants