ScribeMD / docker-cache

Cache Docker Images Whether Built or Pulled

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot use output from a previous step in key

marc-hb opened this issue · comments

I'm successfully fetching the digest of the latest image (before downloading the actual image) with docker manifest inspect ghcr.io/zephyrproject-rtos/ci:latest -v | jq -r '.[0].Descriptor.digest' and I'm (naively?) trying to use it in the key.

I first tried set-output as documented here: https://github.com/marketplace/actions/cache#creating-a-cache-key

      - name: get digest of latest ghcr.io/zephyrproject-rtos/ci
        id: latest-zephyr-img
        run: |
          docker manifest inspect ghcr.io/zephyrproject-rtos/ci:latest -v | jq -r '.[0].Descriptor.digest' | tee latest-img
          echo "::set-output name=date::$(cat latest-img)"

      - name: Cache Docker images
        uses: ScribeMD/docker-cache@0.2.6
        with: # can't get digest :-(
          key: zephyr-build-img-${{ steps.latest-zephyr-img.digest }}

But the value looks empty.

Then Github informed me that set-output is deprecated. So I followed the new documentation and switched to GITHUB_OUTPUT: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

      - name: get digest of latest ghcr.io/zephyrproject-rtos/ci
        id: latest-zephyr-img
        run: |
          docker manifest inspect ghcr.io/zephyrproject-rtos/ci:latest -v | jq -r '.[0].Descriptor.digest' | tee latest-img
          printf 'digest=%s\n' "$(cat latest-img)" >> "${GITHUB_OUTPUT}"

Still empty: https://github.com/thesofproject/sof/actions/runs/3851840976/jobs/6563431229
(thesofproject/sof#6918)

Is this problem specific to docker-cache?

No, Actions don't have the power to control their own inputs so far as I am aware, which can be shown by attempting to use the variable from a trivial run step. My wild guess is that the colon in the value of the variable is creating issues, so maybe you need an extra set of quotes?

Thanks, I'll try "harder" tomorrow.

Edit: actually I won't because of #304

In case this helps anyone else facing a similar issue, the problem was that steps.latest-zephyr-img.digest is not defined. You meant steps.latest-zephyr-img.outputs.digest.