Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multiple pipelines execution #926

Merged
merged 1 commit into from
May 31, 2023
Merged
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
50 changes: 33 additions & 17 deletions engine/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,11 @@ func ExecConfigurationFile(env *Env, file *ReviewpadFile) (ExitStatus, *Program,

// pipelines should only run on pull requests
if env.TargetEntity.Kind == entities.PullRequest {
// process pipelines
for _, pipeline := range file.Pipelines {
log.Infof("evaluating pipeline '%v':", pipeline.Name)
pipelineLog := log.WithField("pipeline", pipeline.Name)

pipelineLog.Infof("processing pipeline '%v':", pipeline.Name)

var err error
activated := pipeline.Trigger == ""
if !activated {
Expand All @@ -373,24 +373,40 @@ func ExecConfigurationFile(env *Env, file *ReviewpadFile) (ExitStatus, *Program,
}
}

if activated {
for num, stage := range pipeline.Stages {
pipelineLog.Infof("evaluating pipeline stage '%v'", num)
if stage.Until == "" {
program.append(stage.Actions)
retStatus, err := execActions(interpreter, stage.Actions)
return retStatus, program, err
}
if !activated {
pipelineLog.Info("skipping pipeline because the trigger condition was not met")
continue
}

isDone, err := interpreter.EvalExpr("patch", stage.Until)
if err != nil {
return ExitStatusFailure, nil, err
for num, stage := range pipeline.Stages {
pipelineLog.Infof("processing pipeline stage %v", num)

if stage.Until == "" {
pipelineLog.Info("pipeline stage 'until' condition not specified, executing actions")

program.append(stage.Actions)
retStatus, err := execActions(interpreter, stage.Actions)
if err != nil || retStatus == ExitStatusFailure {
return retStatus, nil, err
}

if !isDone {
program.append(stage.Actions)
retStatus, err := execActions(interpreter, stage.Actions)
return retStatus, program, err
break
}

isStageCompleted, err := interpreter.EvalExpr("patch", stage.Until)
if err != nil {
return ExitStatusFailure, nil, err
}

if isStageCompleted {
pipelineLog.Info("pipeline stage 'until' condition was met, skipping stage")
} else {
pipelineLog.Info("pipeline stage 'until' condition was not met, executing actions")

program.append(stage.Actions)
retStatus, err := execActions(interpreter, stage.Actions)
if err != nil || retStatus == ExitStatusFailure {
return retStatus, nil, err
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions engine/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,25 @@ func TestExecConfigurationFile(t *testing.T) {
targetEntity: engine.DefaultMockTargetEntity,
wantExitStatus: engine.ExitStatusSuccess,
},
"reviewpad with pipelines": {
inputReviewpadFilePath: "testdata/exec/reviewpad_with_pipelines.yml",
wantProgram: engine.BuildProgram(
[]*engine.Statement{
engine.BuildStatement(`$addLabel("pipeline with no trigger")`),
engine.BuildStatement(`$addLabel("pipeline with trigger")`),
engine.BuildStatement(`$addLabel("pipeline with single stage and single action")`),
engine.BuildStatement(`$addLabel("pipeline with single stage and multiple actions - 1/2")`),
engine.BuildStatement(`$addLabel("pipeline with single stage and multiple actions - 2/2")`),
engine.BuildStatement(`$addLabel("pipeline with multiple stages - stage 2")`),
engine.BuildStatement(`$addLabel("pipeline with multiple stages and multiple actions - stage 2 - 1/2")`),
engine.BuildStatement(`$addLabel("pipeline with multiple stages and multiple actions - stage 2 - 2/2")`),
engine.BuildStatement(`$addLabel("pipeline with single stage and concise actions")`),
engine.BuildStatement(`$addLabel("pipeline with multiple stages and concise actions - stage 2")`),
},
),
targetEntity: engine.DefaultMockTargetEntity,
wantExitStatus: engine.ExitStatusSuccess,
},
}

codehostClient := aladino.GetDefaultCodeHostClient(t, aladino.GetDefaultPullRequestDetails(), aladino.GetDefaultPullRequestFileList(), nil, nil)
Expand Down
65 changes: 65 additions & 0 deletions engine/testdata/exec/reviewpad_with_pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Copyright 2022 Explore.dev Unipessoal Lda. All Rights Reserved.
# Use of this source code is governed by a license that can be
# found in the LICENSE file.

pipelines:
- name: pipeline with no trigger
stages:
- actions:
- $addLabel("pipeline with no trigger")

- name: pipeline with trigger
trigger: 1 == 1
stages:
- actions:
- $addLabel("pipeline with trigger")

- name: pipeline with failing trigger
trigger: 1 == 2
stages:
- actions:
- $addLabel("pipeline with failing trigger")

- name: pipeline with single stage and single action
trigger: 1 == 1
stages:
- actions:
- $addLabel("pipeline with single stage and single action")

- name: pipeline with single stage and multiple actions
trigger: 1 == 1
stages:
- actions:
- $addLabel("pipeline with single stage and multiple actions - 1/2")
- $addLabel("pipeline with single stage and multiple actions - 2/2")

- name: pipeline with multiple stages
trigger: 1 == 1
stages:
- actions:
- $addLabel("pipeline with multiple stages - stage 1")
until: 1 == 1
- actions:
- $addLabel("pipeline with multiple stages - stage 2")

- name: pipeline with multiple stages and multiple actions
trigger: 1 == 1
stages:
- actions:
- $addLabel("pipeline with multiple stages and multiple actions - stage 1")
until: 1 == 1
- actions:
- $addLabel("pipeline with multiple stages and multiple actions - stage 2 - 1/2")
- $addLabel("pipeline with multiple stages and multiple actions - stage 2 - 2/2")

- name: pipeline with single stage and concise actions
trigger: 1 == 1
stages:
- actions: $addLabel("pipeline with single stage and concise actions")

- name: pipeline with multiple stages and concise actions
trigger: 1 == 1
stages:
- actions: $addLabel("pipeline with multiple stages and concise actions - stage 1")
until: 1 == 1
- actions: $addLabel("pipeline with multiple stages and concise actions - stage 2")
Loading
Loading