mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-30 19:22:09 +00:00
feat: support evaluating workflow-level concurrency blocks in jobparser (#1026)
- Changes `EvaluateConcurrency` to `EvaluateWorkflowConcurrency`, which has no job-related arguments - Changes gitContext to be sent as an object rather than a map - Allows `nil` to be returned for `cancelInProgress`, which indicates that the value wasn't specified in the input yaml -- required for distinguishing the `cancel-in-progress: false` case from not being specified at all. ReadWorkflowRawConcurrency & EvaluateWorkflowConcurrency were never used in forgejo yet, so this shouldn't break the forgejo build. Prerequisite for https://codeberg.org/forgejo/forgejo/pulls/9434. <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/1026): <!--number 1026 --><!--line 0 --><!--description ZmVhdDogc3VwcG9ydCBldmFsdWF0aW5nIHdvcmtmbG93LWxldmVsIGNvbmN1cnJlbmN5IGJsb2NrcyBpbiBqb2JwYXJzZXI=-->feat: support evaluating workflow-level concurrency blocks in jobparser<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/1026 Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org> Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net> Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
This commit is contained in:
parent
014b4ba5f6
commit
56ef60060b
3 changed files with 87 additions and 106 deletions
|
@ -342,10 +342,11 @@ func TestParseMappingNode(t *testing.T) {
|
|||
|
||||
func TestEvaluateConcurrency(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input model.RawConcurrency
|
||||
group string
|
||||
cancelInProgress bool
|
||||
name string
|
||||
input model.RawConcurrency
|
||||
group string
|
||||
cancelInProgressNil bool
|
||||
cancelInProgress bool
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
|
@ -357,18 +358,18 @@ func TestEvaluateConcurrency(t *testing.T) {
|
|||
cancelInProgress: true,
|
||||
},
|
||||
{
|
||||
name: "undefined",
|
||||
input: model.RawConcurrency{},
|
||||
group: "",
|
||||
cancelInProgress: false,
|
||||
name: "undefined",
|
||||
input: model.RawConcurrency{},
|
||||
group: "",
|
||||
cancelInProgressNil: true,
|
||||
},
|
||||
{
|
||||
name: "group-evaluation",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ github.workflow }}-${{ github.ref }}",
|
||||
},
|
||||
group: "test_workflow-main",
|
||||
cancelInProgress: false,
|
||||
group: "test_workflow-main",
|
||||
cancelInProgressNil: true,
|
||||
},
|
||||
{
|
||||
name: "cancel-evaluation-true",
|
||||
|
@ -393,37 +394,44 @@ func TestEvaluateConcurrency(t *testing.T) {
|
|||
input: model.RawConcurrency{
|
||||
Group: "user-${{ github.event.commits[0].author.username }}",
|
||||
},
|
||||
group: "user-someone",
|
||||
cancelInProgress: false,
|
||||
group: "user-someone",
|
||||
cancelInProgressNil: true,
|
||||
},
|
||||
{
|
||||
name: "arbitrary-var",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ vars.eval_arbitrary_var }}",
|
||||
},
|
||||
group: "123",
|
||||
cancelInProgress: false,
|
||||
group: "123",
|
||||
cancelInProgressNil: true,
|
||||
},
|
||||
{
|
||||
name: "arbitrary-input",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ inputs.eval_arbitrary_input }}",
|
||||
},
|
||||
group: "456",
|
||||
cancelInProgress: false,
|
||||
group: "456",
|
||||
cancelInProgressNil: true,
|
||||
},
|
||||
{
|
||||
name: "cancel-in-progress-only",
|
||||
input: model.RawConcurrency{
|
||||
CancelInProgress: "true",
|
||||
},
|
||||
group: "",
|
||||
cancelInProgress: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
group, cancelInProgress, err := EvaluateConcurrency(
|
||||
group, cancelInProgress, err := EvaluateWorkflowConcurrency(
|
||||
&test.input,
|
||||
"job-id",
|
||||
nil, // job
|
||||
map[string]any{
|
||||
"workflow": "test_workflow",
|
||||
"ref": "main",
|
||||
"event": map[string]any{
|
||||
// gitCtx
|
||||
&model.GithubContext{
|
||||
Workflow: "test_workflow",
|
||||
Ref: "main",
|
||||
Event: map[string]any{
|
||||
"commits": []any{
|
||||
map[string]any{
|
||||
"author": map[string]any{
|
||||
|
@ -437,20 +445,24 @@ func TestEvaluateConcurrency(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
}, // gitCtx
|
||||
map[string]*JobResult{
|
||||
"job-id": {},
|
||||
}, // results
|
||||
},
|
||||
// vars
|
||||
map[string]string{
|
||||
"eval_arbitrary_var": "123",
|
||||
}, // vars
|
||||
},
|
||||
// inputs
|
||||
map[string]any{
|
||||
"eval_arbitrary_input": "456",
|
||||
}, // inputs
|
||||
},
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, test.group, group)
|
||||
assert.EqualValues(t, test.cancelInProgress, cancelInProgress)
|
||||
if test.cancelInProgressNil {
|
||||
assert.Nil(t, cancelInProgress)
|
||||
} else {
|
||||
require.NotNil(t, cancelInProgress)
|
||||
assert.EqualValues(t, test.cancelInProgress, *cancelInProgress)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue