question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Path Validation Error when caching on container jobs

See original GitHub issue

When I use the cache action with a container job, the cache is not saved during the post cache step and instead I get the following error

Post job cleanup.
/usr/bin/docker exec  ecc19d4d[2](https://github.com/daoudi-mohammed/spring-boilerplate/runs/6771275062?check_suite_focus=true#step:10:2)b410eadd[3](https://github.com/daoudi-mohammed/spring-boilerplate/runs/6771275062?check_suite_focus=true#step:10:3)082d7a7d5d22cc782f29dfba69ac4a8edc83090a10843c sh -c "cat /etc/*release | grep ^ID"
Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.

Here is the code for my job

jobs:
  unit-tests:
    
    runs-on: ubuntu-latest

    container: openjdk:17-jdk-alpine

    steps:
      - name: Setup git
        working-directory: ""
        run: |
          apk add -q --no-cache --no-progress git yq tar
          git config --global --add safe.directory $GITHUB_WORKSPACE

      - name: Check out repository code
        uses: actions/checkout@v2

      - name: Cache maven packages
        uses: actions/cache@v3
        with:
          path: |
            ${{ github.workspace }}/.m2/repository
          key: test

      - name: Run liquibase update
        run: |
          mkdir -pv ${{ github.workspace }}/.m2/repository/
          echo "hello" > ${{ github.workspace }}/.m2/repository/hello.txt

I tried replacing the ${{ github.workspace }} with it’s exact value (absolute path) but nothing worked.

However when I use a hardcoded path that has nothing to do with ${{ github.workspace }} it works

with:
          path: |
            /test/.m2/repository
          key: test

      - name: Run liquibase update
        run: |
          mkdir -pv test/.m2/repository/
          echo "hello" > test/.m2/repository/hello.txt

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Iduoadcommented, Jun 8, 2022

It definitely helps! Thank you so much @kotewar

1reaction
kotewarcommented, Jun 9, 2022

This is a mixed scenario where the workflow is running on ubuntu image sometimes, and on the container the rest of the times. That’s why ${{ github.workspace }} is sometimes evaluated as /__w and /home/runner/work/repo-name/repo-name the rest of the times. To investigate the issue, we went ahead to understand the behaviour of actions when ran in a container. If interested to know, please refer the workflow to understand the same. The logs will give you a better idea of the same.

To conclude our understandings, here’s what we found -

  1. Containers will always have ${{ github.workspace }} as /__w. If anything is running with /home/runner/work/repo-name/repo-name as current working directory, its outside your container in the ubuntu-latest image (or base image for that matter).
  2. To run actions cache inside the container for java application, the appropriate location of .m2 folder must be known. After investigation, it turns out that .m2 folder in openjdk:17-jdk-alpine is actually present at /root/.m2/repository location. So this should actually be the path that must be used to cache the /.m2/repository folder. Refer this
  3. After the /.m2 folder is located, it should be referred in path parameter of the cache action.

Sample code to get .m2 folder location and setting it in the appropriate location.

     - id: cache-path
        run: | 
          echo "::set-output name=dir::$(mvn help:evaluate -Dexpression=settings.localRepository | grep 'm2/repository')"
      - name: Cache maven packages
        id: cache
        uses: actions/cache@v3
        with:
          path: |
            ${{ steps.cache-path.outputs.dir }}
          key: test_100

Please try using this and see if you get the expected results. You can refer this workflow. Hope this helps! 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Path Validation Error when caching on container jobs - IssueHint
When I use the cache action with a container job, the cache is not saved during the post cache step and instead I...
Read more >
Path Validation Error when caching on container jobs
Path Validation Error when caching on container jobs.
Read more >
Error to cache the deps inside a docker container · Issue #15174
I'm using Deno v 1.21.3 and I'm trying to build a docker image for my application: FROM ubuntu:20.04 # install curl RUN apt-get...
Read more >
Cache created in `ubuntu-latest` cannot be restored in Docker ...
It seems that the @actions/cache job silently fails if there is no zstd binary available in the PATH in the container that you...
Read more >
Document - Container Launch error with Distributed cache files fails ...
The job works fine in the Job Tracker/Task Tracker environment because full path is being used for the target while creating the symlinks....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found