Repository: nektos/act (language: go)

Issue:
act does not create separate containers for matrix builds with reusable workflows
### Bug report info

```plain text
act version:            0.2.50
GOOS:                   darwin
GOARCH:                 amd64
NumCPU:                 8
Docker host:            DOCKER_HOST environment variable is not set
Sockets found:
	/var/run/docker.sock
	$HOME/.docker/run/docker.sock
Config files:           
	/Users/andy/.actrc:
		-P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
		-P ubuntu-20.04=ghcr.io/catthehacker/ubuntu:act-20.04
		-P ubuntu-18.04=ghcr.io/catthehacker/ubuntu:act-18.04
Build info:
	Go version:            go1.21.0
	Module path:           command-line-arguments
	Main version:          
	Main path:             
	Main checksum:         
	Build settings:
		-buildmode:           exe
		-compiler:            gc
		-ldflags:             -X main.version=0.2.50
		DefaultGODEBUG:       panicnil=1
		CGO_ENABLED:          1
		CGO_CFLAGS:           
		CGO_CPPFLAGS:         
		CGO_CXXFLAGS:         
		CGO_LDFLAGS:          
		GOARCH:               amd64
		GOOS:                 darwin
		GOAMD64:              v1
Docker Engine:
	Engine version:        24.0.5
	Engine runtime:        runc
	Cgroup version:        2
	Cgroup driver:         cgroupfs
	Storage driver:        overlay2
	Registry URI:          https://index.docker.io/v1/
	OS:                    Docker Desktop
	OS type:               linux
	OS version:            
	OS arch:               x86_64
	OS kernel:             5.15.49-linuxkit-pr
	OS CPU:                4
	OS memory:             7859 MB
	Security options:
		name=seccomp,profile=unconfined
		name=cgroupns
```


### Command used with act

```sh
act -j call-reusable-workflow
```


### Describe issue

When using act with reusable workflows called with a matrix strategy, act does not create separate docker containers for each matrix combination; it tries to run them all in the same container which generates an error (see log output below). 

If I run the same matrix strategy in a standalone workflow, act creates a separate docker container for each matrix combination and the workflow runs successfully.

### Link to GitHub repository

https://github.com/Andy4495/act-workflow-test

### Workflow content

```yml
# The "caller" workflow
name: Call Reusable Workflow

on: 
  push:
  workflow_dispatch:

jobs:
  call-reusable-workflow: 
    strategy:
      matrix:
        include:
          - message: test1
          - message: test2
          - message: test3
          - message: test4
 
    name: call-reusable-workflow
    uses: Andy4495/act-workflow-test/.github/workflows/reusable-flow.yml@main
    with:
      message: ${{ matrix.message }}

---

# The "called" (reusable) workflow
name: reusable-workflow

on: 
  workflow_call:
    inputs:
      message:
        description: Message to display
        required: true
        type: string

jobs:
  reusable-workflow: 
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Print the message
        run: |
          echo Test reusable workflow ${{ inputs.message }}
```


### Relevant log output

```sh
Error: failed to create container: 'Error response from daemon: Conflict. The container name "/act-call-reusable-workflow-reusable-workflow-reusable-workflow-c7535ef5a84abfd1f2412cceca72bd226072ccb44b16a59787972320d9cb1a2d" is already in use by container "d0baad951ea56daf6bd3097af098d08b22d726733e0e4a54120fe40c357874a0". You have to remove (or rename) that container to be able to reuse that name.'
```


### Additional information

As mentioned above, this works fine with standalone workflows.


Discussion / hints:
I found the problem and it looks like the fix is pretty simple.

The container name generated for reusable workflows is not unique, so each matrix run was trying to use the same container. The code was using the non-unique caller job name instead of the unique name (with the -1, -2, ...  appended). 

So the fix should be in `runner/run_context.go` function `String()`. 

Change this: 

    name = fmt.Sprintf("%s/%s", rc.caller.runContext.Run.JobID, name)

To this:

    name = fmt.Sprintf("%s/%s", rc.caller.runContext.Name, name)

I'll open a pull request after I run a few more tests.


Fix patch:
diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go
index 70d2f8f489d..a69abc6e224 100644
--- a/pkg/runner/run_context.go
+++ b/pkg/runner/run_context.go
@@ -64,7 +64,7 @@ func (rc *RunContext) String() string {
 	if rc.caller != nil {
 		// prefix the reusable workflow with the caller job
 		// this is required to create unique container names
-		name = fmt.Sprintf("%s/%s", rc.caller.runContext.Run.JobID, name)
+		name = fmt.Sprintf("%s/%s", rc.caller.runContext.Name, name)
 	}
 	return name
 }


Test patch: