generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinputs.ts
73 lines (62 loc) · 1.86 KB
/
inputs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { getInput, notice, warning } from '@actions/core'
import semver from 'semver'
export interface Inputs {
version: string | null
venv: string | null
cache: boolean
}
export function getInputs(): Inputs {
const version = getVersionInput('uv-version')
return {
version,
venv: getVenvInput('uv-venv'),
cache: getCacheInput('uv-cache', version)
}
}
export function getVersionInput(name: string): string | null {
const version = getInput(name)
if (!version || version.toLowerCase() === 'latest') {
notice('Using latest uv version')
return null
}
const coerced = semver.coerce(version)
if (!coerced) {
throw new Error(`Passed uv version '${version}' is not valid`)
} else if (!semver.satisfies(coerced, '>=0.3.0')) {
warning(
`Passed uv version '${coerced}' is less than 0.3.0. Caching will be disabled.`
)
}
warning(`Using uv version ${version}. This may not be the latest version.`)
return version.trim()
}
export function getVenvInput(name: string): string | null {
const venv = getInput(name)
if (!venv) {
return null
}
return venv.trim()
}
export function getCacheInput(name: string, version: string | null): boolean {
const cache = getInput(name)
const cacheRequested = cache.toLowerCase() === 'true'
if (cacheRequested && version) {
const coerced = semver.coerce(version)
if (coerced && semver.satisfies(coerced, '>=0.3.0')) {
return true
} else {
warning(
'Cache requested but uv version is less than 0.3.0. Caching will be disabled.'
)
return false
}
}
return cacheRequested && version === null // Allow caching for 'latest' version
}
export function isCacheAllowed(version: string | null): boolean {
if (!version) {
return true
}
const coerced = semver.coerce(version)
return coerced ? semver.satisfies(coerced, '>=0.3.0') : false
}