Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GITHUB_* variables are empty #2418

Open
AndesKrrrrrrrrrrr opened this issue Aug 7, 2024 · 3 comments
Open

GITHUB_* variables are empty #2418

AndesKrrrrrrrrrrr opened this issue Aug 7, 2024 · 3 comments
Labels
kind/bug Something isn't working

Comments

@AndesKrrrrrrrrrrr
Copy link
Contributor

Bug report info

act version:            0.2.65
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 16
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	$XDG_RUNTIME_DIR/podman/podman.sock
Config files:           
	/var/home/person/.config/act/actrc:
		-P ubuntu-latest=catthehacker/ubuntu:act-latest
		-P ubuntu-22.04=catthehacker/ubuntu:act-22.04
		-P ubuntu-20.04=catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.22.5
	Module path:           command-line-arguments
	Main version:          
	Main path:             
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.65
		DefaultGODEBUG:       httplaxcontentlength=1,httpmuxgo121=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 linux
		GOAMD64:              v1

Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Command used with act

act push -W .github/workflows/empty-env.yml

Describe issue

Some GITHUB_*_REF variables are empty, even though Act claims on its front page to provide these variables.

These are empty:

GITHUB_REF_TYPE=          
GITHUB_ACTION_PATH=       
GITHUB_ACTION_REPOSITORY= 
GITHUB_BASE_REF=          
GITHUB_HEAD_REF=          
GITHUB_ACTION_REF=        

Link to GitHub repository

https://github.com/AndesKrrrrrrrrrrr/act-MWE/tree/main

Workflow content

name: Empty env MWE

on:
  pull_request: {}
  push: {}

jobs:
  prepare:
    runs-on: ubuntu-latest
    steps:
      - run: |
          set -x
          env | grep "^GITHUB_"
      - run: |
          set -euxo pipefail
          [[ -n "$GITHUB_HEAD_REF" ]] &&
          [[ -n "$GITHUB_BASE_REF" ]] &&
          [[ -n "$GITHUB_SHA" ]] &&
          true

Relevant log output

INFO[0000] Using docker host 'unix:///run/user/1000/podman/podman.sock', and daemon socket 'unix:///run/user/1000/podman/podman.sock' 
[Empty env MWE/prepare] 🚀  Start image=catthehacker/ubuntu:act-latest
[Empty env MWE/prepare]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Empty env MWE/prepare]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Empty env MWE/prepare]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Empty env MWE/prepare]   🐳  docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[Empty env MWE/prepare] ⭐ Run Main set -x
env | grep "^GITHUB_"
[Empty env MWE/prepare]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/0] user= workdir=
| + env
| + grep '^GITHUB_'
| GITHUB_WORKSPACE=/var/home/person/work/act-MWE
| GITHUB_PATH=/var/run/act/workflow/pathcmd.txt
| GITHUB_ACTION=0
| GITHUB_RUN_NUMBER=1
| GITHUB_REF_TYPE=
| GITHUB_ACTIONS=true
| GITHUB_SHA=a5d48eb18b2b0aeeb31487335ac644aa69d689c3
| GITHUB_REF=refs/pull/%!f(<nil>)/merge
| GITHUB_API_URL=https://api.github.com
| GITHUB_STATE=/var/run/act/workflow/statecmd.txt
| GITHUB_ENV=/var/run/act/workflow/envs.txt
| GITHUB_EVENT_PATH=/var/run/act/workflow/event.json
| GITHUB_EVENT_NAME=pull_request
| GITHUB_RUN_ID=1
| GITHUB_STEP_SUMMARY=/var/run/act/workflow/SUMMARY.md
| GITHUB_ACTOR=nektos/act
| GITHUB_GRAPHQL_URL=https://api.github.com/graphql
| GITHUB_ACTION_PATH=
| GITHUB_SERVER_URL=https://github.com
| GITHUB_REF_NAME=%!f(<nil>)/merge
| GITHUB_JOB=prepare
| GITHUB_REPOSITORY=AndesKrrrrrrrrrrr/act-MWE
| GITHUB_RETENTION_DAYS=0
| GITHUB_ACTION_REPOSITORY=
| GITHUB_BASE_REF=
| GITHUB_REPOSITORY_OWNER=AndesKrrrrrrrrrrr
| GITHUB_HEAD_REF=
| GITHUB_ACTION_REF=
| GITHUB_WORKFLOW=Empty env MWE
| GITHUB_OUTPUT=/var/run/act/workflow/outputcmd.txt
[Empty env MWE/prepare]   ✅  Success - Main set -x
env | grep "^GITHUB_"
[Empty env MWE/prepare] ⭐ Run Main set -euxo pipefail
[[ -n "$GITHUB_HEAD_REF" ]] &&
[[ -n "$GITHUB_BASE_REF" ]] &&
[[ -n "$GITHUB_SHA" ]] &&
true
[Empty env MWE/prepare]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
| + [[ -n '' ]]
[Empty env MWE/prepare]   ❌  Failure - Main set -euxo pipefail
[[ -n "$GITHUB_HEAD_REF" ]] &&
[[ -n "$GITHUB_BASE_REF" ]] &&
[[ -n "$GITHUB_SHA" ]] &&
true
[Empty env MWE/prepare] exitcode '1': failure
[Empty env MWE/prepare] 🏁  Job failed
Error: Job 'prepare' failed

