| 37 | } |
| 38 | |
| 39 | func 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 | |
| 82 | func (c *Compiler) validateOnGitHubAppNeedsExpressions(data *WorkflowData) error { |
| 83 | if data == nil || data.ActivationGitHubApp == nil { |