Checksum for cache

cache

#1

Hello,

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:


#2

I just opened a bug ticket for this.


#4

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

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


#5

It works !
Thanks


#6

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.

map1:
  key:
    val

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.


#7