GitHub Cache with Maven project in subdirectory

I had the following configuration of my GH Action workflow of a simple Maven project.

name: Java CI

on:
  pull_request:
    branches:
      - master

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Cache Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: Verify with Maven
        run: mvn -B -e -ff clean verify

Everything used to work, till I move the Maven project into a code subdirectory:

name: Java CI

on:
  pull_request:
    paths:
      - code/**
    branches:
      - master

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      - name: Cache Maven repository
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: Verify with Maven
        run: mvn -B -e -ff clean verify --file code/pom.xml

Now in the log I see the cache step says Cache not found for input keys: Linux-maven-xxxxxxx, Linux-maven-.

Does anyone know why the cache is not working with the project in a subdirectory?
Thanks.

Hi @akefirad,

Glad to see you in Github Community Forum!

I followed your description and copied your code to my repo, however cache works fine after i move the project to subdirectory code. My workflow here, and screenshot below:

The cache miss typically appears in below situation:

  1. It’s first time to run the workflow, and never cached before.
  2. The key or restore key doesn’t match.

And GitHub will remove any cache entries that have not been accessed in over 7 days. Did you cache it recently?

Please kindly have a double check and if the issue persists, please share your repo/sample repo for further investigation.

Thanks

I’m pretty sure I checked it multiple times and didn’t see the cache being used. But you’re right. Now it’s working. Not sure if it was really because of #1 or #2. Sorry for the bother. Thanks.