Using uvx in GitHub Actions in a cache-friendly way
Developers using Python tools in GitHub Actions often face slow workflows because tools installed via uvx must be downloaded from PyPI every time the job runs. This process consumes time and bandwidth by repeatedly fetching the same dependencies.
To solve this, developers can set a specific environment variable called UV_EXCLUDE_NEWER to a fixed date at the beginning of their workflow. By incorporating this date into the GitHub Actions cache key, the system stores the installed tools and their dependencies. This allows subsequent workflow runs to retrieve the tools from the cache instead of downloading them from the internet.
This method ensures that tools remain consistent across runs while still allowing for easy updates. When a developer wants to upgrade to newer versions of their tools, they simply update the date in the environment variable, which forces the cache to refresh. This approach balances the need for fast, reliable automation with the flexibility to manage tool versions effectively.