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

Add option to specify go version from go.mod or go.work #21

Merged
merged 6 commits into from
Aug 10, 2023

Conversation

manel-bc
Copy link
Contributor

@manel-bc manel-bc commented Aug 8, 2023

Something I've been missing from actions/setup-go.

It makes sure at least one of the inputs go-version or go-version-file is set, with the former taking precedence.

@WillAbides
Copy link
Owner

Thanks. I just discovered that feature of setup-go recently and was thinking about adding this. I'll review it later today or in the morning.

Copy link
Owner

@WillAbides WillAbides left a comment

Choose a reason for hiding this comment

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

The code looks good. I like that you used perl for the regex. Since it's a dependency anyway, we might as well use it for what it is good for 😄

I requested a couple of changes. Let me know if you have any questions or want help implementing them.

I'm not 100% sure if my suggestion of >=1.N works with semver-select. I'll check on that and report back if there are issues.

src/lib Outdated
return
fi

perl -nle 'print $1 if /^go (\d\.\d+)/' < "$go_file_path"
Copy link
Owner

Choose a reason for hiding this comment

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

I think it is valid to have space before "go" and more than one space between "go" and the version constraint.

The doc also gives 1.21rc1 as an example value, so we should capture to the end of the token.

It also says that 1.16 is assumed when there is no directive. So either select_go_version_from_file should return "1.16" when there is no match or src/run should set it to "1.16" when select_go_version_from_file returns nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new regexp should cater for that, and made 1.16 the default in case of no match

src/lib Outdated Show resolved Hide resolved
src/run Outdated
# shellcheck disable=2153 # false positive about GO_VERSION being a misspelling of go_version
constraint="$GO_VERSION"
if [ "$constraint" = "tip" ] || [ "$constraint" = "gotip" ]; then
constraint='*'
INSTALL_GO_TIP=1
fi

if [ -z "$constraint" ]; then
constraint="$(select_go_version_from_file "$GITHUB_WORKSPACE/$GO_VERSION_FILE")"
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure that using the output of select_go_version_from_file as the constraint is the right thing to do here. The go.mod doc says the version is the minimum version to use. So it seems like when the directive is 1.18 the constraint should be >=1.18 and 1.21rc1 should be >=1.21rc1.

I think sticking a >= at the beginning of the constraint is all we need to do here. It may not work quite right in the time between go1.22rc1 and go1.22, but this PR doesn't need to address that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added >=

Treat go version from file as minimum required
Copy link
Owner

@WillAbides WillAbides left a comment

Choose a reason for hiding this comment

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

Thanks for updating. Just one more change to the regex. I also need to update semver-select to make it work with release candidates.

src/lib Outdated Show resolved Hide resolved
Co-authored-by: WillAbides <233500+WillAbides@users.noreply.github.com>
@WillAbides WillAbides self-requested a review August 10, 2023 13:38
Copy link
Owner

@WillAbides WillAbides left a comment

Choose a reason for hiding this comment

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

LGTM. I'm going to merge this then make a PR of my own to update the semver-select version before doing a release.

@WillAbides WillAbides merged commit b25f96d into WillAbides:main Aug 10, 2023
13 checks passed
@manel-bc
Copy link
Contributor Author

Nice, thanks :)

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.

None yet

2 participants