Skip to content

Support for Outputting or Exporting Go Environment Variables #54

Open
@bflad

Description

@bflad

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.

Activity

Sergey-Murtazin

Sergey-Murtazin commented on Oct 19, 2021

@Sergey-Murtazin
Contributor

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

jgustie

jgustie commented on Oct 19, 2021

@jgustie

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.

bflad

bflad commented on Oct 19, 2021

@bflad
Author

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

added
feature requestNew feature or request to improve the current logic
and removed
enhancementNew feature or request
on Oct 25, 2021
lucacome

lucacome commented on Jul 23, 2022

@lucacome

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.

removed their assignment
on Oct 27, 2022
qrkourier

qrkourier commented on Feb 15, 2023

@qrkourier

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.

lucacome

lucacome commented on Feb 16, 2023

@lucacome

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

urica12

urica12 commented on Feb 16, 2023

@urica12

Run

mvdan

mvdan commented on Mar 27, 2023

@mvdan

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.

self-assigned this
on Jul 12, 2023

9 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature requestNew feature or request to improve the current logic

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @bflad@dsame@lucacome@jgustie@qrkourier

    Issue actions

      Support for Outputting or Exporting Go Environment Variables · Issue #54 · actions/setup-go