Skip to content

Commit

Permalink
fix: allow running whole groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Dec 26, 2024
1 parent 94e3757 commit 1a9632a
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions internal/lefthook/runner/run_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ var (
type domain struct {
failed *atomic.Bool

glob string
root string
glob string
root string
onlyJobs []string
}

func (r *Runner) runJobs(ctx context.Context) []Result {
Expand All @@ -36,7 +37,7 @@ func (r *Runner) runJobs(ctx context.Context) []Result {
resultsChan := make(chan Result, len(r.Hook.Jobs))

var failed atomic.Bool
domain := &domain{failed: &failed}
domain := &domain{failed: &failed, onlyJobs: r.RunOnlyJobs}

for i, job := range r.Hook.Jobs {
id := strconv.Itoa(i)
Expand Down Expand Up @@ -82,7 +83,7 @@ func (r *Runner) runJob(ctx context.Context, domain *domain, id string, job *con
}

if len(job.Run) != 0 || len(job.Script) != 0 {
if len(r.RunOnlyJobs) != 0 && !slices.Contains(r.RunOnlyJobs, job.Name) {
if len(domain.onlyJobs) != 0 && !slices.Contains(domain.onlyJobs, job.Name) {
return skipped(job.PrintableName(id))
}

Expand All @@ -95,13 +96,8 @@ func (r *Runner) runJob(ctx context.Context, domain *domain, id string, job *con
inheritedDomain.root = first(job.Root, domain.root)
groupName := first(job.Name, "["+id+"]")

if len(r.RunOnlyJobs) != 0 && slices.Contains(r.RunOnlyJobs, job.Name) {
children := make([]string, len(job.Group.Jobs), 0)
for _, child := range job.Group.Jobs {
children = append(children, child.Name)
}

r.RunOnlyJobs = append(r.RunOnlyJobs, children...)
if len(domain.onlyJobs) != 0 && slices.Contains(domain.onlyJobs, job.Name) {
inheritedDomain.onlyJobs = []string{}
}

return r.runGroup(ctx, groupName, &inheritedDomain, job.Group)
Expand Down

0 comments on commit 1a9632a

Please sign in to comment.