DEV Community

Cover image for invalid go version '1.21.4': must match format 1.23
Mathias Jiya
Mathias Jiya

Posted on

invalid go version '1.21.4': must match format 1.23

Todays article is about how to get passed this error. So, I was trying to setup a GitHub workflow (golangci-lint and tests) for a project I am working on and then this error came up.
The above error is as a result of the go version in your go.mod file. Which apparently should look like this 1.x.x but the GitHub actions you are trying to setup wants it to be in this format 1.x
The way to solve this problem is to update the go version in your go.mod file to be 1.21 instead of 1.21.4. Also, note that if any of your GitHub actions is running the command go tidy in anyway, then you will need to reduce the go version in your go.mod file because the maximum version supported by the go tidy is 1.20 else you'll get another kind of error similar to maximum version supported by the go tidy is 1.20 for that particular Github action.

Generally, when you get this error, just update your go version from this format 1.x.x to 1.x and you should be good.
Do have a wonderful day ;).

Top comments (4)

Collapse
 
mrwormhole profile image
Talha Altınel • Edited

go mod tidy and golangci-lint works in every version? curious what GH action you are using on

Collapse
 
iqquee profile image
Mathias Jiya

This is the GitHub actions I was trying to run. For some reasons, on this line run: cd src && go get && go mod tidy && go test ./... it returned an maximum go version supported by go mod tidy and after updating the go version everything works as they should.

on: [pull_request]
name: tests
jobs:
  test-service:
    runs-on: ubuntu-latest
    steps:
      - name: Install Go
        uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Install dependencies
        run: cd src && go get github.com/golang/mock/mockgen@v1.6.0
      - name: test
        run: cd src && go get && go mod tidy && go test ./...
Enter fullscreen mode Exit fullscreen mode


sh

Collapse
 
mrwormhole profile image
Talha Altınel

some of the GH actions look like in older versions, I would recommend updating them then also pls do not mutate the state of go.mod via go get during a CI/CD phase. Anything that runs go test or go build automatically does go mod download if vendor file is not created specifically via go mod vendor , you don't really need to run go get or go mod tidy in any of these cases

Thread Thread
 
iqquee profile image
Mathias Jiya

Thanks boss.