Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/envfiles/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func ParseEnvFile(path string) (map[string]string, error) {
// Each line in the file is a path to add.
// If the file doesn't exist, an empty slice is returned without error.
func ParsePathFile(path string) ([]string, error) {
var result []string
result := make([]string, 0, 8) // Pre-allocate with reasonable initial capacity

file, err := os.Open(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/envfiles/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func TestParsePathFile(t *testing.T) {
{
name: "empty file",
content: "",
expected: nil,
expected: []string{},
},
{
name: "single path",
Expand Down
3 changes: 2 additions & 1 deletion internal/workflow/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func extractJobOrderFromNode(root *yaml.Node) []string {

if keyNode.Value == "jobs" && valueNode.Kind == yaml.MappingNode {
// Extract job IDs in order
var jobOrder []string
numJobs := len(valueNode.Content) / 2
jobOrder := make([]string, 0, numJobs)
for j := 0; j < len(valueNode.Content)-1; j += 2 {
jobKeyNode := valueNode.Content[j]
jobOrder = append(jobOrder, jobKeyNode.Value)
Expand Down
10 changes: 6 additions & 4 deletions internal/workflow/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,30 @@ jobs:
// BenchmarkLoadWorkflowFile benchmarks the workflow file loading performance.
func BenchmarkLoadWorkflowFile(b *testing.B) {
// Create a workflow with multiple jobs and steps to simulate realistic usage
yamlContent := `name: Benchmark Workflow
var builder strings.Builder
builder.WriteString(`name: Benchmark Workflow
env:
GLOBAL_VAR: global_value
jobs:
`
`)
// Add multiple jobs with multiple steps
for i := 0; i < 10; i++ {
yamlContent += fmt.Sprintf(` job%d:
fmt.Fprintf(&builder, ` job%d:
name: Job %d
runs-on: ubuntu-latest
env:
JOB_VAR: job_value_%d
steps:
`, i, i, i)
for j := 0; j < 5; j++ {
yamlContent += fmt.Sprintf(` - name: Step %d-%d
fmt.Fprintf(&builder, ` - name: Step %d-%d
run: echo "Running step %d in job %d"
env:
STEP_VAR: step_value_%d_%d
`, i, j, j, i, i, j)
}
}
yamlContent := builder.String()

tmpDir := b.TempDir()
workflowPath := filepath.Join(tmpDir, "benchmark.yml")
Expand Down
6 changes: 3 additions & 3 deletions internal/workflow/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func DiscoverWorkflows(repoRoot string) ([]string, error) {
return nil, fmt.Errorf("failed to read workflows directory: %w", err)
}

var workflows []string
workflows := make([]string, 0, len(entries))
for _, entry := range entries {
if entry.IsDir() {
continue
}

name := entry.Name()
ext := strings.ToLower(filepath.Ext(name))
if ext == ".yml" || ext == ".yaml" {
ext := filepath.Ext(name)
if strings.EqualFold(ext, ".yml") || strings.EqualFold(ext, ".yaml") {
workflows = append(workflows, filepath.Join(workflowsDir, name))
}
}
Expand Down