ChristopherHX / gitea-actions-runner

MIT License
9 stars 2 forks source link

Unable to Locate XDG_CACHE_HOME and GOCACHE with actions/setup-go@v3 in ChristopherHX/gitea-actions-runner #5

Closed oilrich25 closed 11 months ago

oilrich25 commented 11 months ago

Issue Description:

When using ChristopherHX/gitea-actions-runner in conjunction with actions-runner/bin/Runner.Worker, there is an issue with the actions/setup-go@v3 action. Specifically, it fails to locate XDG_CACHE_HOME and GOCACHE during the execution.

Steps to Reproduce:

Use the following configuration for actions/setup-go@v3:

##[group]Run actions/setup-go@v3
with:
  go-version: >=1.21.0
  check-latest: false
  cache: false
env:
  CACHE_EPOCH: 1
  CCACHE_MAXFILES: 0
  CCACHE_MAXSIZE: 200M
  SCCACHE_CACHE_SIZE: 200M
##[endgroup]

Execute the workflow with the specified configuration.

Expected Behavior:

The actions/setup-go@v3 action should successfully set up Go version >=1.21.0 without encountering issues related to the missing XDG_CACHE_HOME and GOCACHE.

Actual Behavior:

The action encounters the following error:

warning: GOPATH set to GOROOT () has no effect
build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
##[error]Command failed: /root/oilrich25/gitea-actions-runner/actions-runner/_work/_tool/go/1.21.3/x64/bin/go env\nwarning: GOPATH set to GOROOT () has no effect\nbuild cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined\n

Additional Information:

  1. Operating System: Linux
  2. Go Version: 1.21.3
  3. Runner Environment: ChristopherHX/gitea-actions-runner with actions-runner/bin/Runner.Worker

Notes:

This issue seems to be related to the inability to locate the necessary build cache due to the absence of definitions for GOCACHE, XDG_CACHE_HOME, and HOME. Investigating and resolving this issue would ensure the successful execution of the workflow.

oilrich25 commented 11 months ago

Currently I have to set GOCACHE, XDC_CACHE_HOME in action.yaml. However, it seems that there is no need to set it in nektos/act. The values ​​​​of GOCACHE and XDC_CACHE_HOME are filled in by default. There is no need to set GOCACHE and XDC_CACHE_HOME in action.yaml.

name: Unit Tests

on:
  pull_request:
    branches:
      - "main"
  push:
    branches:
      - "main"

jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '>=1.21.0'

      - name: Test AdService
        run: |
          cd src/adservice
          go vet ./...
          go test -v ./...    
oilrich25 commented 11 months ago

github action:

Run actions/setup-go@v3
Setup go version spec >=1.21.0
Found in cache @ /opt/hostedtoolcache/go/1.21.4/x64
Added go to the path
Successfully set up Go version >=1.21.0
go version go1.21.4 linux/amd64

go env
  GO111MODULE=''
  GOARCH='amd64'
  GOBIN=''
  GOCACHE='/home/runner/.cache/go-build'
  GOENV='/home/runner/.config/go/env'
  GOEXE=''
  GOEXPERIMENT=''
  GOFLAGS=''
  GOHOSTARCH='amd64'
  GOHOSTOS='linux'
  GOINSECURE=''
  GOMODCACHE='/home/runner/go/pkg/mod'
  GONOPROXY=''
  GONOSUMDB=''
  GOOS='linux'
  GOPATH='/home/runner/go'
  GOPRIVATE=''
  GOPROXY='https://proxy.golang.org,direct'
  GOROOT='/opt/hostedtoolcache/go/1.21.4/x64'
  GOSUMDB='sum.golang.org'
  GOTMPDIR=''
  GOTOOLCHAIN='auto'
  GOTOOLDIR='/opt/hostedtoolcache/go/1.21.4/x64/pkg/tool/linux_amd64'
  GOVCS=''
  GOVERSION='go1.21.4'
  GCCGO='gccgo'
  GOAMD64='v1'
  AR='ar'
  CC='gcc'
  CXX='g++'
  CGO_ENABLED='1'
  GOMOD='/dev/null'
  GOWORK=''
  CGO_CFLAGS='-O2 -g'
  CGO_CPPFLAGS=''
  CGO_CXXFLAGS='-O2 -g'
  CGO_FFLAGS='-O2 -g'
  CGO_LDFLAGS='-O2 -g'
  PKG_CONFIG='pkg-config'
  GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build355655332=/tmp/go-build -gno-record-gcc-switches'

