4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHub ActionsでGo 1.20使用時に `go mod tidy` が失敗した場合

Posted at

TL; DR

バージョンはクオーテーションで囲みましょう :innocent:

go-version: '1.20'

はじめに

Go1.20を使ってGitHub Actionsを実行していたら、go mod tidy が以下のエラーで失敗してしまいました。

go mod tidy: exit status 2; output: go: unknown subcommand "mod"

mod がなぜか認識されない...?

.github/workflows/release.yml
name: release
jobs:
  goreleaser:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Setup Go
        uses: actions/setup-go@v3
        with:
          # Goのバージョン
          go-version: 1.20

原因

バージョンを数値で指定したので、Go 1.2 がインストールされてしまったのが原因でした。それは go mod 使えなくても仕方がない :angel:

Run actions/setup-go@v3
  with:
    go-version: 1.2
    check-latest: false
    token: ***
    cache: false
Setup go version spec 1.2
Attempting to download 1.2...
matching 1.2...
Not found in manifest.  Falling back to download directly from Go
Install from dist
Acquiring go1.2.2 from https://storage.googleapis.com/golang/go1.2.2.linux-amd64.tar.gz

正しくは文字列で以下のように指定します。

.github/workflows/release.yml
      - name: Setup Go
        uses: actions/setup-go@v3
        with:
          # これで末尾の0が消えることは無い
          go-version: '1.20'

ただのポカミスですね...
エラー理由に一瞬ぎょっとしたので、忘れないように記事にしました。yamlを書くときは文字列のクオーテーションを忘れずに!

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?