Additional information

No response

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr added the kind/bug Something isn't working label Aug 7, 2024
@ChristopherHX
Copy link
Contributor

..........

GITHUB_ACTION_PATH=
GITHUB_ACTION_REPOSITORY
GITHUB_ACTION_REF=

Those are empty as run is not an action, please check this against actions/runner

GITHUB_BASE_REF=
GITHUB_HEAD_REF=

act pull_request exclusive if -e provides specfic pr webhook keys
please check against actions/runner when your job runs via push

Do you have some suggestion to get the values? I believe we have documented how the event.json must look like, but that could be invalid didn't verify

GITHUB_REF_TYPE=

What is expected here for refs/pull ? I remember that was undefined while the code has been written and empty was correct

@AndesKrrrrrrrrrrr
Copy link
Contributor Author

GITHUB_ACTION_PATH=
GITHUB_ACTION_REPOSITORY
GITHUB_ACTION_REF=

Those are empty as run is not an action, please check this against actions/runner

Yeah, that makes sense. For now, I don't care about these anyways.

GITHUB_BASE_REF=
GITHUB_HEAD_REF=

act pull_request exclusive if -e provides specfic pr webhook keys please check against actions/runner when your job runs via push

What do you mean by this (act pull_request exclusive)?

Do you have some suggestion to get the values? I believe we have documented how the event.json must look like, but that could be invalid didn't verify

We can gather these independent of Github, since we know the base branch, and the current branch. We can set GITHUB_BASE_REF to the argument of --defaultbranch or create a new flag --basebranch (defaulting to --basebranch). GITHUB_HEAD_REF can be gathered from git as either the current branch name, or the current commit hash.

GITHUB_REF_TYPE=

What is expected here for refs/pull ? I remember that was undefined while the code has been written and empty was correct

From the docs, though, I've never used it myself or seen it used 🤷

The type of ref that triggered the workflow run. Valid values are branch or tag.

@ChristopherHX
Copy link
Contributor

From the docs, though, I've never used it myself or seen it used 🤷

The type of ref that triggered the workflow run. Valid values are branch or tag

Yes, that is for refs/tag/ and refs/heads/, but we are writing about refs/pull/.
For branch and tag it is implemented.
Stll this has been empty on GH at one point of time for PR's (no push, no anything else), I don't verify such information periodically.

What do you mean by this (act pull_request exclusive)?

The trigger event name is checked:
Tbh, this looks like to miss pull_request_review and so on

func (ghc *GithubContext) SetBaseAndHeadRef() {

act push never set's the value from event.json, but I think you don't provide such a file.

To set the value currently just do

act --env GITHUB_HEAD_REF=pr --env GITHUB_BASE_REF=main that has no event name filter. But then github.event doesn't mirror the value in the wenhook structure

BaseRef: rc.Config.Env["GITHUB_BASE_REF"],

we know the base branch

I don't know it, I would need to guess it. A sha might be an unexpected value here

Not every PR goes to default branch, only most.

As a default fallback it's ok, you can make a pr, but please only for events contain pull_request in their name

GITHUB_HEAD_REF can be gathered from git as either the current branch name, or the current commit hash.

As a default fallback it's ok, you can make a pr, but please only for events contain pull_request in their name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants