karmada-io / karmada

Open, Multi-Cloud, Multi-Cluster Kubernetes Orchestration
https://karmada.io
Apache License 2.0
4.12k stars 807 forks source link

use single source for go version #4794

Closed grosser closed 3 weeks ago

grosser commented 1 month ago

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE
karmada-bot commented 1 month ago

Welcome @grosser! It looks like this is your first PR to karmada-io/karmada πŸŽ‰

XiShanYongYe-Chang commented 1 month ago

Hi @grosser, do you have any documentation on how to use the .go-version file?

RainbowMango commented 1 month ago

I'm also curious about how it works. I couldn't find more information, except the asdf thing: https://github.com/asdf-community/asdf-golang?tab=readme-ov-file#version-selection

grosser commented 1 month ago

trying with go-version-file that hopefully works 🀞

tools like go-env / asdf / mise can read this file to set the local go version some of them can also read .go.mod, but asdf and mise refuse to read from it because of some rabbithole

liangyuanpeng commented 1 month ago

I can see that the .go-version is working .

grosser commented 1 month ago

πŸ‘‹ need a CI approval

liangyuanpeng commented 4 weeks ago

The karmada's maintainers will return from vacation tomorrow.

/lgtm

liangyuanpeng commented 4 weeks ago

I think it's need to squash the commit

grosser commented 4 weeks ago

squashed into single commit

if single commit is a requirement, making the PR template say it would speed up PRs

grosser commented 4 weeks ago

and need another approval @liangyuanpeng

RainbowMango commented 4 weeks ago

and need another approval @liangyuanpeng

Done.

codecov-commenter commented 4 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 51.76%. Comparing base (a0c0a98) to head (5bdc159). Report is 6 commits behind head on master.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #4794 +/- ## ======================================= Coverage 51.75% 51.76% ======================================= Files 250 250 Lines 24980 24980 ======================================= + Hits 12928 12930 +2 + Misses 11342 11340 -2 Partials 710 710 ``` | [Flag](https://app.codecov.io/gh/karmada-io/karmada/pull/4794/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | Coverage Ξ” | | |---|---|---| | [unittests](https://app.codecov.io/gh/karmada-io/karmada/pull/4794/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io) | `51.76% <ΓΈ> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=karmada-io#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

RainbowMango commented 4 weeks ago

Hey guys, I just made a test on my forked repo, and seems actions/setup-go@v5 can read Go version from go.mod file. Here is the change:

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 6cec21009..3c91b0dbf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -16,9 +16,9 @@ jobs:
       - name: checkout code
         uses: actions/checkout@v3
       - name: install Go
-        uses: actions/setup-go@v3
+        uses: actions/setup-go@v5
         with:
-          go-version: 1.21.8
+          go-version-file: go.mod
       - name: verify license
         run: hack/verify-license.sh
       - name: vendor
diff --git a/go.mod b/go.mod
index 13d6c12c9..3901dc429 100644
--- a/go.mod
+++ b/go.mod
@@ -1,6 +1,6 @@
 module github.com/karmada-io/karmada

-go 1.21
+go 1.21.1

 require (
        github.com/adhocore/gronx v1.6.3

I intentionally set the Go version to v1.21.1 instead of the current using version(v1.21.8), to test if it works. The test result shows it indeed works as expected. See the workflow logs here: https://github.com/RainbowMango/karmada/actions/runs/8585586406/job/23527142126#step:3:18

RainbowMango commented 4 weeks ago

unify version that ci uses

I guess we can solve it by the test approach mentioned on above.

make life easier for anyone using a go version manager

Which go version manager are you using? can it read go version from the go.mod file?

grosser commented 4 weeks ago

I'm using mise, which refuses to read the go.mod sadly (already opened issue, but they say "go.mod says what the minimum version is") (same for asdf) go-env does read it though using go.mod for this and having a .go-version file would also work fine

RainbowMango commented 4 weeks ago

I'm using mise, which refuses to read the go.mod sadly (already opened issue, but they say "go.mod says what the minimum version is")

Which mise? Can you share the issue link?

grosser commented 4 weeks ago

https://github.com/jdx/mise/issues/1689#issuecomment-1955357190

RainbowMango commented 4 weeks ago

I haven't used mise before, but I just tried it out. I still don't know how the auto-switching works, and what its benefit is. Can you help to explain it a little bit?

grosser commented 4 weeks ago

auto-switching switches the go version when cd-ing into a directory according to the directories .go-version

grosser commented 3 weeks ago

I'm ok with either ... just want someone with merge permission to tell me what they would be willing to merge and will make adjustments accordingly. Would also love to merge as is and create followup for adding to go.mod to move the discussion 🀷

RainbowMango commented 3 weeks ago

Thanks @grosser.

This PR consists of two parts actually as you mentioned in the PR description:

unify version that ci uses

Great thanks for bringing this discussion, really helpful! This part is clear, that we can add the Go version to go.mod and let CI get the version from it.

make life easier for anyone using a go version manager

For this part, I'm evaluating all these go-version managers(mise, asdf, go-env) to figure out the following questions:

RainbowMango commented 3 weeks ago

It seems both mise and asdf provided the auto-switching feature:

They both support .tool-versions, can we use this file?

RainbowMango commented 3 weeks ago

auto-switching switches the go version when cd-ing into a directory according to the directories .go-version

This feature is awesome by the way. Just tried it out.

grosser commented 3 weeks ago

why would we need .tool-versions, this repo only uses go right ?

RainbowMango commented 3 weeks ago

yeah, since .tool-versions can be consumed by both asdf and mise users.

I mean take go.mod as a single source of truth, and the .tool-versions dedicated to those go-version managers.

liangyuanpeng commented 3 weeks ago

I think @RainbowMango is mean we want to use go.mod for the project and CI, then .tool-versions to working for go-version managers.

There are two topic, the Part1 is go version for build & CI, Part2 is the file for people who using the go-version managers.

I can see common practice ( kubernetes/kind/etcd ) is that go mod is set to the language version, and .go-version uses the higher version for compilation and building.

But as @RainbowMango say, using go.mod to unify go versions in CI may be a direction, so maybe we can try to using go.mod for CI and .tool-versions to working go version manager.

auto-switching switches the go version when cd-ing into a directory according to the directories .go-version

would you like to try with .tool-versions ? ( I don't have try them )

grosser commented 3 weeks ago

asdf also supports .go-version, so can we avoid 1 level of indirection by using that instead of .tool-versions ?

RainbowMango commented 3 weeks ago

asdf also supports .go-version, so can we avoid 1 level of indirection by using that instead of .tool-versions ?

Thanks for the reminder. I didn't notice it. then I belive .go-version is better than .tool-versions.

RainbowMango commented 3 weeks ago

By the way, the actions/setup-go has been updated to v5 by #4756, you might need to rebase when making adjustments.

grosser commented 3 weeks ago

rebased + updated go.mod to have full version

... is this mergeable now or what still needs to change ?

grosser commented 3 weeks ago

plz restart the 1 failed ci job, seems unrelated ...

RainbowMango commented 3 weeks ago

Done. This reminds me to hurry up the #4637, after that we can restart the test by /retest command.

grosser commented 3 weeks ago

still 2 checks pending ... any idea how to get them to pass ?

RainbowMango commented 3 weeks ago

still 2 checks pending ... any idea how to get them to pass ?

All good now. Ready to move forward now. /approve @liangyuanpeng If you have any further comments, please continue...

karmada-bot commented 3 weeks ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/karmada-io/karmada/blob/master/OWNERS)~~ [RainbowMango] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment