actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.39k stars 1.17k forks source link

Is it possible to share cache between github hosted and self-hosted runners? #1168

Closed paulo9mv closed 1 year ago

paulo9mv commented 1 year ago

I want to save the cache running in ubuntu-latest runner. Then restore that cache in a self-hosted runner, which is Ubuntu also.

On my tests it didn't work even setting enableCrossOsArchive: true. If the cache is created on a ubuntu-latest, it's restored successfully in another ubuntu-latest.

Is this possible to be achieved? Thanks in advance

paulo9mv commented 1 year ago

After some tests I realised I was messing with the paths, that's why it wasn't recognizing the cache hit. Now it's working.

skjnldsv commented 1 year ago

@paulo9mv so you were successful? Do you have some code to share? :) I'm struggling with this :bow:

paulo9mv commented 1 year ago

Hey @skjnldsv , unfortunately I don't have and I couldn't make it work after this comment, as I initially thought ):

I got stuck with this detail on the documentation, about compression (https://github.com/actions/cache#cache-version):

Cache version is a hash [generated](https://github.com/actions/toolkit/blob/500d0b42fee2552ae9eeb5933091fe2fbf14e72d/packages/cache/src/internal/cacheHttpClient.ts#L73-L90) for a combination of compression tool used (Gzip, Zstd, etc. based on the runner OS) and the path of directories being cached. If two caches have different versions, they are identified as unique caches while matching. This, for example, means that a cache created on a windows-latest runner can't be restored on ubuntu-latest as cache Versions are different.

The self-hosted and ubuntu-latest were using different compression tools, so they couldn't share cache ): I was not able to make both use the same algorithm, so in the end, I'm generating and consuming cache on the same runners in my entire pipeline.

skjnldsv commented 1 year ago

I opened a ticket about this https://github.com/actions/toolkit/issues/1433

The root cause is the different paths