|
| 1 | +name: "Setup Go Paths" |
| 2 | +description: Overrides Go paths like GOCACHE and GOMODCACHE to use temporary directories. |
| 3 | +outputs: |
| 4 | + gocache: |
| 5 | + description: "Value of GOCACHE" |
| 6 | + value: ${{ steps.paths.outputs.gocache }} |
| 7 | + gomodcache: |
| 8 | + description: "Value of GOMODCACHE" |
| 9 | + value: ${{ steps.paths.outputs.gomodcache }} |
| 10 | + gopath: |
| 11 | + description: "Value of GOPATH" |
| 12 | + value: ${{ steps.paths.outputs.gopath }} |
| 13 | + gotmp: |
| 14 | + description: "Value of GOTMPDIR" |
| 15 | + value: ${{ steps.paths.outputs.gotmp }} |
| 16 | + cached-dirs: |
| 17 | + description: "Go directories that should be cached between CI runs" |
| 18 | + value: ${{ steps.paths.outputs.cached-dirs }} |
| 19 | +runs: |
| 20 | + using: "composite" |
| 21 | + steps: |
| 22 | + - name: Override Go paths |
| 23 | + id: paths |
| 24 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 |
| 25 | + with: |
| 26 | + script: | |
| 27 | + const path = require('path'); |
| 28 | +
|
| 29 | + // RUNNER_TEMP should be backed by a RAM disk on Windows if |
| 30 | + // coder/setup-ramdisk-action was used |
| 31 | + const runnerTemp = process.env.RUNNER_TEMP; |
| 32 | + const gocacheDir = path.join(runnerTemp, 'go-cache'); |
| 33 | + const gomodcacheDir = path.join(runnerTemp, 'go-mod-cache'); |
| 34 | + const gopathDir = path.join(runnerTemp, 'go-path'); |
| 35 | + const gotmpDir = path.join(runnerTemp, 'go-tmp'); |
| 36 | +
|
| 37 | + core.exportVariable('GOCACHE', gocacheDir); |
| 38 | + core.exportVariable('GOMODCACHE', gomodcacheDir); |
| 39 | + core.exportVariable('GOPATH', gopathDir); |
| 40 | + core.exportVariable('GOTMPDIR', gotmpDir); |
| 41 | +
|
| 42 | + core.setOutput('gocache', gocacheDir); |
| 43 | + core.setOutput('gomodcache', gomodcacheDir); |
| 44 | + core.setOutput('gopath', gopathDir); |
| 45 | + core.setOutput('gotmp', gotmpDir); |
| 46 | +
|
| 47 | + const cachedDirs = `${gocacheDir}\n${gomodcacheDir}`; |
| 48 | + core.setOutput('cached-dirs', cachedDirs); |
| 49 | +
|
| 50 | + - name: Create directories |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -e |
| 54 | + mkdir -p "$GOCACHE" |
| 55 | + mkdir -p "$GOMODCACHE" |
| 56 | + mkdir -p "$GOPATH" |
| 57 | + mkdir -p "$GOTMPDIR" |
0 commit comments