Skip to content

Commit

Permalink
support inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zettat123 committed Jan 15, 2025
1 parent e5ac174 commit c8a4ffd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
32 changes: 31 additions & 1 deletion services/actions/concurrency.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,37 @@ import (
"fmt"

actions_model "code.gitea.io/gitea/models/actions"
"code.gitea.io/gitea/modules/json"
api "code.gitea.io/gitea/modules/structs"

"github.com/nektos/act/pkg/jobparser"
act_model "github.com/nektos/act/pkg/model"
)

func EvaluateWorkflowConcurrency(run *actions_model.ActionRun, rc *act_model.RawConcurrency, vars map[string]string) (string, bool, error) {

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: act_model.RawConcurrency

Check failure on line 17 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: act_model.RawConcurrency
gitCtx := jobparser.ToGitContext(GenerateGitContext(run, nil))

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.ToGitContext

Check failure on line 18 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.ToGitContext
inputs, err := getInputsFromRun(run)
if err != nil {
return "", false, fmt.Errorf("get inputs: %w", err)
}
jobResults := map[string]*jobparser.JobResult{"": {}}

concurrencyGroup, concurrencyCancel := jobparser.EvaluateConcurrency(rc, "", gitCtx, jobResults, vars, inputs)

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.EvaluateConcurrency

Check failure on line 25 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.EvaluateConcurrency

return concurrencyGroup, concurrencyCancel, nil
}

func EvaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_model.ActionRunJob, vars map[string]string, jobResults map[string]*jobparser.JobResult) (string, bool, error) {
rawConcurrency := &act_model.RawConcurrency{

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: act_model.RawConcurrency

Check failure on line 31 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: act_model.RawConcurrency
Group: actionRunJob.RawConcurrencyGroup,
CancelInProgress: actionRunJob.RawConcurrencyCancel,
}

gitCtx := jobparser.ToGitContext(GenerateGitContext(run, actionRunJob))

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.ToGitContext

Check failure on line 36 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.ToGitContext
inputs, err := getInputsFromRun(run)
if err != nil {
return "", false, fmt.Errorf("get inputs: %w", err)
}

singleWorkflows, err := jobparser.Parse([]byte(actionRunJob.WorkflowPayload))
if err != nil {
Expand All @@ -34,7 +53,18 @@ func EvaluateJobConcurrency(run *actions_model.ActionRun, actionRunJob *actions_
Needs: actionRunJob.Needs,
}

concurrencyGroup, concurrencyCancel := jobparser.EvaluateJobConcurrency(rawConcurrency, actionRunJob.JobID, gitCtx, vars, jobResults)
concurrencyGroup, concurrencyCancel := jobparser.EvaluateConcurrency(rawConcurrency, actionRunJob.JobID, gitCtx, jobResults, vars, inputs)

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-pgsql

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-sqlite

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mssql

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-unit

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-mysql

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-backend

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

undefined: jobparser.EvaluateConcurrency

Check failure on line 56 in services/actions/concurrency.go

View workflow job for this annotation

GitHub Actions / test-e2e

undefined: jobparser.EvaluateConcurrency

return concurrencyGroup, concurrencyCancel, nil
}

func getInputsFromRun(run *actions_model.ActionRun) (map[string]any, error) {
if run.Event != "workflow_dispatch" {
return map[string]any{}, nil
}
var payload api.WorkflowDispatchPayload
if err := json.Unmarshal([]byte(run.EventPayload), &payload); err != nil {
return nil, err
}
return payload.Inputs, nil
}
7 changes: 5 additions & 2 deletions services/actions/notifier_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,11 @@ func handleWorkflows(
continue
}
if wfRawConcurrency != nil {
wfGitCtx := jobparser.ToGitContext(GenerateGitContext(run, nil))
wfConcurrencyGroup, wfConcurrencyCancel := jobparser.EvaluateWorkflowConcurrency(wfRawConcurrency, wfGitCtx, vars)
wfConcurrencyGroup, wfConcurrencyCancel, err := EvaluateWorkflowConcurrency(run, wfRawConcurrency, vars)
if err != nil {
log.Error("EvaluateWorkflowConcurrency: %v", err)
continue
}
if len(wfConcurrencyGroup) > 0 {
run.ConcurrencyGroup = wfConcurrencyGroup
run.ConcurrencyCancel = wfConcurrencyCancel
Expand Down

0 comments on commit c8a4ffd

Please sign in to comment.