mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-03 08:45:33 +02:00
fix: Adjust the jobparser and the matrix part
This commit is contained in:
1 parent
cfcb78a948
commit
9c8c05eb2e
2 files changed
+32
-1
No files matched your search
@@ -9,9 +9,10 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
|
||||||
"gitea.com/gitea/runner/act/exprparser"
|
"gitea.com/gitea/runner/act/exprparser"
|
||||||
"gitea.com/gitea/runner/act/model"
|
"gitea.com/gitea/runner/act/model"
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"go.yaml.in/yaml/v4"
|
"go.yaml.in/yaml/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"maps"
|
"maps"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -349,6 +350,35 @@ func constructWorkflowWithNeeds(job *actions_model.ActionRunJob, taskNeeds map[s
|
|||||||
// Add the actual job we want to expand (with matrix and needs)
|
// Add the actual job we want to expand (with matrix and needs)
|
||||||
maps.Copy(newJobs, jobsSection)
|
maps.Copy(newJobs, jobsSection)
|
||||||
|
|
||||||
|
// The WorkflowPayload may contain a normalised/wrapped matrix (e.g.
|
||||||
|
// version: ["${{ fromJson(...) }}"]). Restore the original scalar expression
|
||||||
|
// from RawStrategy so jobparser.Parse() can expand it correctly with job outputs.
|
||||||
|
// Also drop the pre-baked "name" so jobparser regenerates it per matrix combination
|
||||||
|
// (e.g. "build (1)", "build (2)", …) instead of "build (Array)".
|
||||||
|
// Critically, re-add "needs" because EraseNeeds() removed them from WorkflowPayload:
|
||||||
|
// without needs, NewInterpeter builds an empty Needs context and
|
||||||
|
// "needs.generate.outputs.*" expressions can never be evaluated.
|
||||||
|
if targetJobDef, ok := newJobs[job.JobID]; ok {
|
||||||
|
if targetJobMap, ok := targetJobDef.(map[string]any); ok {
|
||||||
|
delete(targetJobMap, "name")
|
||||||
|
// Restore needs from taskNeeds keys so the expression evaluator
|
||||||
|
// can resolve needs.<jobID>.outputs.* references.
|
||||||
|
needsKeys := make([]string, 0, len(taskNeeds))
|
||||||
|
for needJobID := range taskNeeds {
|
||||||
|
needsKeys = append(needsKeys, needJobID)
|
||||||
|
}
|
||||||
|
sort.Strings(needsKeys)
|
||||||
|
targetJobMap["needs"] = needsKeys
|
||||||
|
if job.RawStrategy != "" {
|
||||||
|
var rawStrategyMap map[string]any
|
||||||
|
if err := yaml.Unmarshal([]byte(job.RawStrategy), &rawStrategyMap); err == nil {
|
||||||
|
targetJobMap["strategy"] = rawStrategyMap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newJobs[job.JobID] = targetJobMap
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Construct the full workflow
|
// Construct the full workflow
|
||||||
workflow := map[string]any{
|
workflow := map[string]any{
|
||||||
"name": "matrix-expansion",
|
"name": "matrix-expansion",
|
||||||
|
|||||||
Reference in new issue
Block a user