how to use cache from bash script

I have found the actions/cache action and I like it.

My workflow is rather dynamic and I would like to calculate what set of caches is needed.

Therefore I would like to control my caches from within my build bash script.

Is that possible?

Hi tombrus,

Thanks for your feedback! Control exact cache from bash script is not supported.

Action/cache will help to store the output or downloaded dependencies from one run onto Github. These cache files should not be changed often between jobs or workflow runs. Related link.

It is possible to control key/restore key(same for path) in the bash file, format as below:

echo "::set-output name=key1::$var1"
echo "::set-output name=key2::$var2"

Add a prior step before action/cache in workflow file, code sample as below, hope it helps, thanks.

- name: setkey
      id: keyvalue
      run: |
      shell: bash

    - name: Cache node modules
      uses: actions/cache@v1
        path: node_modules
        key: ${{ runner.OS }}-${{ steps.keyvalue.outputs.key1 }}
        restore-keys: |
          ${{ runner.OS }}-${{ steps.keyvalue.outputs.key2 }}
          ${{ runner.OS }}-
1 Like

Hi weide-zhou,

Thanks for the reply. It is not exactly what I was looking for but I did not yet know the neat trick of feeding back info through “::set-output”. I put that one in my toolbox!

In my original question I mentioned “rather dynamic”. I did not phrase that correctly. Actually I would like to have a higher granularity in my caches. I would like to make e.g. 20 caches of different dirs in my workspace, so that when changes are pushed only some parts need recalculation, other parts will use the caches. This set of 20 will increase over time. I do not want to have a long list of cache steps in my yaml file and I prefer not to have my devs maintain that list because they will forget. My bash script can dig out this list and I would like to cache all items in the list.

Is a loop contruct possible in the yaml file? Then I could construct something. 

Can I programatically add steps (e.g. from a bash script)? That would also help to get this done on the yaml level.

I hope you, or somebody else, will have some answers.