@@ -5,56 +5,71 @@ import { info, warning } from "../utils/io/io"
5
5
import { debug } from "@actions/core"
6
6
import path from "path"
7
7
import { isGitHubCI } from "../utils/env/isci"
8
- import { cacheDependencies } from "./actions_cache"
8
+ import { isCacheFeatureAvailable , IS_LINUX , IS_WINDOWS } from "setup-python/src/utils"
9
+ import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
9
10
10
11
function isPyPyVersion ( versionSpec : string ) {
11
12
return versionSpec . startsWith ( "pypy" )
12
13
}
13
14
14
- // function resolveVersionInput(version: string): string {
15
- // let versionFile = getInput("python-version-file")
15
+ /*
16
+ function resolveVersionInput(version: string): string {
17
+ let versionFile = getInput("python-version-file")
16
18
17
- // if (version && versionFile) {
18
- // warning("Both python-version and python-version-file inputs are specified, only python-version will be used")
19
- // }
19
+ if (version && versionFile) {
20
+ warning("Both python-version and python-version-file inputs are specified, only python-version will be used")
21
+ }
20
22
21
- // if (version) {
22
- // return version
23
- // }
23
+ if (version) {
24
+ return version
25
+ }
24
26
25
- // versionFile = versionFile || ".python-version"
26
- // if (!existsSync(versionFile)) {
27
- // throw new Error(`The specified python version file at: ${versionFile} does not exist`)
28
- // }
29
- // version = readFileSync(versionFile, "utf8")
30
- // info(`Resolved ${versionFile} as ${version}`)
27
+ versionFile = versionFile || ".python-version"
28
+ if (!existsSync(versionFile)) {
29
+ throw new Error(`The specified python version file at: ${versionFile} does not exist`)
30
+ }
31
+ version = readFileSync(versionFile, "utf8")
32
+ info(`Resolved ${versionFile} as ${version}`)
31
33
32
- // return version
33
- // }
34
+ return version
35
+ }
36
+ */
37
+
38
+ export async function cacheDependencies ( cache : string , pythonVersion : string ) {
39
+ const cacheDependencyPath = undefined // core.getInput("cache-dependency-path") || undefined
40
+ const cacheDistributor = getCacheDistributor ( cache , pythonVersion , cacheDependencyPath )
41
+ await cacheDistributor . restoreCache ( )
42
+ }
34
43
35
44
export async function setupActionsPython ( version : string , _setupDir : string , arch : string ) {
36
- if ( process . env . AGENT_TOOLSDIRECTORY ?. trim ( ) ) {
37
- debug ( `Python is expected to be installed into AGENT_TOOLSDIRECTORY=${ process . env . AGENT_TOOLSDIRECTORY } ` )
45
+ // According to the README windows binaries do not require to be installed
46
+ // in the specific location, but Mac and Linux do
47
+ if ( ! IS_WINDOWS && ! process . env . AGENT_TOOLSDIRECTORY ?. trim ( ) ) {
48
+ if ( IS_LINUX ) {
49
+ process . env . AGENT_TOOLSDIRECTORY = "/opt/hostedtoolcache"
50
+ } else {
51
+ process . env . AGENT_TOOLSDIRECTORY = "/Users/runner/hostedtoolcache"
52
+ }
38
53
process . env . RUNNER_TOOL_CACHE = process . env . AGENT_TOOLSDIRECTORY
39
- } else {
40
- debug ( `Python is expected to be installed into RUNNER_TOOL_CACHE==${ process . env . RUNNER_TOOL_CACHE } ` )
41
54
}
55
+ debug ( `Python is expected to be installed into RUNNER_TOOL_CACHE=${ process . env . RUNNER_TOOL_CACHE } ` )
42
56
// const version = resolveVersionInput(versionGiven)
43
57
if ( version ) {
44
58
let pythonVersion : string
45
59
if ( isPyPyVersion ( version ) ) {
46
- const installed = await findPyPyVersion ( version , arch )
60
+ const installed = await findPyPyVersion ( version , arch , true )
47
61
pythonVersion = `${ installed . resolvedPyPyVersion } -${ installed . resolvedPythonVersion } `
48
62
info ( `Successfully set up PyPy ${ installed . resolvedPyPyVersion } with Python (${ installed . resolvedPythonVersion } )` )
49
63
} else {
50
- const installed = await useCpythonVersion ( version , arch )
64
+ const installed = await useCpythonVersion ( version , arch , true )
51
65
pythonVersion = installed . version
52
66
info ( `Successfully set up ${ installed . impl } (${ pythonVersion } )` )
53
67
}
54
68
55
- const cache = "pip" // core.getInput("cache") // package manager used for caching
56
-
57
- await cacheDependencies ( cache , pythonVersion )
69
+ if ( isCacheFeatureAvailable ( ) ) {
70
+ const cache = "pip" // core.getInput("cache") // package manager used for caching
71
+ await cacheDependencies ( cache , pythonVersion )
72
+ }
58
73
}
59
74
60
75
if ( isGitHubCI ( ) ) {
0 commit comments