FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
setup-python/src/cache-save.ts at main · eFog-R/setup-python · GitHub
eFog-R
/
setup-python
Public
forked from
actions/setup-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
setup-python
/
src
/
cache-save.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
87 lines (71 loc) · 2.28 KB
Breadcrumbs
setup-python
/
src
/
cache-save.ts
Copy path
File metadata and controls
87 lines (71 loc) · 2.28 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import
*
as
core
from
'@actions/core'
;
import
*
as
cache
from
'@actions/cache'
;
import
fs
from
'fs'
;
import
{
State
}
from
'./cache-distributions/cache-distributor'
;
// Added early exit to resolve issue with slow post action step:
// - https://github.com/actions/setup-node/issues/878
// https://github.com/actions/cache/pull/1217
export
async
function
run
(
earlyExit
?:
boolean
)
{
try
{
const
cache
=
core
.
getInput
(
'cache'
)
;
if
(
cache
)
{
await
saveCache
(
cache
)
;
if
(
earlyExit
)
{
process
.
exit
(
0
)
;
}
}
}
catch
(
error
)
{
const
err
=
error
as
Error
;
core
.
setFailed
(
err
.
message
)
;
}
}
async
function
saveCache
(
packageManager
:
string
)
{
const
cachePathState
=
core
.
getState
(
State
.
CACHE_PATHS
)
;
if
(
!
cachePathState
)
{
core
.
warning
(
'Cache paths are empty. Please check the previous logs and make sure that the python version is specified'
)
;
return
;
}
const
cachePaths
=
JSON
.
parse
(
cachePathState
)
as
string
[
]
;
core
.
debug
(
`paths for caching are
${
cachePaths
.
join
(
', '
)
}
`
)
;
if
(
!
isCacheDirectoryExists
(
cachePaths
)
)
{
core
.
warning
(
`Cache folder path is retrieved for
${
packageManager
}
but doesn't exist on disk:
${
cachePaths
.
join
(
', '
)
}
. This likely indicates that there are no dependencies to cache. Consider removing the cache step if it is not needed.`
)
;
return
;
}
const
primaryKey
=
core
.
getState
(
State
.
STATE_CACHE_PRIMARY_KEY
)
;
const
matchedKey
=
core
.
getState
(
State
.
CACHE_MATCHED_KEY
)
;
if
(
!
primaryKey
)
{
core
.
warning
(
'Error retrieving key from state.'
)
;
return
;
}
else
if
(
matchedKey
===
primaryKey
)
{
// no change in target directories
core
.
info
(
`Cache hit occurred on the primary key
${
primaryKey
}
, not saving cache.`
)
;
return
;
}
let
cacheId
=
0
;
try
{
cacheId
=
await
cache
.
saveCache
(
cachePaths
,
primaryKey
)
;
}
catch
(
err
)
{
const
message
=
(
err
as
Error
)
.
message
;
core
.
info
(
`[warning]
${
message
}
`
)
;
return
;
}
if
(
cacheId
==
-
1
)
{
return
;
}
core
.
info
(
`Cache saved with the key:
${
primaryKey
}
`
)
;
}
function
isCacheDirectoryExists
(
cacheDirectory
:
string
[
]
)
{
const
result
=
cacheDirectory
.
reduce
(
(
previousValue
,
currentValue
)
=>
{
return
previousValue
||
fs
.
existsSync
(
currentValue
)
;
}
,
false
)
;
return
result
;
}
run
(
true
)
;
Back
|
FazBrowse Home
|
New Git URL