Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
feat(server): add Tera templating support to tasks
Browse files Browse the repository at this point in the history
This replaces the existing custom (limited) templating support that
swapped `{My Var}` with the value of the task variable `My Var`.

With this first implementation, there are two global objects available
for use:

1. The `var` object contains all task variables and their related job
   values.
2. The `sys` object contains system-level variables for accessing data
   that isn't defined via a variable, but is provided by Automaat.

(see the last paragraph how to use these objects)

For a rundown of the templating syntax, see the Tera documentation at
https://tera.netlify.com/docs/templates/#templates.

It is important to note that the scope of the template is limited to a
single processor configuration **string value**. This means that the
following step definition works:

    {
      "name": "Universal Welcome",
      "description": "Greet your planetary system.",
      "processor": {
        "shellCommand": {
          "command": "echo",
          "arguments": [
            "hello",
            "{% if var['Planet'] is matching('Earth|Mars') %}Solar System{% else %}Planetary System{% endif %}"
          ]
        }
      }
    }

But this one won't, because the variable `name` is defined in its own
JSON string, which is parsed separately from the next string value:

    {
      "name": "Universal Welcome",
      "description": "Greet your planetary system.",
      "processor": {
        "shellCommand": {
          "command": "echo",
          "arguments": [
            "hello",
            "{% if var['Planet'] is matching('Earth|Mars') %}{% set name = "Solar" %}{% else %}{% set name = "Planetary" %}{% endif %}",
            "{{ name }} System"
          ]
        }
      }
    }

Closes #23.

This is also another step towards implementing
#22 and
#24.

BREAKING CHANGE: With the change of templating engine, variables are now
accessed in a different way:

* task variable access `{My Var}` becomes `{{ var["My Var"] }}`
* step output `{$input}` becomes `{{ sys["previous step output"] }}`
* workspace path `{$workspace}` becomes `{{ sys["workspace path"] }}`
  • Loading branch information
JeanMertz committed Jul 12, 2019
1 parent 015c41d commit 858d44d
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 37 deletions.
Loading

0 comments on commit 858d44d

Please sign in to comment.