setup-go icon indicating copy to clipboard operation
setup-go copied to clipboard

Support for Outputting or Exporting Go Environment Variables

Open bflad opened this issue 4 years ago • 9 comments

Version

actions/setup-go@v2

Description

In some of our GitHub Actions workflows, we opt to cache the GOCACHE between jobs to save compilation time. It seems like we currently need to run go env GOCACHE to fetch the correct GOCACHE path after this action is run, e.g.

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-go@v2
      with:
        go-version: "1.14"
    - name: go env
      run: |
        echo "::set-env name=GOCACHE::$(go env GOCACHE)"
    - uses: actions/cache@v2
      with:
        path: ${{ env.GOCACHE }}
        key: ${{ runner.os }}-GOCACHE-${{ hashFiles('go.sum') }}-${{ hashFiles('src/**') }}

Since this action already runs go env, it would be great if those values were either available as outputs, e.g.

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-go@v2
      id: setup_go
      with:
        go-version: "1.14"
    - uses: actions/cache@v2
      with:
        path: ${{ steps.setup_go.outputs.GOCACHE }}
        key: ${{ runner.os }}-GOCACHE-${{ hashFiles('go.sum') }}-${{ hashFiles('src/**') }}

Or if we could configure environment variables to automatically be exported:

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: actions/setup-go@v2
      with:
        go-version: "1.14"
        export-environment-variables: [GOCACHE]
    - uses: actions/cache@v2
      with:
        path: ${{ env.GOCACHE }}
        key: ${{ runner.os }}-GOCACHE-${{ hashFiles('go.sum') }}-${{ hashFiles('src/**') }}

Thank you for the consideration! Please reach out if I'm missing something and this is already possible or if this would be acceptable as an enhancement.

bflad avatar May 28 '20 13:05 bflad

Hi @bflad ! Sorry for the late response! Could you please clarify if the issue is still actual for you? Thanks!

Sergey-Murtazin avatar Oct 19 '21 16:10 Sergey-Murtazin

It definitely helps make workflow definitions platform agnostic. For example, it would allow all three platform specific cache action examples to be replaced with a single more robust example:

- uses: actions/cache@v2
  with:
    path: |
      ${{ steps.setup_go.outputs.GOCACHE }}
      ${{ steps.setup_go.outputs.GOMODCACHE }}
    key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
    restore-keys: |
      ${{ runner.os }}-go-

This particular use case may not be as relevant if setup-go had a cache input (like setup-node) to handle cache setup.

jgustie avatar Oct 19 '21 17:10 jgustie

Hi @Sergey-Murtazin 👋 Certainly still valid for our use cases, mostly to help with platform agnostic workflows as mentioned above. Thanks!

bflad avatar Oct 19 '21 21:10 bflad

I was about to open a similar issue 🙂

I'm interested in GOPATH and I know it's pretty simple to retrieve it, but having it as an output of the action would make the workflows cleaner IMHO.

A JSON output of go env would work too.

lucacome avatar Jul 23 '22 03:07 lucacome

It'd be helpful to have go env as outputs from this action so that it's not necessary to solve for GOBIN, GOPATH, GOCACHE in the worflow.

qrkourier avatar Feb 15 '23 22:02 qrkourier

I've opened a #334 with some default outputs that I think will cover 99% of the cases, let me know what you think 🙏

lucacome avatar Feb 16 '23 21:02 lucacome

Run

urica12 avatar Feb 16 '23 23:02 urica12

Would love this as well. I currently have extra steps like echo "dir=$(go env GOMODCACHE)" >> ${GITHUB_OUTPUT}, which are verbose and wasteful, since setup-go has already run go env.

mvdan avatar Mar 27 '23 14:03 mvdan

The issue is waiting for the merge of the PR https://github.com/actions/setup-go/pull/334

dsame avatar Aug 28 '23 08:08 dsame