If ChristopherHX/gitea-actions-runner uses go, you need to set GOPATH, GOMODCACHE, GOCACHE before it can be used normally.

name: Unit Tests

on:
  pull_request:
    branches:
      - "main"
  push:
    branches:
      - "main"

env:
  GOPATH: /root/go
  GOMODCACHE: /root/go/pkg/mod
  GOCACHE: /root/gocache

jobs:
  testing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '>=1.21.0'

      - name: Test AdService
        run: |
          cd src/adservice
          go vet ./...
          go test -v ./...    

I saw that the default value in github action is GOCACHE='/home/runner/.cache/go-build'. I think GOPATH, GOMODCACHE, GOCACHE should be stored in the same directory as cache of gitea-actions-runner-0.0.3-linux-amd64 by default

root@oilrich25:~/oilrich25/gitea-actions-runner# ls -l
total 22576
drwxr-xr-x 6 git 127 4096 Dec 5 02:10 actions-runner
-rw-r--r-- 1 root root 2576 Dec 5 01:52 actions-runner-worker.ps1
-rw-r--r-- 1 root root 1473 Dec 5 01:52 actions-runner-worker.py
drwxr-xr-x 3 root root 4096 Dec 5 02:10 cache                      //   `cache/go-build` The directory where GOCACHE should be stored by default
-rwxr-xr-x 1 root root 13983744 Dec 4 18:53 gitea-actions-runner-0.0.3-linux-amd64
-rwxr-xr-x 1 root root 0 Dec 5 02:02 gitea-actions-runner-log-error.txt
-rwxr-xr-x 1 root root 9110664 Dec 5 06:22 gitea-actions-runner-log.txt
ChristopherHX commented 11 months ago

If you use actions/runner as a worker

