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
Retrieve go version from go.mod file #174
Comments
FWIW, this is the workaround I use: - run: sed -En 's/^go[[:space:]]+([[:digit:].]+)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }} |
Thanks @TMaYaD, that helped me a lot! - run: sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION }}" |
Linux- name: Get the system requirements.
run: sudo apt-get install coreutils -y
- name: Get the current version of Go from project.
run: cat go.mod | head -3 | tail -1 | echo "GO_VERSION_FROM_PROJECT=$(cut -d' ' -f2)" >>${GITHUB_ENV}
- name: Set up Go version "${{ env.GO_VERSION_FROM_PROJECT }}"
uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION_FROM_PROJECT }}"
id: go MacOS- name: Get the system requirements.
run: brew install coreutils
- name: Get the current version of Go from project.
run: cat go.mod | head -3 | tail -1 | echo "GO_VERSION_FROM_PROJECT=$(cut -d' ' -f2)" >>${GITHUB_ENV}
- name: Set up Go version "${{ env.GO_VERSION_FROM_PROJECT }}"
uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION_FROM_PROJECT }}"
id: go Windows- name: Get the current version of Go from project.
run: type go.mod | select -first 3 | select -last 1 | %{ 'GO_VERSION_FROM_PROJECT={1}' -f ($_ -split ' ') } >>$env:GITHUB_ENV
- name: Set up Go version "${{ env.GO_VERSION_FROM_PROJECT }}"
uses: actions/setup-go@v2
with:
go-version: "${{ env.GO_VERSION_FROM_PROJECT }}"
id: go |
Since Go is already available on the GH Action runners, you can have it as simple as:
|
What's for windows?? |
@prajwal-koirala-0000, it works for Windows as well: https://github.com/vsafonkin/test-repo/runs/6173404643?check_suite_focus=true |
Hello, @pantelis-karamolegkos 👋 Thank you and all others for contributing! We are closing this issue because this PR has been successfully merged. If you have any questions or additions feel free to ping us. Cheers! |
Description:
Instead of hard-coding the
go
version, the action could (optionally)go.mod
filego
version specified there.Justification:
Justification or a use case for your proposal.
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: