After submitting a support ticket, it was suggested I report this issue here.
I have a workflow that runs iOS tests, using caches for both Carthage and Cocoapods dependencies. For the Carthage dependencies, the cache key expression looks like this:
${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
Recently a workflow failed with this error:
Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.2 compiler
because the cache was used but the Swift version on the MacOS runner had been updated.
I believe that the solution to this is to include the Swift version in the cache key expression, just like runner.os and the hash of Cartfile.resolved. Running something like swift --version will output the version and I was thinking of using this in a step's output so that it could be read as input in the cache key but I understand that cache key expressions are evaluated before the workflow is executed.
So it would be great to either get access to the Swift version in a similar fashion to runner.os or to be able to use step outputs as inputs in the cache key expression.
Running something like
swift --versionwill output the version and I was thinking of using this in a step's output so that it could be read as input in the cache key
This should work
but I understand that cache key expressions are evaluated before the workflow is executed.
These cache key expressions are evaluated before the step is executed, not the workflow itself.
Thanks for this! That sounds perfect. It seems like I got some incorrect information from the support staff (otherwise it was excellent). Will let them know.
Will also try to put a sample public repo together using this technique and share here.
I ran into this looking for the exact same thing.
It would be nice to add an example with an arbitrary command output used in the cache key (a version or anything else).
Thanks.
馃憢 Thanks for the feedback, I've opened a PR to add an example of this case: https://github.com/actions/cache/pull/312