Possible to get specific os version for cache keys?

We use {{ runner.os }} in our cache keys, like most of the docs and examples I’ve seen around the internet. When ubuntu-latest was updated from 18 to 20, the build failed and I was surprised to see that it was because the cache wasn’t busted. Looking into it, {{ runner.os }} returns “Linux” (or “macOS” or similar), so it didn’t change even though our OS did. I would prefer to include the actual os version (e.g. ubuntu-20-04 or similar) in my cache keys so that the cache is busted when we change the os version. After looking around a bit, I don’t see an easy way to do this, but it feels like I’m missing something obvious here. Anyone have any leads?


Hi, I’m not quite sure if we have a workaround for this. Can we ask that you open an issue here if you have not already?

The maintainers of actions/cache may have a workaround.

With that being said, if other GitHub users reading this have found additional workarounds, we’d be grateful if you shared them with us!

Thanks for the nudge! I opened an issue here: Possible to use specific OS version for cache keys? · Issue #543 · actions/cache · GitHub

Quoting myself from the linked GitHub issue for the sake of anyone who may be watching this thread but not the associated issue:

This isn’t glamorous, but you can use ${{ matrix.os }} as the value of runs-on, and include it in the cache key provided that you define strategy.matrix.os to a suitable array of runners (e.g., [ubuntu-20.04]) as documented by Workflow syntax for GitHub Actions - GitHub Docs.