Skip to content

Commit cbc9a0f

Browse files
authored
Avoid too long names for actions (#23162)
The name of the job or step comes from the workflow file, while the name of the runner comes from its registration. If the strings used for these names are too long, they could cause db issues.
1 parent 067b0c2 commit cbc9a0f

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

models/actions/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ func InsertRun(ctx context.Context, run *ActionRun, jobs []*jobparser.SingleWork
192192
if len(needs) > 0 || run.NeedApproval {
193193
status = StatusBlocked
194194
}
195+
job.Name, _ = util.SplitStringAtByteN(job.Name, 255)
195196
runJobs = append(runJobs, &ActionRunJob{
196197
RunID: run.ID,
197198
RepoID: run.RepoID,

models/actions/task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,9 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
298298
if len(workflowJob.Steps) > 0 {
299299
steps := make([]*ActionTaskStep, len(workflowJob.Steps))
300300
for i, v := range workflowJob.Steps {
301+
name, _ := util.SplitStringAtByteN(v.String(), 255)
301302
steps[i] = &ActionTaskStep{
302-
Name: v.String(),
303+
Name: name,
303304
TaskID: task.ID,
304305
Index: int64(i),
305306
RepoID: task.RepoID,

routers/api/actions/runner/runner.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"code.gitea.io/gitea/modules/actions"
1313
"code.gitea.io/gitea/modules/json"
1414
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/util"
1516
actions_service "code.gitea.io/gitea/services/actions"
1617

1718
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
@@ -55,9 +56,10 @@ func (s *Service) Register(
5556
}
5657

5758
// create new runner
59+
name, _ := util.SplitStringAtByteN(req.Msg.Name, 255)
5860
runner := &actions_model.ActionRunner{
5961
UUID: gouuid.New().String(),
60-
Name: req.Msg.Name,
62+
Name: name,
6163
OwnerID: runnerToken.OwnerID,
6264
RepoID: runnerToken.RepoID,
6365
AgentLabels: req.Msg.AgentLabels,

0 commit comments

Comments
 (0)