I just learned that you can use yaml references in your config.yml (which is btw not mentioned anywhere in the docs that I have seen) which I’ve now started using extensively to remove a lot of repetition. All my steps now look something like
- *cache_restore_node_download
- *cmd_install_node
- *cache_save_node_download
with those references defined as:
- &cache_restore_node_download
restore_cache:
name: Restoring cache - node installation package
key: cache-downloads-node-{{ checksum ".tmp/node_version" }}
- &cmd_install_node
run:
name: Installing node
command: |
[snip] ...commands to download the correct node version if another version was restored above...
[snip] ...install node from downloaded archive...
- &cache_save_node_download
save_cache:
name: Saving cache - node installation package
key: cache-downloads-node-{{ checksum ".tmp/node_version" }}
paths:
- ~/.downloads/node/
However, having to do this in every job in a workflow is still a lot of repetition, especially since this is not my only cache and I have to do this several times.
It would make the config much more concise if it was possible to combine all those three steps into one, e.g. with a reference such as:
  • &install_node
- restore_cache: ...
- run: ...
- save_cache: ...
so that one of my steps could be:
- *install_node
This however translates to a nested array, which is not a structure that Circle supports. This could be allowed by Circle if nested steps were flattened to a 1-dimensional array, e.g. if
- - restore_cache: ...
- run: ...
- save_cache: ...
was rewritten as simply
- restore_cache: ...
- run: ...
- save_cache: ...
This is to say, nested steps are just one way of supporting bundling multiple steps into one yaml reference. I’m open to hear about other possibilities of allowing that if somebody has other ideas or already does this in some other way!
CCI-I-456