Skip to content

Leading / in path segment of remote causes incorrect GITHUB_REPOSITORY & GITHUB_REPOSITORY_OWNER #5949

@sh41

Description

@sh41

Bug report info

act version:            0.2.82
GOOS:                   linux
GOARCH:                 amd64
NumCPU:                 16
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
Config files:           
	/home/steve/.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.24.0
	Module path:           github.com/nektos/act
	Main version:          v0.2.82+dirty
	Main path:             github.com/nektos/act
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-trimpath:            true
		CGO_ENABLED:          0
		GOARCH:               amd64
		GOOS:                 linux
		GOAMD64:              v1
		vcs:                  git
		vcs.revision:         5668308bac0d256c8a4c3aa1467d2ebcb55bc717
		vcs.time:             2025-02-01T14:37:09Z
		vcs.modified:         true
Docker Engine:
	Engine version:        28.5.1
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         cgroupfs
	Storage driver:        overlayfs
	Registry URI:          https://index.docker.io/v1/
	OS:                    Docker Desktop
	OS type:               linux
	OS version:            
	OS arch:               x86_64
	OS kernel:             6.6.87.2-microsoft-standard-WSL2
	OS CPU:                16
	OS memory:             32096 MB
	Security options:
		name=seccomp,profile=builtin
		name=cgroupns

Command used with act

gh act -W print_context.yml  -j print-context-and-exit

Describe issue

git@github.com:/sh41/act.git is a valid remote in git, but it is not parsed correctly by act. See https://stackoverflow.com/a/70330178 for a discussion of the origins of this syntax.

In the log output you can see:

| GITHUB_REPOSITORY=/sh41/act
| GITHUB_REPOSITORY_OWNER=

which should be:

| GITHUB_REPOSITORY=act
| GITHUB_REPOSITORY_OWNER=sh41

Link to GitHub repository

No response

Workflow content

name: Print Context

on: [push]

jobs:
  print-context-and-exit:
    runs-on: ubuntu-latest
    steps:
      - name: Print the entire GitHub context
        run: |
          echo "GITHUB CONTEXT:"
          echo "${{ toJSON(github) }}"
          echo "ENV VARS:"
          printenv | sort | grep GITHUB_REPO
      - name: End job after printing context
        run: exit 0

Relevant log output

➜  act git:(master) ✗ git remote -v
origin  git@github.com:/sh41/act.git (fetch)
origin  git@github.com:/sh41/act.git (push)
➜  act git:(master) ✗                      
➜  act git:(master) ✗ gh act -W print_context.yml  -j print-context-and-exit
INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock' 
[Print Context/print-context-and-exit] ⭐ Run Set up job
[Print Context/print-context-and-exit] 🚀  Start image=catthehacker/ubuntu:act-latest
[Print Context/print-context-and-exit]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Print Context/print-context-and-exit]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Print Context/print-context-and-exit]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[Print Context/print-context-and-exit]   🐳  docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[Print Context/print-context-and-exit]   ✅  Success - Set up job
[Print Context/print-context-and-exit] ⭐ Run Main Print the entire GitHub context
[Print Context/print-context-and-exit]   🐳  docker exec cmd=[bash -e /var/run/act/workflow/0] user= workdir=
| GITHUB CONTEXT:
| {
|   event: {
|     repository: {
|       default_branch: master
|     }
|   },
|   event_path: /var/run/act/workflow/event.json,
|   workflow: Print Context,
|   run_attempt: 1,
|   run_id: 1,
|   run_number: 1,
|   actor: nektos/act,
|   repository: /sh41/act,
|   event_name: push,
|   sha: 3d71542867d7cbdac6a75e540be6f64362e94de2,
|   ref: refs/heads/master,
|   ref_name: master,
|   ref_type: branch,
|   head_ref: ,
|   base_ref: ,
|   token: ***,
|   workspace: /home/steve/dev/act,
|   action: 0,
|   action_path: ,
|   action_ref: ,
|   action_repository: ,
|   job: print-context-and-exit,
|   job_name: ,
|   repository_owner: ,
|   retention_days: 0,
|   runner_perflog: /dev/null,
|   runner_tracking_id: ,
|   server_url: https://github.com,
|   api_url: https://api.github.com,
|   graphql_url: https://api.github.com/graphql
| }
| ENV VARS:
| GITHUB_REPOSITORY=/sh41/act
| GITHUB_REPOSITORY_OWNER=
[Print Context/print-context-and-exit]   ✅  Success - Main Print the entire GitHub context [140.657448ms]
[Print Context/print-context-and-exit] ⭐ Run Main End job after printing context
[Print Context/print-context-and-exit]   🐳  docker exec cmd=[bash -e /var/run/act/workflow/1] user= workdir=
[Print Context/print-context-and-exit]   ✅  Success - Main End job after printing context [120.691553ms]
[Print Context/print-context-and-exit] ⭐ Run Complete job
[Print Context/print-context-and-exit] Cleaning up container for job print-context-and-exit
[Print Context/print-context-and-exit]   ✅  Success - Complete job
[Print Context/print-context-and-exit] 🏁  Job succeeded

Additional information

I think this can be fixed by changing this line:
https://github.com/nektos/act/blame/3d71542867d7cbdac6a75e540be6f64362e94de2/pkg/common/git/git.go#L29

to:

	githubSSHRegex      = regexp.MustCompile(`github.com(?::/?|/)(.+)/(.+?)(?:.git)?$`)

and for GHE:
https://github.com/nektos/act/blame/3d71542867d7cbdac6a75e540be6f64362e94de2/pkg/common/git/git.go#L212
to

		gheSSHRegex := regexp.MustCompile(fmt.Sprintf(`%s(?::/?|/)/(.+?)(?:.git)?$`, githubInstance))

In both cases

[:/] = either a : or a /
is replaced by:
(?::/?|/) = non-capturing group of either a : optionally followed by a / OR just / on it's own.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions