Cache is restores, but if clause returns wrong assertion

I’ve been caching “node_modules” successfully, as it seems!

Although, when I try the same step process for a dynamically generated directory, as demonstrated bellow (hypothetically, so might have some typos), it:

  • Restores the cache directory
  • The assertion is incorrect, so instead of “cache-hit” to equal truthy, it does not!

I’m finding hard to figure why that is, because the logic I’m following is the one documented in here.

I’m right now going to test, creating the target cache directory before the Cache step, as that might be why its not working, will provide feedback afterwards.

Any help is appreciated!

Thank you!

name: CI

on:
  pull_request:
    branches: [ main ]

  workflow_dispatch:

jobs:
  build:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2

      - name: Initialise directory to cache
        run: |
          if [ ! -d "./foobarDir" ]; then
            mkdir ./foobarDir
            echo "Created empty directory!"
          fi

      - name: Query Foobar
        run: .sh/query-head-commit.sh
        env:
          PRIVATE_ACCESS_TOKEN: ${{ secrets.PRIVATE_ACCESS_TOKEN }}
          TARGET_BRANCH: feat/foobar

      - name: Cache Foobar
        id: mycache
        uses: actions/cache@v1
        with:
          path: foobarDir
          key: mycache-${{ hashFiles('FOOBAR_HEAD') }}

      - name: Assert cache-hit != 'true'?
        if: steps.mycache.cache-hit != 'true'
        run: |
          echo "There is no CACHE-HIT!"
          if [ ! -f "./foobarDir/foobar.txt" ]; then
            touch ./foobarDir/foobar.txt
            echo "Hello world" > ./foobarDir/foobar.txt
          fi
          cat ./foobarDir/foobar.txt
          cat FOOBAR_HEAD

      - name: Assert cache-hit == 'true'?
        if: steps.mycache.cache-hit == 'true'
        run: echo "That's a CACHE-HIT!"

The issue is in the syntax, it should be:

if: steps.mycache.outputs.cache-hit 

Missed the outputs