Skip to content

[duplicate-code] Duplicate Code: repeated setup/pre-step assembly in compiler job paths #39026

@github-actions

Description

@github-actions

Summary

configureCustomJobSteps and applyBuiltinJobPreSteps both collect setup-steps and pre-steps, call extractPinnedJobSteps, and then splice those lists into job steps with nearly identical control flow.

Duplication Details

  • pkg/workflow/compiler_jobs.go:960-1003
  • pkg/workflow/compiler_jobs.go:1028-1080

Impact

  • Future changes to step ordering or validation now need to be updated in two places.
  • The duplicated branching increases the risk of custom and built-in jobs drifting apart.

Refactoring Recommendation

Extract a shared helper that loads setup-steps / pre-steps once and returns the normalized slices plus insertion intent. Keep the job-specific validation and target-job lookup separate, but centralize the extraction and insertion flow.

Code Sample

if hasSetupStepsField {
    setupSteps, err = c.extractPinnedJobSteps("setup-steps", jobName, configMap, data)
}
if hasPreStepsField {
    preSteps, err = c.extractPinnedJobSteps("pre-steps", jobName, configMap, data)
}
...
job.Steps = insertPreStepsAtEarliestBoundary(job.Steps, preSteps)
job.Steps = insertSetupStepsAtStart(job.Steps, setupSteps)

Analysis Metadata

  • Commit: 27e0d8d
  • Detection Method: Serena semantic code analysis + local source inspection

Generated by 🔍 Duplicate Code Detector · 78.6 AIC · ⌖ 12.1 AIC · ⊞ 14.8K ·

  • expires on Jun 14, 2026, 10:41 PM UTC-08:00

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions