Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robstar's avatar
Level 50

GitHub Actions / Sanity

I have a semi popular Laravel package with a basic GitHub actions file, see https://github.com/f9webltd/laravel-api-response-helpers/blob/master/.github/workflows/run-tests.yml.

In an attempt to speed up build times I'm using the actions/cache@v4 action to cache composer dependencies foir future runs.

I'm missing something because when each build completes I see the following warning:

Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.

Sample run at https://github.com/f9webltd/laravel-api-response-helpers/actions/runs/8248995028/job/22560479342

Can anyone help restore my sanity as I'm missing something obvious here :)

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like the issue you're encountering is related to the cache path not being correctly specified or the path not existing when the cache action attempts to save the cache. Here's a step-by-step guide to ensure your caching works correctly:

  1. Make sure you're using the correct path for the Composer cache. The default cache directory for Composer is usually ~/.composer on Unix-based systems or C:\Users\<username>\AppData\Local\Composer on Windows. However, when using GitHub Actions, the path might be different.

  2. Update your GitHub Actions workflow file to cache the correct directory. For Composer, you typically want to cache the vendor directory and the Composer cache directory.

Here's an example of how you can set up caching for a Laravel package:

name: Run Tests

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2

    - name: Cache Composer dependencies
      uses: actions/cache@v4
      with:
        path: |
          vendor
          ~/.composer/cache
        key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
        restore-keys: |
          ${{ runner.os }}-composer-

    - name: Install Composer dependencies
      run: composer install --prefer-dist --no-progress --no-suggest

    # ... other steps for setting up PHP, running tests, etc.

In this example, the path key specifies multiple paths to cache. The vendor directory and the ~/.composer/cache directory are included. The key is unique based on the operating system and the hash of the composer.lock file, ensuring that the cache is only used when the dependencies have not changed.

  1. Ensure that the paths you are trying to cache actually exist when the cache action runs. If the vendor directory or the Composer cache directory does not exist at the time of caching, you will receive the "Path Validation Error" warning.

  2. If you're still encountering issues, you can add a step to debug and list the directories before the cache step to ensure they exist:

    - name: List directories
      run: ls -la ~/.composer/cache || echo "Composer cache directory does not exist"

This will output the contents of the Composer cache directory or indicate if it does not exist.

By following these steps, you should be able to resolve the caching issue in your GitHub Actions workflow. If the problem persists, double-check the paths and make sure they are accessible in the GitHub Actions runner environment.

Please or to participate in this conversation.