mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-07 15:50:28 +00:00
fix: restore the caller's event and inputs in reusable workflow jobs (#1250)
Fixes https://github.com/go-gitea/gitea/issues/38705 Gitea side: https://github.com/go-gitea/gitea/pull/39452 Jobs of a called workflow currently see `gitea.event_name == "workflow_call"`, and their `gitea.event.inputs` is replaced by the caller's `with:`. On GitHub they keep the caller's event, and their `inputs` are the run's `workflow_dispatch` inputs overlaid with the caller's `with:`. For compatibility with older runners, Gitea keeps sending that form and adds a `gitea_workflow_call` key with the original trigger event name and inputs of the run, and the `inputs` Gitea resolved for the job. When the key is present, the runner restores `gitea.event_name` and `gitea.event.inputs` from it, and uses the resolved `inputs` for the job's expressions and the setup log. Without that key (older Gitea, or jobs outside called workflows), nothing changes. Reviewed-on: https://gitea.com/gitea/runner/pulls/1250 Reviewed-by: bircni <[email protected]> Reviewed-by: silverwind <[email protected]> Co-authored-by: Zettat123 <[email protected]>
This commit is contained in:
1 parent
81add27459
commit
990ebaa2ac
6 files changed
+104
-2
No files matched your search
@@ -358,3 +358,48 @@ func TestNewRunnerCacheServiceV2(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRestoreCalledWorkflowContext(t *testing.T) {
|
||||
newTask := func(workflowCall map[string]any) *runnerv1.Task {
|
||||
values := map[string]any{
|
||||
"event_name": "workflow_call",
|
||||
"event": map[string]any{"ref": "refs/heads/main", "inputs": map[string]any{"env": "leaf"}},
|
||||
}
|
||||
if workflowCall != nil {
|
||||
values["gitea_workflow_call"] = workflowCall
|
||||
}
|
||||
taskCtx, err := structpb.NewStruct(values)
|
||||
require.NoError(t, err)
|
||||
return &runnerv1.Task{Context: taskCtx}
|
||||
}
|
||||
|
||||
t.Run("dispatched run", func(t *testing.T) {
|
||||
task := newTask(map[string]any{
|
||||
"original_event_name": "workflow_dispatch",
|
||||
"original_event_inputs": map[string]any{"target": "prod"},
|
||||
"inputs": map[string]any{"target": "prod", "env": "leaf"},
|
||||
})
|
||||
assert.Equal(t, map[string]any{"target": "prod", "env": "leaf"}, restoreCalledWorkflowContext(task))
|
||||
taskCtx := task.Context.AsMap()
|
||||
assert.Equal(t, "workflow_dispatch", taskCtx["event_name"])
|
||||
assert.Equal(t, map[string]any{"ref": "refs/heads/main", "inputs": map[string]any{"target": "prod"}}, taskCtx["event"])
|
||||
assert.Equal(t, []string{"::group::Inputs", "env: leaf", "target: prod", "::endgroup::"}, inputLines(task.Context.Fields))
|
||||
})
|
||||
|
||||
t.Run("event without inputs", func(t *testing.T) {
|
||||
task := newTask(map[string]any{
|
||||
"original_event_name": "push",
|
||||
"inputs": map[string]any{"env": "leaf"},
|
||||
})
|
||||
assert.Equal(t, map[string]any{"env": "leaf"}, restoreCalledWorkflowContext(task))
|
||||
taskCtx := task.Context.AsMap()
|
||||
assert.Equal(t, "push", taskCtx["event_name"])
|
||||
assert.Equal(t, map[string]any{"ref": "refs/heads/main"}, taskCtx["event"])
|
||||
})
|
||||
|
||||
t.Run("not a called workflow's job", func(t *testing.T) {
|
||||
task := newTask(nil)
|
||||
assert.Nil(t, restoreCalledWorkflowContext(task))
|
||||
assert.Equal(t, "workflow_call", task.Context.AsMap()["event_name"])
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user