Skip to content

Commit 5547789

Browse files
jensengmergify[bot]ChristopherHX
authored
Evaluate if condition when calling a reusable workflow (#2087)
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: ChristopherHX <christopher.homberger@web.de>
1 parent 04011b6 commit 5547789

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/runner/run_context.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,15 +691,17 @@ func (rc *RunContext) isEnabled(ctx context.Context) (bool, error) {
691691

692692
if jobType == model.JobTypeInvalid {
693693
return false, jobTypeErr
694-
} else if jobType != model.JobTypeDefault {
695-
return true, nil
696694
}
697695

698696
if !runJob {
699697
l.WithField("jobResult", "skipped").Debugf("Skipping job '%s' due to '%s'", job.Name, job.If.Value)
700698
return false, nil
701699
}
702700

701+
if jobType != model.JobTypeDefault {
702+
return true, nil
703+
}
704+
703705
img := rc.platformImage(ctx)
704706
if img == "" {
705707
for _, platformName := range rc.runsOnPlatformNames(ctx) {

pkg/runner/run_context_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,17 @@ if: always()`, ""),
619619
})
620620
rc.Run.JobID = "job2"
621621
assertObject.True(rc.isEnabled(context.Background()))
622+
623+
rc = createIfTestRunContext(map[string]*model.Job{
624+
"job1": createJob(t, `uses: ./.github/workflows/reusable.yml`, ""),
625+
})
626+
assertObject.True(rc.isEnabled(context.Background()))
627+
628+
rc = createIfTestRunContext(map[string]*model.Job{
629+
"job1": createJob(t, `uses: ./.github/workflows/reusable.yml
630+
if: false`, ""),
631+
})
632+
assertObject.False(rc.isEnabled(context.Background()))
622633
}
623634

624635
func TestRunContextGetEnv(t *testing.T) {

0 commit comments

Comments
 (0)