Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache doesn't work with github workspace directory #833

Assignees
Labels
bug Something isn't working

Comments

@erwan-joly
Copy link

erwan-joly commented Jun 24, 2022

Hi, I'm trying to cache the whole workspace to fetch it between jobs.
Unfortunately it seems like the local directory can not be cached

Using . doesn't work (it cache 22B)

- name: Cache build folder
        uses: actions/cache@v3
        with:
          key: cs-repo-${{ github.run_number }}-${{ github.run_attempt }}
          path: .

Using ${{ github.workspace }} doesn't work (it also cache 22B)

- name: Cache build folder
        uses: actions/cache@v3
        with:
          key: cs-repo-${{ github.run_number }}-${{ github.run_attempt }}
          path: ${{ github.workspace }}

the only solution I found which work is to list all the files/directory

- name: Cache build folder
        uses: actions/cache@v3
        with:
          key: cs-repo-${{ github.run_number }}-${{ github.run_attempt }}
          path: |
              file1
              file2
              dir1
              dir2
@aparna-ravindra aparna-ravindra added the bug Something isn't working label Jun 24, 2022
@aparna-ravindra
Copy link
Contributor

Thank you for the report. I was able to reproduce this. From the first look, it appears that there is a bug while converting the cache paths to relative paths for compression in the toolkit. I will debug the cause and get back.

Contribution are welcome as this will mostly require changes in actions/toolkit and actions/cache.

@erwan-joly
Copy link
Author

It doesn't seems to be fixed for some reason :/
I've tested with actions/[email protected] both the two version with . and env variable and it still cache 22B @pdotl

@lvpx
Copy link
Contributor

lvpx commented Aug 4, 2022

Hi @erwan-joly , the above version is for actions/cache npm module and not for the actions/cache action. We are yet to merge toolkit changes into the actions/cache. Once done, you should be able to test and use the same. I'll post an update here once done.

@lvpx
Copy link
Contributor

lvpx commented Aug 5, 2022

@erwan-joly ,please test now with the latest version of actions/cache using actions/cache@v3.

@erwan-joly
Copy link
Author

@pdotl I confirm it's now fixed 💯

@khelkun
Copy link

khelkun commented Feb 23, 2023

One should also consider this issue if he has troubles with github.worspace context and cache action as I did:

github.workspace === /home/runner/work/testContainers/testContainers
GITHUB_WORKSPACE === /__w/testContainers/testContainers
runner.workspace === /home/runner/work/testContainers
RUNNER_WORKSPACE === /__w/testContainers

My build job relies on ${{ github.workspace }} to output its result and I want to cache this result and restore it in my publish job. Here is how I made this works:

name: Build

on:
  push:
    tags:
      - '*'
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    container:
      image: mstorsjo/llvm-mingw:latest
    steps:
      - name: build stuff
        run: |
          echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
          echo "github.workspace=${{ github.workspace }}"
          # echo curent working dir which is $GITHUB_WORKSPACE and not ${{ github.workspace }}.
          echo "current working dir:"
          pwd

          # cd to build dir.
          # for the example, creates a my_build_dir and cd to it.
          cd my_build_dir

          # run build command that generates the buil result in ${{ github.workspace }}/output.
          # for the example, creates the output dir and touch a result.out file in it.
          mkdir -p ${{ github.workspace }}/output
          touch ${{ github.workspace }}/output/result.out

          # back to $GITHUB_WORKSPACE
          cd ..
          cp -r ${{ github.workspace }}/output $GITHUB_WORKSPACE
          ls -l $GITHUB_WORKSPACE

      - name: Cache build output
        id: cache-save-build-ouput
        uses: actions/cache/save@v3
        with:
          path: |
            ./output
          key: ${{ runner.os }}-build-output-run_${{ github.run_id }}
          enableCrossOsArchive: true


  publish:
    runs-on: ubuntu-latest
    image: mstorsjo/llvm-mingw:latest
    needs: build
    steps:
      - name: Restore build ouput cache
        uses: actions/cache/restore@v3
        id: cache-restore-build-ouput
        with:
          path: |
            ./output
          key: ${{ runner.os }}-build-output-run_${{ github.run_id }}
          enableCrossOsArchive: true
          fail-on-cache-miss: true

      - name: archive
        run: |
          echo "GITHUB_WORKSPACE=$GITHUB_WORKSPACE"
          echo "github.workspace=${{ github.workspace }}"
          # echo curent working dir which is $GITHUB_WORKSPACE and not ${{ github.workspace }}.
          echo "current working dir:"
          pwd

          echo "restored cache output dir:"
          ls -l ./ouput          

Note that restoring a cache in a container image different from the one that saved the cache may fail because the comrpession tool (tar) may be different. For example using image: alpine:latest container in my publish job fails this way:

/bin/tar: unrecognized option: P

On the other hand, using no container on the my publish job fails this way:

##[debug]No matching cache found for cache key 'Linux-build-output-run_4252492458', version '864e6dbc1f60e04c96ce9a7e3cc1dc27a256109377aae3de699034043992ea42 and scope refs/tags/v4.2.1-full. There exist one or more cache(s) with similar key but they have different version or scope. See more info on cache matching here: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key 
##[debug]Other caches with similar key:
##[debug]Cache Key: Linux-build-output-run_4252492[45](https://github.com/khelkun/ffmpeg-wos-arm64-build/actions/runs/4252492458/jobs/7396194685#step:2:46)8, Cache Version: ea8764569ab4d245f2db7a85367253cd303504ee4289[46](https://github.com/khelkun/ffmpeg-wos-arm64-build/actions/runs/4252492458/jobs/7396194685#step:2:47)df7d21a697b0c7812f, Cache Scope: refs/tags/v4.2.1-full, Cache Created: 2023-02-23T12:16:30.7133333Z
##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''
Error: Failed to restore cache entry. Exiting as fail-on-cache-miss is set. Input key: Linux-build-output-run_4252492458

And using the enableCrossOsArchive: true in the actions/cache/restore@v3 does not fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment