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:
silverwind authored and bircni committed 2026-11-11 19:31:21 +00:00
1 parent b5305c6785
commit 0dfec377d2
2 files changed
+15 -2

No files matched your search

+2 -2
View File
@@ -217,11 +217,11 @@ func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps {
steps = append(steps, newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.main()), stepID))
// run the post executor in reverse order
stepPost := rc.newCompositeCommandExecutor(step.post())
stepPost := newCompositeStepLogExecutor(rc.newCompositeCommandExecutor(step.post()), stepID)
if postExecutor != nil {
stepPost = stepPost.Finally(postExecutor)
}
postExecutor = newCompositeStepLogExecutor(stepPost, stepID)
postExecutor = stepPost
}
steps = append(steps, common.JobError)
+13
View File
@@ -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)
})
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) {