consider adding your env variables to the .env file of the actions/runner root (same folder as config.sh/config.cmd

I think the .env file of gitea-actions-runner is broken here, stripped away so much code after hard forking act_runner.

Support reading env files in gitea-actions-runner and make available to all jobs would make more sense to me than mapping arbitary env variables into a service.

oilrich25 commented 11 months ago

If you use actions/runner as a worker

consider adding your env variables to the .env file of the actions/runner root (same folder as config.sh/config.cmd

I think the .env file of gitea-actions-runner is broken here, stripped away so much code after hard forking act_runner.

Support reading env files in gitea-actions-runner and make available to all jobs would make more sense to me than mapping arbitary env variables into a service.

Is the .env file configured in key=value mode or key: value mode?

ChristopherHX commented 11 months ago

Is the .env file configured in key=value mode or key: value mode?

It's key=value with only single line support

ChristopherHX commented 11 months ago

For example I use such a file ~/actions-runner-v2.283.4/.env

LANG=C.UTF-8
NODE_EXTRA_CA_CERTS=/home/ubuntu/actions-runner-v2.283.4/_work/node.crt
oilrich25 commented 11 months ago

For example I use such a file ~/actions-runner-v2.283.4/.env

LANG=C.UTF-8
NODE_EXTRA_CA_CERTS=/home/ubuntu/actions-runner-v2.283.4/_work/node.crt

I tried setting GOPATH, GOMODCACHE, GOCACHE in .env, but found that it didn't seem to work.

# tree -a . -L 1
.
├── actions-runner
├── actions-runner-worker.ps1
├── actions-runner-worker.py
├── act_runner
├── cache
├── .env
├── gitea-actions-runner-log-error.txt
├── gitea-actions-runner-log.txt
└── .runner

# cat .env 
GOPATH=/root/go
GOMODCACHE=/root/go/pkg/mod
GOCACHE=/root/gocache
##[group]Run actions/setup-go@v3
with:
  go-version: >=1.21.0
  check-latest: false
  cache: false
##[endgroup]
Setup go version spec >=1.21.0
Found in cache @ /root/siba/gitea-actions-runner/actions-runner/_work/_tool/go/1.21.3/x64
Added go to the path
warning: GOPATH set to GOROOT () has no effect
Successfully set up Go version >=1.21.0
warning: GOPATH set to GOROOT () has no effect
go version go1.21.3 linux/amd64
##[group]go env
##[error]Command failed: /root/oilrich25/gitea-actions-runner/actions-runner/_work/_tool/go/1.21.3/x64/bin/go env\nwarning: GOPATH set to GOROOT () has no effect\nbuild cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined\n
warning: GOPATH set to GOROOT () has no effect
build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
ChristopherHX commented 11 months ago

Your .env file is in the wrong folder...

I would expect this layout

# tree -a . -L 1
.
├── actions-runner
        actions-runner/.env
        actions-runner/.runner
        actions-runner/bin/Runner.Worker
        actions-runner/config.sh

├── actions-runner-worker.ps1
├── actions-runner-worker.py
├── act_runner
├── cache
├── gitea-actions-runner-log-error.txt
├── gitea-actions-runner-log.txt
└── .runner

# cat actions-runner/.env
GOPATH=/root/go
GOMODCACHE=/root/go/pkg/mod
GOCACHE=/root/gocache
ChristopherHX commented 11 months ago

Ah I see only actions runner.listener loads the .env file... This won't work in this case

oilrich25 commented 11 months ago

Ah I see only actions runner.listener loads the .env file... This won't work in this case

root@oilrich25:~/oilrich25/gitea-actions-runner# tree -a . -L 2
.
├── actions-runner
│   ├── bin
│   ├── config.sh
│   ├── _diag
│   ├── .env
│   ├── env.sh
│   ├── externals
│   ├── run-helper.cmd.template
│   ├── run-helper.sh.template
│   ├── .runner
│   ├── run.sh
│   ├── safe_sleep.sh
│   └── _work
├── actions-runner-worker.ps1
├── actions-runner-worker.py
├── act_runner
├── cache
│   ├── bolt.db
│   └── cache
├── gitea-actions-runner-log-error.txt
├── gitea-actions-runner-log.txt
└── .runner

7 directories, 15 files
root@oilrich25:~/oilrich25/gitea-actions-runner# cat actions-runner/.env 
GOPATH=/root/go
GOMODCACHE=/root/go/pkg/mod
GOCACHE=/root/gocache
root@oilrich25:~/oilrich25/gitea-actions-runner# ./act_runner svc stop
root@oilrich25:~/oilrich25/gitea-actions-runner# ./act_runner svc start
##[group]Run actions/setup-go@v3
with:
  go-version: >=1.21.0
  check-latest: false
  cache: false
##[endgroup]
Setup go version spec >=1.21.0
Found in cache @ /root/siba/gitea-actions-runner/actions-runner/_work/_tool/go/1.21.3/x64
Added go to the path
warning: GOPATH set to GOROOT () has no effect
Successfully set up Go version >=1.21.0
go version go1.21.3 linux/amd64
warning: GOPATH set to GOROOT () has no effect
##[group]go env
warning: GOPATH set to GOROOT () has no effect
build cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined
##[error]Command failed: /root/oilrich25/gitea-actions-runner/actions-runner/_work/_tool/go/1.21.3/x64/bin/go env\nwarning: GOPATH set to GOROOT () has no effect\nbuild cache is required, but could not be located: GOCACHE is not defined and neither $XDG_CACHE_HOME nor $HOME are defined\n
ChristopherHX commented 11 months ago

The .env file next to the actions_runner.exe should now be loaded https://github.com/ChristopherHX/gitea-actions-runner/commit/08d7044ad1dac40affac164ec3567cd8ebb3a326 probably and allowing to override preset variables like PATH

svc install now shows a hint to add HOME and PATH to the file together with a link to the package documentation for the format.

oilrich25 commented 11 months ago

The .env file next to the actions_runner.exe should now be loaded 08d7044 probably and allowing to override preset variables like PATH

svc install now shows a hint to add HOME and PATH to the file together with a link to the package documentation for the format.

After testing, the problem has been successfully solved.