'Share cache between distinct jobs

I have two jobs in the same GitHub Actions workflow. The first one creates a file and the second one expects to find this file in the same directory where the first one created it.

I thought I can use actions/cache@v3 for it like so:

jobs:
  job1:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: actions/cache@v3
        with:
          path: some_dir/my_file
          key: my_file

      ... (create the file)

  job2:
    needs: job1
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      - uses: actions/cache@v3
        with:
          path: some_dir/my_file
          key: my_file

      ... (use the file)

GitHub Action says that cache is restored successfully in job2, however, in job2 I can't find my_file in the directory where I expect it to be. What is the problem?



Solution 1:[1]

So, the problem was actually that I used to look for cache in path relative to custom working-directory while steps with uses are not influenced by this setting, so I had to use absolute paths for actions/cache.

Now it works as expected.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eyjafl