mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-09-15 18:57:01 +00:00
feat: support evaluation of concurrency clauses in runner (#827)
Pre-req for support `concurrency` clauses for Gitea Actions, later added to Gitea in PR: https://github.com/go-gitea/gitea/pull/32751. Unit tests added in this PR relative to upstream. Squashes PRs https://gitea.com/gitea/act/pulls/124 & https://gitea.com/gitea/act/pulls/139, as noted in https://code.forgejo.org/forgejo/runner/issues/678 Reviewed-on: https://gitea.com/gitea/act/pulls/124 Reviewed-by: Lunny Xiao <lunny@noreply.gitea.com> Co-authored-by: Zettat123 <zettat123@gmail.com> Co-committed-by: Zettat123 <zettat123@gmail.com> Reviewed-on: https://gitea.com/gitea/act/pulls/139 Reviewed-by: Zettat123 <zettat123@noreply.gitea.com> Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: ChristopherHX <christopher.homberger@web.de> Co-committed-by: ChristopherHX <christopher.homberger@web.de> <!--start release-notes-assistant--> <!--URL:https://code.forgejo.org/forgejo/runner--> - features - [PR](https://code.forgejo.org/forgejo/runner/pulls/827): <!--number 827 --><!--line 0 --><!--description ZmVhdDogc3VwcG9ydCBldmFsdWF0aW9uIG9mIGNvbmN1cnJlbmN5IGNsYXVzZXMgaW4gcnVubmVy-->feat: support evaluation of concurrency clauses in runner<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://code.forgejo.org/forgejo/runner/pulls/827 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
3f468733cb
commit
7a31b6a55e
12 changed files with 330 additions and 4 deletions
|
@ -339,3 +339,118 @@ func TestParseMappingNode(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateConcurrency(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input model.RawConcurrency
|
||||
group string
|
||||
cancelInProgress bool
|
||||
}{
|
||||
{
|
||||
name: "basic",
|
||||
input: model.RawConcurrency{
|
||||
Group: "group-name",
|
||||
CancelInProgress: "true",
|
||||
},
|
||||
group: "group-name",
|
||||
cancelInProgress: true,
|
||||
},
|
||||
{
|
||||
name: "undefined",
|
||||
input: model.RawConcurrency{},
|
||||
group: "",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
{
|
||||
name: "group-evaluation",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ github.workflow }}-${{ github.ref }}",
|
||||
},
|
||||
group: "test_workflow-main",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
{
|
||||
name: "cancel-evaluation-true",
|
||||
input: model.RawConcurrency{
|
||||
Group: "group-name",
|
||||
CancelInProgress: "${{ !contains(github.ref, 'release/')}}",
|
||||
},
|
||||
group: "group-name",
|
||||
cancelInProgress: true,
|
||||
},
|
||||
{
|
||||
name: "cancel-evaluation-false",
|
||||
input: model.RawConcurrency{
|
||||
Group: "group-name",
|
||||
CancelInProgress: "${{ contains(github.ref, 'release/')}}",
|
||||
},
|
||||
group: "group-name",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
{
|
||||
name: "event-evaluation",
|
||||
input: model.RawConcurrency{
|
||||
Group: "user-${{ github.event.commits[0].author.username }}",
|
||||
},
|
||||
group: "user-someone",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
{
|
||||
name: "arbitrary-var",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ vars.eval_arbitrary_var }}",
|
||||
},
|
||||
group: "123",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
{
|
||||
name: "arbitrary-input",
|
||||
input: model.RawConcurrency{
|
||||
Group: "${{ inputs.eval_arbitrary_input }}",
|
||||
},
|
||||
group: "456",
|
||||
cancelInProgress: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
group, cancelInProgress, err := EvaluateConcurrency(
|
||||
&test.input,
|
||||
"job-id",
|
||||
nil, // job
|
||||
map[string]any{
|
||||
"workflow": "test_workflow",
|
||||
"ref": "main",
|
||||
"event": map[string]interface{}{
|
||||
"commits": []interface{}{
|
||||
map[string]interface{}{
|
||||
"author": map[string]interface{}{
|
||||
"username": "someone",
|
||||
},
|
||||
},
|
||||
map[string]interface{}{
|
||||
"author": map[string]interface{}{
|
||||
"username": "someone-else",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}, // gitCtx
|
||||
map[string]*JobResult{
|
||||
"job-id": {},
|
||||
}, // results
|
||||
map[string]string{
|
||||
"eval_arbitrary_var": "123",
|
||||
}, // vars
|
||||
map[string]any{
|
||||
"eval_arbitrary_input": "456",
|
||||
}, // inputs
|
||||
)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, test.group, group)
|
||||
assert.EqualValues(t, test.cancelInProgress, cancelInProgress)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue