fix: use dynamic imports to load the cache files

This commit is contained in:
Amin Yahyaabadi 2022-04-18 18:36:48 -07:00
parent 0f42dc4b13
commit 8705b57937
6 changed files with 19 additions and 11 deletions

2
dist/cache-factory.8ad1a0d1.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/cache-factory.8ad1a0d1.js.map vendored Normal file

File diff suppressed because one or more lines are too long

2
dist/cache.32a23f6d.js vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/cache.32a23f6d.js.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -5,19 +5,11 @@ import { info, warning } from "../utils/io/io"
import * as core from "@actions/core" import * as core from "@actions/core"
import path from "path" import path from "path"
import { isGitHubCI } from "../utils/env/isci" import { isGitHubCI } from "../utils/env/isci"
import { isCacheFeatureAvailable } from "setup-python/src/utils"
import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
function isPyPyVersion(versionSpec: string) { function isPyPyVersion(versionSpec: string) {
return versionSpec.startsWith("pypy-") return versionSpec.startsWith("pypy-")
} }
async function cacheDependencies(cache: string, pythonVersion: string) {
const cacheDependencyPath = undefined // core.getInput("cache-dependency-path") || undefined
const cacheDistributor = getCacheDistributor(cache, pythonVersion, cacheDependencyPath)
await cacheDistributor.restoreCache()
}
export async function setupActionsPython(version: string, _setupDir: string, arch: string) { export async function setupActionsPython(version: string, _setupDir: string, arch: string) {
if (process.env.AGENT_TOOLSDIRECTORY?.trim()) { if (process.env.AGENT_TOOLSDIRECTORY?.trim()) {
core.debug(`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env.AGENT_TOOLSDIRECTORY}`) core.debug(`Python is expected to be installed into AGENT_TOOLSDIRECTORY=${process.env.AGENT_TOOLSDIRECTORY}`)
@ -41,9 +33,9 @@ export async function setupActionsPython(version: string, _setupDir: string, arc
} }
const cache = "pip" // core.getInput("cache") // package manager used for caching const cache = "pip" // core.getInput("cache") // package manager used for caching
if (isCacheFeatureAvailable()) {
await cacheDependencies(cache, pythonVersion) const { cacheDependencies } = await import("./cache")
} await cacheDependencies(cache, pythonVersion)
} }
} catch (err) { } catch (err) {
core.setFailed((err as Error).message) core.setFailed((err as Error).message)

10
src/python/cache.ts Normal file
View File

@ -0,0 +1,10 @@
import { isCacheFeatureAvailable } from "setup-python/src/utils"
import { getCacheDistributor } from "setup-python/src/cache-distributions/cache-factory"
export async function cacheDependencies(cache: string, pythonVersion: string) {
if (isCacheFeatureAvailable()) {
const cacheDependencyPath = undefined // core.getInput("cache-dependency-path") || undefined
const cacheDistributor = getCacheDistributor(cache, pythonVersion, cacheDependencyPath)
await cacheDistributor.restoreCache()
}
}