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

Gradle plugin always invalidates configuration cache on github actions, when ratchetFrom is set #2249

Open
5 of 6 tasks
superxiao opened this issue Sep 6, 2024 · 4 comments

Comments

@superxiao
Copy link

superxiao commented Sep 6, 2024

If you are submitting a bug, please include the following:

  • summary of problem
  • Gradle or Maven version
  • spotless version
  • operating system and version
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
  • copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace

Gradle: 8.10
Spotless gradle plugin: 7.0.0.BETA2
When the spotless gradle plugin is used, configuration cache on github actions using setup-gradle usually fails with the following message:

Calculating task graph as configuration cache cannot be reused because the file system entry '.git/refs/remotes/origin/.probe-8edb64c1-4909-420b-b493-b18d007910f4' has been removed.

Spotless config:

spotless {
    ratchetFrom("origin/main")
    java {
        googleJavaFormat()
    }
}

Without ratchetFrom, it's this,

Reusing configuration cache.

It seems the spotpless plugin introduces git and the entire .git folder as an input for configuration cache of some sort, with ratchetFrom.

This issue may be related.

Here is a sample repo where this can reproduce. You would run the .github/workflows/gradle.xml (can be dispatched manually or on pull request/push) action once to generate cache from the setup-gradle action which is invoked inside. A subsequent run should reuse configuration cache, but does not. When you remove ratchetFrom, clear github cache, and run the action twice, the configuration cache is reused.

@superxiao superxiao changed the title Gradle plugin always invalidates configuration cache on github actions, when ratchetFrom is set Gradle plugin always invalidates configuration cache on github actions Sep 8, 2024
@superxiao superxiao changed the title Gradle plugin always invalidates configuration cache on github actions Gradle plugin always invalidates configuration cache on github actions, when ratchetFrom is set Sep 9, 2024
@superxiao
Copy link
Author

superxiao commented Oct 25, 2024

I dealt with this issue by turning off ratchetFrom for CI:

spotless {
  if (System.getenv("CI") == null) {
    ratchetFrom("origin/develop")
  }
...
}

And then have a dedicated job to run static analysis (including spotless), with explicitly specified files:

      - name: Get changed files
       id: changed-files
       uses: tj-actions/changed-files@v45
       with:
         files: src/**/*.java
         separator: ","

      - name: Run static analysis
       run: |
         ./gradlew checkstyleMain checkstyleTest spotlessCheck \
         -PspotlessFiles=${{ steps.changed-files.outputs.all_changed_files }}

Note, if the changes files are different, this job will not reuse configuration cache (as it should not). However, if changed files are the same, configuration cache is reused; and all other jobs (e.g. running tests) can skip spotless -x spotlessApply and reuse configuration cache.

@nedtwigg
Copy link
Member

This may be fixed in 7.0.0.BETA4, please confirm if this is true.

@superxiao
Copy link
Author

I upgraded to 7.0.0.BETA4 and the issue still reproduces. I manually triggered the action once to generate cache, and trigger it again without any new commit, and it does not reuse the configuration cache. All other steps are FROM-CACHE.

I'm happy to close this issue though for the workaround I posted above. In the end it just makes CI build a bit slower, nothing too bad.

@nedtwigg
Copy link
Member

Calculating task graph as configuration cache cannot be reused because the file system entry '.git/refs/remotes/origin/.probe-8edb64c1-4909-420b-b493-b18d007910f4' has been removed.

Thanks for opening this issue. This is a strange message, and makes it hard to tell if this is a bug in Spotless or Gradle...

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

No branches or pull requests

2 participants