Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use computed properties in github actions

I am trying to rebuild my ci-cd within the new github actions yaml format (new), the issue is that I can't seem to use computed values as arguments in a step.

I have tried the following

      - name: Download Cache
        uses: ./.github/actions/cache
        with:
          entrypoint: restore_cache
          args: --bucket=gs://[bucket secret] --key=node-modules-cache-$(checksum package.json)-node-12.7.0

However "$(checksum package.json)" is not valid as part of an argument. Please not this has nothing to do with if the command checksum exists, it does exist within the container.

I'm trying to copy this kind of setup in google cloud build

  - name: gcr.io/$PROJECT_ID/restore_cache
    id: restore_cache_node
    args:
      - '--bucket=gs://${_CACHE_BUCKET}'
      - '--key=node-modules-cache-$(checksum package.json)-node-${_NODE_VERSION}'

I expected to be able to use compute arguments in a similar way to other ci-cd solutions.

Is there a way to do this that I am missing? Maybe being able to use 'run:' within a docker container to run some commands.

like image 461
Drew Hutton Avatar asked Nov 06 '22 14:11

Drew Hutton


1 Answers

The only solution I'm aware of at the moment is to compute the value in a previous step so that you can use it in later steps.

See this answer for a method using set-output. This is the method I would recommend for passing computed values between workflow steps. Github Actions, how to share a calculated value between job steps?

Alternatively, you can create environment variables. Computed environment variables can also be used in later steps. How do I set an env var with a bash expression in GitHub Actions?

like image 155
peterevans Avatar answered Nov 11 '22 03:11

peterevans