generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.ts
49 lines (41 loc) · 1.19 KB
/
main.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
import { setFailed, getInput, warning } from '@actions/core'
import { findUv } from './find'
import { getInputs, isCacheAllowed } from './inputs'
import { activateVenv, createVenv } from './venv'
import { setupCache, restoreCache, saveCache, minimizeCache } from './cache'
async function run(): Promise<void> {
try {
const inputs = getInputs()
const cacheDir = getInput('uv-cache-dir')
if (cacheDir) {
process.env.UV_CACHE_DIR = cacheDir
}
const shouldCache = inputs.cache && isCacheAllowed(inputs.version)
if (shouldCache) {
await setupCache()
await restoreCache()
} else if (inputs.cache && !isCacheAllowed(inputs.version)) {
warning(
'Caching is not supported for uv versions below 0.3.0. Skipping cache operations.'
)
}
await findUv(inputs.version)
if (inputs.venv) {
await createVenv(inputs.venv)
await activateVenv(inputs.venv)
}
if (shouldCache) {
await saveCache()
await minimizeCache()
}
} catch (error) {
setFailed(errorAsMessage(error))
}
}
function errorAsMessage(error: unknown) {
if (error instanceof Error) {
return error.message
}
return String(error)
}
run()