Checksum for cache




I want to cache some directories and the key must be a filename in a directory of the working dir.
If I write for example key: {{ checksum "composer.lock" }} then the file must be found at the root of the working dir.
But these following syntax don’t work
key: {{ checksum "apps/app1/composer.lock" }} or
key: {{ checksum "/root/workingdir/apps/app1/composer.lock" }}
key: /root/workingdir/apps/app1/{{ checksum "composer.lock" }}
key: apps/app1/{{ checksum "composer.lock" }}

The error is

* error parsing config: yaml: unmarshal errors:
  line 18: cannot unmarshal !!map into string

Is it supported or not ?

Continuing the discussion from Getting Started: Configuration:


I just opened a bug ticket for this.


Can you try this with the apostrophes? It seems like your YAML is not validating:

key: '{{ checksum "apps/app1/composer.lock" }}'


It works !


For others who get here reading this, this looks like YAML coerces the section after key: differently depending on whether you use fixed strings or only dynamic fields. key: mykey-{{ checksum "apps/app1/composer.lock" }} would coerce the value to a string.

On the other hand, key: {{ checksum "apps/app1/composer.lock" }} attempts to convert the value section to a map because you can write a map using curly brackets or line-breaks and indents. The following will produce equivalently nested maps.


map2: {key2: val}

You can follow along with these interactively using this online yaml parser.

Note that we recently addressed this by changing cache keys to look like << checksum "file" >>. We will still support the {{ checksum "file" }} curly bracket syntax, but the angle bracket syntax is less error prone.