From 53e26e56b1986ebcd13e668f6f540e612e9c54bd Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 25 Jul 2025 09:44:25 +0000 Subject: [PATCH] fix: sum256 the container name so derivations do not overflow (#191) For instance, the volume name derived from the workflow name may exceed the file system limit when the container name it is derived from is too long. Fixes forgejo/runner#152 Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/191 Reviewed-by: Michael Kriese Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/common/sha256.go | 13 +++++++++++++ act/common/sha256_test.go | 13 +++++++++++++ act/model/workflow.go | 5 +---- act/runner/run_context.go | 2 +- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 act/common/sha256.go create mode 100644 act/common/sha256_test.go diff --git a/act/common/sha256.go b/act/common/sha256.go new file mode 100644 index 00000000..3979e01f --- /dev/null +++ b/act/common/sha256.go @@ -0,0 +1,13 @@ +// Copyright 2025 The Forgejo Authors +// SPDX-License-Identifier: MIT +package common + +import ( + "crypto/sha256" + "encoding/hex" +) + +func Sha256(content string) string { + hashBytes := sha256.Sum256([]byte(content)) + return hex.EncodeToString(hashBytes[:]) +} diff --git a/act/common/sha256_test.go b/act/common/sha256_test.go new file mode 100644 index 00000000..6f20f61a --- /dev/null +++ b/act/common/sha256_test.go @@ -0,0 +1,13 @@ +// Copyright 2025 The Forgejo Authors +// SPDX-License-Identifier: MIT +package common + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestSha256(t *testing.T) { + assert.Equal(t, "3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb", Sha256("something")) +} diff --git a/act/model/workflow.go b/act/model/workflow.go index f4861041..bca11dd0 100644 --- a/act/model/workflow.go +++ b/act/model/workflow.go @@ -1,8 +1,6 @@ package model import ( - "crypto/sha256" - "encoding/hex" "errors" "fmt" "io" @@ -738,8 +736,7 @@ func (s *Step) Type() StepType { } func (s *Step) UsesHash() string { - hashBytes := sha256.Sum256([]byte(s.Uses)) - hashString := hex.EncodeToString(hashBytes[:]) + hashString := common.Sha256(s.Uses) return filepath.Join(hashString[:2], hashString[2:]) } diff --git a/act/runner/run_context.go b/act/runner/run_context.go index a43ec444..f8e8782f 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -94,7 +94,7 @@ func (rc *RunContext) GetEnv() map[string]string { } func (rc *RunContext) jobContainerName() string { - return createSimpleContainerName(rc.Config.ContainerNamePrefix, "WORKFLOW-"+rc.Run.Workflow.Name, "JOB-"+rc.Name) + return createSimpleContainerName(rc.Config.ContainerNamePrefix, "WORKFLOW-"+common.Sha256(rc.Run.Workflow.Name), "JOB-"+rc.Name) } // networkName return the name of the network which will be created by `act` automatically for job,