Skip to content

Commit

Permalink
Evaluate if condition when calling a reusable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jenseng committed Nov 10, 2023
1 parent 55b09a0 commit 9fba010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,15 +673,17 @@ func (rc *RunContext) isEnabled(ctx context.Context) (bool, error) {

if jobType == model.JobTypeInvalid {
return false, jobTypeErr
} else if jobType != model.JobTypeDefault {
return true, nil
}

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

if jobType != model.JobTypeDefault {
return true, nil
}

img := rc.platformImage(ctx)
if img == "" {
if job.RunsOn() == nil {
Expand Down
11 changes: 11 additions & 0 deletions pkg/runner/run_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,17 @@ if: always()`, ""),
})
rc.Run.JobID = "job2"
assertObject.True(rc.isEnabled(context.Background()))

rc = createIfTestRunContext(map[string]*model.Job{
"job1": createJob(t, `uses: ./.github/workflows/reusable.yml`, ""),
})
assertObject.True(rc.isEnabled(context.Background()))

rc = createIfTestRunContext(map[string]*model.Job{
"job1": createJob(t, `uses: ./.github/workflows/reusable.yml
if: false`, ""),
})
assertObject.False(rc.isEnabled(context.Background()))
}

func TestRunContextGetEnv(t *testing.T) {
Expand Down

0 comments on commit 9fba010

Please sign in to comment.