mirror of
https://github.com/go-gitea/gitea.git
synced 2026-11-19 15:14:40 +09:00
fix(actions): support concurrency longer than 255 characters (#40392)
`raw_concurrency` on `action_run` and `action_run_job` was `VARCHAR(255)`, so a workflow `concurrency` block longer than 255 bytes failed to insert and no run was created. The column is now `TEXT`. Startup sync widens it on PostgreSQL and MySQL, and migration 370 converts it on MSSQL. The evaluated concurrency group had the same limit, so groups longer than 255 characters are now stored as their SHA-256 hash. Run creation failures also log the workflow and ref. Fixes: https://github.com/go-gitea/gitea/issues/40391 Assisted-by: Claude Code:claude-opus-5-5 --------- Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
1 parent
fbf986d1c7
commit
44e4b6a8d2
8 files changed
+107
-4
No files matched your search
@@ -446,6 +446,7 @@ func prepareMigrationTasks() []*migration {
|
||||
newMigration(367, "Add latest_release_id to repository table", v29.AddLatestReleaseIDToRepository),
|
||||
newMigration(368, "Add unique index for team name", v29.AddUniqueTeamNameIndex),
|
||||
newMigration(369, "Add runner_name to action_task", v29.AddRunnerNameToActionTask),
|
||||
newMigration(370, "Change raw_concurrency of action_run and action_run_job to TEXT on MSSQL", v29.ChangeActionsRawConcurrencyToText),
|
||||
}
|
||||
return preparedMigrations
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v29
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
"gitea.dev/modules/setting"
|
||||
)
|
||||
|
||||
func ChangeActionsRawConcurrencyToText(_ context.Context, x base.EngineMigration) error {
|
||||
if !setting.Database.Type.IsMSSQL() { // startup sync widens VARCHAR to TEXT on MySQL and PostgreSQL
|
||||
return nil
|
||||
}
|
||||
for _, table := range []string{"action_run", "action_run_job"} {
|
||||
if _, err := x.Exec("ALTER TABLE " + table + " ALTER COLUMN raw_concurrency NVARCHAR(MAX) NULL"); err != nil {
|
||||
return fmt.Errorf("ChangeActionsRawConcurrencyToText: %s: %w", table, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v29
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
"gitea.dev/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestChangeActionsRawConcurrencyToText(t *testing.T) {
|
||||
if !setting.Database.Type.IsMSSQL() {
|
||||
t.Skip("Only MSSQL needs a migration to widen raw_concurrency")
|
||||
}
|
||||
|
||||
type ActionRun struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RawConcurrency string
|
||||
}
|
||||
type ActionRunJob struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
RawConcurrency string
|
||||
}
|
||||
|
||||
x, deferrable := migrationtest.PrepareTestEnv(t, 0, new(ActionRun), new(ActionRunJob))
|
||||
defer deferrable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
require.NoError(t, ChangeActionsRawConcurrencyToText(t.Context(), x))
|
||||
|
||||
long := strings.Repeat("界", 1000)
|
||||
run := &ActionRun{RawConcurrency: long}
|
||||
job := &ActionRunJob{RawConcurrency: long}
|
||||
_, err := x.Insert(run, job)
|
||||
require.NoError(t, err)
|
||||
|
||||
gotRun, gotJob := &ActionRun{ID: run.ID}, &ActionRunJob{ID: job.ID}
|
||||
_, err = x.Get(gotRun)
|
||||
require.NoError(t, err)
|
||||
_, err = x.Get(gotJob)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, long, gotRun.RawConcurrency)
|
||||
assert.Equal(t, long, gotJob.RawConcurrency)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ type ActionRun struct {
|
||||
TriggerEvent string // the trigger event defined in the `on` configuration of the triggered workflow
|
||||
Status Status `xorm:"index index(repo_status)"`
|
||||
Version int `xorm:"version default 0"` // Status could be updated concomitantly, so an optimistic lock is needed
|
||||
RawConcurrency string // raw concurrency
|
||||
RawConcurrency string `xorm:"TEXT"` // raw concurrency
|
||||
|
||||
// WorkflowRepoID/WorkflowCommitSHA record the (repo, commit) the run's workflow file content came from.
|
||||
// Always filled (repo-level run = the repo itself; scoped run = the source repo).
|
||||
|
||||
@@ -56,7 +56,7 @@ type ActionRunJob struct {
|
||||
|
||||
Status Status `xorm:"index index(pickup) index(repo_status)"`
|
||||
|
||||
RawConcurrency string // raw concurrency from job YAML's "concurrency" section
|
||||
RawConcurrency string `xorm:"TEXT"` // raw concurrency from job YAML's "concurrency" section
|
||||
|
||||
// IsConcurrencyEvaluated is only valid/needed when this job's RawConcurrency is not empty.
|
||||
// If RawConcurrency can't be evaluated (e.g. depend on other job's outputs or have errors), this field will be false.
|
||||
|
||||
@@ -6,10 +6,12 @@ package actions
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"unicode/utf8"
|
||||
|
||||
act_model "gitea.dev/actionslib/pkg/model"
|
||||
actions_model "gitea.dev/models/actions"
|
||||
"gitea.dev/modules/actions/jobparser"
|
||||
"gitea.dev/modules/base"
|
||||
"gitea.dev/modules/setting"
|
||||
"gitea.dev/modules/util"
|
||||
webhook_module "gitea.dev/modules/webhook"
|
||||
@@ -41,6 +43,7 @@ func EvaluateRunConcurrencyFillModel(ctx context.Context, run *actions_model.Act
|
||||
if err != nil {
|
||||
return fmt.Errorf("evaluate concurrency: %w", err)
|
||||
}
|
||||
attempt.ConcurrencyGroup = boundedConcurrencyGroup(attempt.ConcurrencyGroup)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -83,6 +86,14 @@ func EvaluateJobConcurrencyFillModel(ctx context.Context, run *actions_model.Act
|
||||
if err != nil {
|
||||
return util.NewInvalidArgumentErrorf("%v", err)
|
||||
}
|
||||
actionRunJob.ConcurrencyGroup = boundedConcurrencyGroup(actionRunJob.ConcurrencyGroup)
|
||||
actionRunJob.IsConcurrencyEvaluated = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func boundedConcurrencyGroup(group string) string {
|
||||
if utf8.RuneCountInString(group) > 255 {
|
||||
return base.EncodeSha256(group)
|
||||
}
|
||||
return group
|
||||
}
|
||||
@@ -5,7 +5,9 @@ package actions
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode/utf8"
|
||||
|
||||
act_model "gitea.dev/actionslib/pkg/model"
|
||||
actions_model "gitea.dev/models/actions"
|
||||
@@ -49,6 +51,19 @@ func TestEvaluateRunConcurrency_RunIDFallback(t *testing.T) {
|
||||
assert.Contains(t, attemptA.ConcurrencyGroup, "791")
|
||||
assert.Contains(t, attemptB.ConcurrencyGroup, "792")
|
||||
assert.NotEqual(t, attemptA.ConcurrencyGroup, attemptB.ConcurrencyGroup)
|
||||
|
||||
t.Run("preserves 255 runes and bounds longer groups", func(t *testing.T) {
|
||||
evaluateGroup := func(group string) string {
|
||||
require.NoError(t, EvaluateRunConcurrencyFillModel(ctx, runA, attemptA, &act_model.RawConcurrency{Group: group}, nil, nil))
|
||||
return attemptA.ConcurrencyGroup
|
||||
}
|
||||
group := strings.Repeat("界", 255)
|
||||
assert.Equal(t, group, evaluateGroup(group))
|
||||
boundedGroup := evaluateGroup(group + "a")
|
||||
assert.LessOrEqual(t, utf8.RuneCountInString(boundedGroup), 255)
|
||||
assert.Equal(t, boundedGroup, evaluateGroup(group+"a"))
|
||||
assert.NotEqual(t, boundedGroup, evaluateGroup(group+"b"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrepareRunAndInsert_ExpressionsSeeRunID(t *testing.T) {
|
||||
|
||||
@@ -396,7 +396,7 @@ func handleWorkflows(
|
||||
for _, dwf := range detectedWorkflows {
|
||||
// repo-level run: the workflow content is this repo at dwf.SourceCommitSHA
|
||||
if err := buildApproveAndInsertRun(ctx, input, ref, commit, payload, isForkPullRequest, dwf, input.Repo.ID, false); err != nil {
|
||||
log.Error("repo %s: %v", input.Repo.FullName(), err)
|
||||
log.Error("repo %s workflow %s ref %s: %v", input.Repo.FullName(), dwf.EntryName, ref, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -816,7 +816,7 @@ func detectAndHandleScopedWorkflows(
|
||||
}
|
||||
|
||||
if err := buildApproveAndInsertRun(ctx, input, ref, consumerCommit, payload, isForkPullRequest, dwf, sourceRepo.ID, true); err != nil {
|
||||
log.Error("scoped workflows: source %s workflow %s: %v", sourceRepo.FullName(), dwf.EntryName, err)
|
||||
log.Error("scoped workflows: source %s workflow %s for consumer %s ref %s: %v", sourceRepo.FullName(), dwf.EntryName, input.Repo.FullName(), ref, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user