File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change 11import PipCache from './pip-cache' ;
22import PipenvCache from './pipenv-cache' ;
33import PoetryCache from './poetry-cache' ;
4+ import UvCache from './uv-cache' ;
45
56export enum PackageManagers {
67 Pip = 'pip' ,
78 Pipenv = 'pipenv' ,
8- Poetry = 'poetry'
9+ Poetry = 'poetry' ,
10+ Uv = 'uv'
911}
1012
1113export function getCacheDistributor (
@@ -20,6 +22,8 @@ export function getCacheDistributor(
2022 return new PipenvCache ( pythonVersion , cacheDependencyPath ) ;
2123 case PackageManagers . Poetry :
2224 return new PoetryCache ( pythonVersion , cacheDependencyPath ) ;
25+ case PackageManagers . Uv :
26+ return new UvCache ( pythonVersion , cacheDependencyPath ) ;
2327 default :
2428 throw new Error ( `Caching for '${ packageManager } ' is not supported` ) ;
2529 }
Original file line number Diff line number Diff line change 1+ import * as glob from '@actions/glob' ;
2+ import * as os from 'os' ;
3+ import * as path from 'path' ;
4+
5+ import CacheDistributor from './cache-distributor' ;
6+
7+ export default class UvCache extends CacheDistributor {
8+ constructor (
9+ private pythonVersion : string ,
10+ protected patterns : string = '**/requirements.txt'
11+ ) {
12+ super ( 'uv' , patterns ) ;
13+ }
14+
15+ protected async getCacheGlobalDirectories ( ) {
16+ if ( process . platform === 'win32' ) {
17+ // `LOCALAPPDATA` should always be defined,
18+ // but we can't just join `undefined`
19+ // into the path in case it's not.
20+ return [
21+ path . join ( process . env [ 'LOCALAPPDATA' ] ?? os . homedir ( ) , 'uv' , 'cache' )
22+ ] ;
23+ }
24+ return [ path . join ( os . homedir ( ) , '.cache/uv' ) ] ;
25+ }
26+
27+ protected async computeKeys ( ) {
28+ const hash = await glob . hashFiles ( this . patterns ) ;
29+ const primaryKey = `${ this . CACHE_KEY_PREFIX } -${ process . env [ 'RUNNER_OS' ] } -python-${ this . pythonVersion } -${ this . packageManager } -${ hash } ` ;
30+ const restoreKey = undefined ;
31+ return {
32+ primaryKey,
33+ restoreKey
34+ } ;
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments