MCPcopy Create free account
hub / github.com/github/gh-aw / validateOnNeedsTargets

Function validateOnNeedsTargets

pkg/workflow/on_needs_validation.go:39–80  ·  view source on GitHub ↗
(data *WorkflowData)

Source from the content-addressed store, hash-verified

37}
38
39func validateOnNeedsTargets(data *WorkflowData) error {
40 if len(data.OnNeeds) == 0 {
41 return nil
42 }
43
44 customJobs := make(map[string]struct {
45 }, len(data.Jobs))
46 for jobName := range data.Jobs {
47 if isReservedOnNeedsTarget(jobName) {
48 continue
49 }
50 customJobs[jobName] = struct {
51 }{}
52 }
53
54 for _, need := range data.OnNeeds {
55 if isReservedOnNeedsTarget(need) {
56 return fmt.Errorf(
57 "on.needs: built-in job %q is not allowed. Expected one of the workflow's custom jobs. Example: on.needs: [secrets_fetcher]",
58 need,
59 )
60 }
61 if !setutil.Contains(customJobs, need) {
62 return fmt.Errorf(
63 "on.needs: unknown job %q. Expected one of the workflow's custom jobs. Example: on.needs: [secrets_fetcher]",
64 need,
65 )
66 }
67
68 if jobConfig, ok := data.Jobs[need].(map[string]any); ok {
69 if jobDependsOnActivation(jobConfig) || jobDependsOnPreActivation(jobConfig) {
70 return fmt.Errorf(
71 "on.needs: job %q cannot depend on activation/pre_activation because pre_activation and activation depend on on.needs jobs",
72 need,
73 )
74 }
75 }
76 }
77
78 onNeedsValidationLog.Printf("Validated %d on.needs dependency target(s)", len(data.OnNeeds))
79 return nil
80}
81
82func (c *Compiler) validateOnGitHubAppNeedsExpressions(data *WorkflowData) error {
83 if data == nil || data.ActivationGitHubApp == nil {

Callers 2

validateOnNeedsMethod · 0.85

Calls 6

ContainsFunction · 0.92
isReservedOnNeedsTargetFunction · 0.85
jobDependsOnActivationFunction · 0.85
ErrorfMethod · 0.45
PrintfMethod · 0.45

Tested by 1