5

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.

Drew Hutton
  • 183
  • 1
  • 9
  • Where do you found that /.github/actions/cache uses? – Tiago Gouvêa Aug 23 '19 at 12:28
  • 1
    @TiagoGouvêa `/.github/actions/cache` is a local Docker action (Dockerfile) which contains the same content as here [Cloudbuilders Cache](https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/cache) Information on how to use a docker local docker image as a action step is located [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#example-using-action-in-the-same-repository-as-the-workflow) As an update I have a workaround of this issue by creating a custom JS action. More information will be posted soon if i can open source this :). – Drew Hutton Aug 25 '19 at 03:58

1 Answers1

1

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?

peterevans
  • 34,297
  • 7
  • 84
  • 83