actions / setup-go

Set up your GitHub Actions workflow with a specific version of Go
MIT License
1.41k stars 531 forks source link

setup-go does not work on macos-14 (M1) #454

Closed Le0Developer closed 7 months ago

Le0Developer commented 9 months ago

Description: actions/setup-go is erroring when used on macos-14 (M1 runners)

Action version: v5

Platform:

Runner type:

Tools version:

Repro steps:
https://github.com/Le0Developer/go-setup-macos-14

Expected behavior: Should build & print hello world.

Actual behavior:

Setup go version spec 
Warning: go-version input was not specified. The action will try to use pre-installed version.
/bin/sh: version: command not found
Error: Command failed:  version
/bin/sh: version: command not found
HarithaVattikuti commented 9 months ago

Hello @Le0Developer Thank you for creating this issue. We will investigate it and get back to you as soon as we have some feedback.

gaby commented 9 months ago

The action should be using the darwin-arm64 ? @Le0Developer have you tried specifying a version?

According to the official docs the arm64 m1 based images do not come with golang preinstalled.

Source: https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md

Try the following and it should work:

jobs:
  build:
    name: Build on macOS 14 (M1)
    runs-on: macos-14
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-go@v5
      with:
        go-version: '1.22.x'
        check-latest: true
    - run: go run hello.go
gaby commented 9 months ago

@HarithaVattikuti This action should default to installing the latest Golang on darwin platforms.

matthewhughes934 commented 9 months ago

@HarithaVattikuti This action should default to installing the latest Golang on darwin platforms.

:thinking: how should this action behaviour in general when Golang is not installed in the system and not version is given. At the moment: the line https://github.com/actions/setup-go/blob/6c1fd22b67f7a7c42ad9a45c0f4197434035e429/src/main.ts#L65 will have goPath == '' and run:

cp.execSync(` version`)

Resulting in the rather unclear error /bin/sh: version: command not found (i.e. the error from the issue)

In this case I suppose the action could:

Le0Developer commented 7 months ago

The action should be using the darwin-arm64 ? @Le0Developer have you tried specifying a version?

According to the official docs the arm64 m1 based images do not come with golang preinstalled.

Source: https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md

I'd expect setup-go to setup go, regardless of if it's already installed or not.

Try the following and it should work:

jobs:
  build:
    name: Build on macOS 14 (M1)
    runs-on: macos-14
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-go@v5
      with:
        go-version: '1.22.x'
        check-latest: true
    - run: go run hello.go

That does work! I was expecting it to default to the latest version, but that works!

aparnajyothi-y commented 7 months ago

Hello @Le0Developer, Apologies for the delay in the response and we have investigated the issue and we are able to reproduce the error with go-version input was not specified in the workflow file. The go-version input should specify the version of Go that we want to set up. If it's not provided, the action tries to use a pre-installed version, which seems to be failing.

Here is an example of how to specify the go-version input:

Thank you for the confirmation and we have checked your workflow and the action is successful after adding the go-version. Hello @gaby, actions/setup-go action can indeed be set up to install the latest version of Go. However, it doesn't default to installing the latest version unless you specify it.

To set up the latest stable version of Go, you can use the @latest version specifier in your workflow file:

Proceeding to close this as the issue resolved with go-version. Please feel free to reach us in case of any further clarifications to reopen this issue.

zpavlinovic commented 1 month ago

...

To set up the latest stable version of Go, you can use the @latest version specifier in your workflow file:

  • name: Set up Go uses: actions/setup-go@v5 with: go-version: '1.12' check-latest: true

Proceeding to close this as the issue resolved with go-version. Please feel free to reach us in case of any further clarifications to reopen this issue.

Sorry, could you explain more how to use @latest qualifier as go-version. I would like to avoid updating go-version every time there is a major Go release (1.22.x, 1.23.x, and so on).

matthewhughes-uw commented 1 month ago

Sorry, could you explain more how to use @latest qualifier as go-version. I would like to avoid updating go-version every time there is a major Go release (1.22.x, 1.23.x, and so on).

You could use the "stable" and "oldstable" aliases https://github.com/actions/setup-go?tab=readme-ov-file#using-stableoldstable-aliases