diff --git a/act/runner/action.go b/act/runner/action.go index 1e41a134..1be16c70 100644 --- a/act/runner/action.go +++ b/act/runner/action.go @@ -429,7 +429,7 @@ func newStepContainer(ctx context.Context, step step, image string, cmd, entrypo Image: image, Username: rc.Config.Secrets["DOCKER_USERNAME"], Password: rc.Config.Secrets["DOCKER_PASSWORD"], - Name: createSimpleContainerName(rc.jobContainerName(), "STEP-"+stepModel.ID), + Name: createContainerName(rc.jobContainerName(), "STEP-"+stepModel.ID), Env: envList, Mounts: mounts, NetworkMode: networkMode, diff --git a/act/runner/run_context.go b/act/runner/run_context.go index 19ad88ef..6db821de 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -101,8 +101,7 @@ func (rc *RunContext) jobContainerName() string { if rc.caller != nil { nameParts = append(nameParts, "CALLED-BY-"+rc.caller.runContext.JobName) } - // return createSimpleContainerName(rc.Config.ContainerNamePrefix, "WORKFLOW-"+rc.Run.Workflow.Name, "JOB-"+rc.Name) - return createSimpleContainerName(nameParts...) // For Gitea + return createContainerName(nameParts...) // For Gitea } // networkNameForGitea return the name of the network @@ -769,7 +768,6 @@ func mergeMaps(maps ...map[string]string) map[string]string { return rtnMap } -// Deprecated: use createSimpleContainerName func createContainerName(parts ...string) string { name := strings.Join(parts, "-") pattern := regexp.MustCompile("[^a-zA-Z0-9]") @@ -783,22 +781,6 @@ func createContainerName(parts ...string) string { return fmt.Sprintf("%s-%x", trimmedName, hash) } -func createSimpleContainerName(parts ...string) string { - pattern := regexp.MustCompile("[^a-zA-Z0-9-]") - name := make([]string, 0, len(parts)) - for _, v := range parts { - v = pattern.ReplaceAllString(v, "-") - v = strings.Trim(v, "-") - for strings.Contains(v, "--") { - v = strings.ReplaceAll(v, "--", "-") - } - if v != "" { - name = append(name, v) - } - } - return strings.Join(name, "_") -} - func trimToLen(s string, l int) string { if l < 0 { l = 0 diff --git a/act/runner/run_context_test.go b/act/runner/run_context_test.go index a1e86597..b4a5dca9 100644 --- a/act/runner/run_context_test.go +++ b/act/runner/run_context_test.go @@ -622,23 +622,16 @@ func TestRunContextGetEnv(t *testing.T) { } } -func Test_createSimpleContainerName(t *testing.T) { - tests := []struct { - parts []string - want string - }{ - { - parts: []string{"a--a", "BBæ­£", "c-C"}, - want: "a-a_BB_c-C", - }, - { - parts: []string{"a-a", "", "-"}, - want: "a-a", - }, - } - for _, tt := range tests { - t.Run(strings.Join(tt.parts, " "), func(t *testing.T) { - assert.Equalf(t, tt.want, createSimpleContainerName(tt.parts...), "createSimpleContainerName(%v)", tt.parts) - }) - } +func TestCreateContainerNameBoundedForLongMatrixInput(t *testing.T) { + longMatrixValue := strings.Repeat("os=ubuntu-latest-go=1.24-node=22-", 20) + name := createContainerName( + "gitea", + "WORKFLOW-super-long-workflow-name", + "JOB-build-matrix-"+longMatrixValue, + ) + + assert.LessOrEqual(t, len(name), 128) + assert.LessOrEqual(t, len(name+"-env"), 255) + assert.LessOrEqual(t, len(name+"-network"), 255) + assert.LessOrEqual(t, len(name+"-job1234567890"), 255) } diff --git a/act/runner/step_docker.go b/act/runner/step_docker.go index 97fc93ec..e17c9c01 100644 --- a/act/runner/step_docker.go +++ b/act/runner/step_docker.go @@ -127,7 +127,7 @@ func (sd *stepDocker) newStepContainer(ctx context.Context, image string, cmd, e Image: image, Username: rc.Config.Secrets["DOCKER_USERNAME"], Password: rc.Config.Secrets["DOCKER_PASSWORD"], - Name: createSimpleContainerName(rc.jobContainerName(), "STEP-"+step.ID), + Name: createContainerName(rc.jobContainerName(), "STEP-"+step.ID), Env: envList, Mounts: mounts, NetworkMode: networkMode,