mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-12 02:44:10 +00:00
fix: keep composite post steps in their own step scope (#1410)
Each composite step's post ran its earlier siblings' posts inside its own step-ID scope, so their log records listed siblings as ancestors, e.g. `outer.results.nodepost` instead of `outer.nodepost`. Every post now gets its own scope. Execution order and run-all-posts behavior are unchanged. Prerequisite for https://gitea.com/gitea/runner/issues/809. _Written by Claude (Opus 5.5)._ Reviewed-on: https://gitea.com/gitea/runner/pulls/1410 Reviewed-by: bircni <[email protected]> Co-authored-by: silverwind <[email protected]>
This commit is contained in:
1 parent
b5305c6785
commit
0dfec377d2
2 files changed
+15
-2
No files matched your search
@@ -217,11 +217,11 @@ func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps {
|
|||||||
steps = append(steps, newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.main()), stepID))
|
steps = append(steps, newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.main()), stepID))
|
||||||
|
|
||||||
// run the post executor in reverse order
|
// run the post executor in reverse order
|
||||||
stepPost := rc.newCompositeCommandExecutor(step.post())
|
stepPost := newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.post()), stepID)
|
||||||
if postExecutor != nil {
|
if postExecutor != nil {
|
||||||
stepPost = stepPost.Finally(postExecutor)
|
stepPost = stepPost.Finally(postExecutor)
|
||||||
}
|
}
|
||||||
postExecutor = newCompositeStepLogExecutor(stepPost, stepID)
|
postExecutor = stepPost
|
||||||
}
|
}
|
||||||
|
|
||||||
steps = append(steps, common.JobError)
|
steps = append(steps, common.JobError)
|
||||||
|
|||||||
@@ -99,6 +99,19 @@ func TestCompositeActionParity(t *testing.T) {
|
|||||||
|
|
||||||
require.ErrorIs(t, rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "nested", Uses: "org/action@v1"}}}}).pre(t.Context()), assert.AnError)
|
require.ErrorIs(t, rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "nested", Uses: "org/action@v1"}}}}).pre(t.Context()), assert.AnError)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("post steps log under their own step ids", func(t *testing.T) {
|
||||||
|
hook := logtest.NewWithLevel(logging.LevelDebug)
|
||||||
|
rc := &RunContext{Config: &Config{}, JobContainer: &jobContainerMock{}}
|
||||||
|
steps := rc.compositeExecutor(&model.Action{Runs: model.ActionRuns{Using: "composite", Steps: []model.Step{{ID: "first", Uses: "./first"}, {ID: "second", Uses: "./second"}}}})
|
||||||
|
require.NoError(t, steps.post(common.WithLogger(t.Context(), logging.New(hook))))
|
||||||
|
var stepIDs []any
|
||||||
|
for _, record := range hook.AllRecords() {
|
||||||
|
ids, _ := record.Attr("stepID")
|
||||||
|
stepIDs = append(stepIDs, ids)
|
||||||
|
}
|
||||||
|
assert.Equal(t, []any{[]string{"second"}, []string{"first"}}, stepIDs)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppendUniqueMasks(t *testing.T) {
|
func TestAppendUniqueMasks(t *testing.T) {
|
||||||
|
|||||||
Reference in new issue
Block a user