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 single source for go version #4794

Merged
merged 1 commit into from
Apr 10, 2024
Merged

Conversation

grosser
Copy link
Contributor

@grosser grosser commented Apr 2, 2024

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

  • unify version that ci uses
  • make life easier for anyone using a go version manager

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 2, 2024
@karmada-bot
Copy link
Collaborator

Welcome @grosser! It looks like this is your first PR to karmada-io/karmada 🎉

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 2, 2024
@grosser grosser marked this pull request as ready for review April 3, 2024 00:05
@karmada-bot karmada-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 3, 2024
@XiShanYongYe-Chang
Copy link
Member

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

@RainbowMango
Copy link
Member

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

Copy link
Contributor

@liangyuanpeng liangyuanpeng left a comment

Choose a reason for hiding this comment

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

You still need to using it on the workflow, otherwise it will not working.

https://github.com/etcd-io/etcd/blob/547aa643e69d55328b203f40ccec50256b44158e/.github/workflows/build.yaml#L24-L28

      - id: goversion
        run: echo "goversion=$(cat .go-version)" >> "$GITHUB_OUTPUT"
      - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
        with:
          go-version: ${{ steps.goversion.outputs.goversion }}

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 3, 2024
@grosser
Copy link
Contributor Author

grosser commented Apr 3, 2024

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
Copy link
Contributor

liangyuanpeng commented Apr 3, 2024

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

@grosser
Copy link
Contributor Author

grosser commented Apr 4, 2024

👋 need a CI approval

@liangyuanpeng
Copy link
Contributor

The karmada's maintainers will return from vacation tomorrow.

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2024
@liangyuanpeng
Copy link
Contributor

I think it's need to squash the commit

@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 6, 2024
@grosser
Copy link
Contributor Author

grosser commented Apr 6, 2024

squashed into single commit

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

@grosser
Copy link
Contributor Author

grosser commented Apr 6, 2024

and need another approval @liangyuanpeng

@RainbowMango
Copy link
Member

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
Copy link
Contributor Author

grosser commented Apr 7, 2024

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

@grosser
Copy link
Contributor Author

grosser commented Apr 8, 2024

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
Copy link
Member

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:

  • Is the .go-version file a standard way that can be consumed by common go-version managers? Otherwise, consider a situation, where a developer uses another go-version manager which requires a different file, shall we introduce another go-version file?
  • Can we put .go-version file to somewhere inside the repo(not in the root of repo)? There are already too many scattered files in the root directory.

@RainbowMango
Copy link
Member

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

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

@RainbowMango
Copy link
Member

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
Copy link
Contributor Author

grosser commented Apr 9, 2024

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

@RainbowMango
Copy link
Member

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
Copy link
Contributor

liangyuanpeng commented Apr 9, 2024

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
Copy link
Contributor Author

grosser commented Apr 9, 2024

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

@RainbowMango
Copy link
Member

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
Copy link
Member

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

@karmada-bot karmada-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 10, 2024
@grosser
Copy link
Contributor Author

grosser commented Apr 10, 2024

rebased + updated go.mod to have full version

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

Signed-off-by: Michael Grosser <michael@grosser.it>
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

Looks good to me!
/lgtm

@liangyuanpeng Do you have further comments?

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 10, 2024
@grosser
Copy link
Contributor Author

grosser commented Apr 10, 2024

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

@RainbowMango
Copy link
Member

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

@grosser
Copy link
Contributor Author

grosser commented Apr 10, 2024

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

@RainbowMango
Copy link
Member

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
Copy link
Collaborator

[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:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 10, 2024
@karmada-bot karmada-bot merged commit d42c2a8 into karmada-io:master Apr 10, 2024
12 checks passed
@grosser grosser deleted the grosser/1.21 branch April 10, 2024 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants