Flows

Flows are a list of executed steps. A command are a flow for piscosour. The flows don't work over a context, step do that, so flows can work over multiple steps, and different contexts.

The flow execution is sequential, step by step, and step are executed for each context. Note that if a step is no defined for any context it is no executed.

Flows are implements with three files in the recipe:

-rwxr-xr-x    1 pisco  staff   flows/flow-name/config.json
-rwxr-xr-x    1 pisco  staff   flows/flow-name/info.md

Where the config.json file has the configuration, info.md explain and document the flow.

Note, it exists a scaffold generator tool

config.json configuration

The config.json file has the definition of the flow. A example is:

{
  "name": "Create from scratch",
  "description": "Starting a repository from scratch",
  "type" : "normal",
  "excludes" : [ "any" ],
  "isGenerator": true,
  "params": {
    "param1": "value1",
    "param2": 2,
    "param3": true,
    "param4": { "object1": "value" }
  },
  "steps": {
    "step1": {
        "excludes" : [ "any" ],
        "params": {
            "param1": "value1",
            "param2": 2
        }
    },
    "step2": {
        "reloadContext" : true,
        "type" : "flow",
    },
    "step3": {
        "implementation-check" : false    
    }
  }
}

In the config.json file could be configured the following fields:

name property

Short name of the flow, it must be descriptive and unique.

description property

It is a short description about the flow.

type property

Type of the flows

excludes property

Is an array of contexts witch execution is excluded for all steps of this flow. For example:

{
  "name": "validate",
  "description": "Validate CI flow",
  "excludes": ["develop", "master", "feature", "hotfix", "release", "merger", "consolidation"],
    "steps": {
      "install": {
        "type": "flow"
      },
  ....
}

The execution of this flow will prompt this message on output:

[18:13:32] Run of flow "install" is excluded for context "feature"

isGenerator property

If the steps creates a context, then this flag must be with a 'true' value.

params property

Others customized paramaters, see parameters for more information.

Example:

{
  "params": {
    "param1": "value1",
    "param2": 2,
    "param3": true,
    "param4": { "object1": "value" }
  }
}

Understanding parameters in flows

The 'config.json' file of a flow has the following possibilities:

a. Common parameters for all steps

{
  "params": {
    "param1": "value1",
    "param2": "value2",
    "param3": "value3"
  }
}

b. Common parameters for all contexts in a specific step

{
  "params": {},
  "steps" : {
    "stepName" : {
      "params" : {
        "param1": "value1",
        "param2": "value2",
        "param3": "value3",
      }
    }
  }
}

c. Parameters for a specific step and context

{
  "params": {},
  "steps" : {
    "stepName" : {
      "contextName" : {
        "params" : {
          "param1": "value1",
          "param2": "value2",
          "param3": "value3"
        }
      }
    }
  }
}

Allways the parameters are available with this.params.

Example:

module.export = {
  run: function() {
    console.log(
      this.params.param1,
      this.params.param2,
      this.params.param3);
  }
}

The priority is (from high to low):

  1. Parameters for a specific step and context
  2. Common parameters for all contexts in a specific step
  3. Common parameters for all steps.

step property

List of sequential steps in the flow.

The execution of a flow with exclude on it will prompt this message on output:

[18:13:32] Run of step "build" is excluded for context "feature"

The execution of a flow with implementation-check on it will prompt this message on output:

[18:13:32] Run of step "provide-env" is allowed to be not implemented for context "app"

reloadContext example:


{
  "name": "consolidate",
  "description": "[Git flow]: Check for semver relate updates",
  "steps": {
    "start" : {
      "type" : "flow"
    },
    "finish" : {
      "reloadContext" : true,
      "type" : "flow"
    }
  }
}

In this example start flow change old context named master to new context named consolidation, finish flow needs to reload contexts in order to realize that this new context is present and execute finish using the new context.

All options example:

{
  "steps": {
    "step1": {
        "excludes" : [ "any" ],
        "params": {
            "param1": "value1",
            "param2": 2
        }
    },
    "step2": {
        "reloadContext" : true,
        "type" : "flow",
    },
    "step3": {
        "implementation-check" : false    
    }
  }
}

Repeated steps

In some cases, it may be necessary to repeat the same step twice or more, with different parameters. Then it is possible to identify the step with a sufix separated with ':' character, like step1:id1.

Example:

{
  "steps": {
    "mystep:first": {
      "params": {
        "myparam": "value1"
      }
    },
    "mystep:second": {
      "params": {
        "myparam": "value2"
      }
    }
  }
}

In the above example, mystep is executed twice with different myparam configuration. It is advisable that the suffix has a semantic value which describe the differences.

Scaffold generator

Pisco provides a scaffold generator. Launch it placed inside your recipe with:

$ cd your-recipe
$ pisco recipe:add-flow