From f36c8371b98a48dfb7d9d25b5080236e2d1e806b Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 9 Jun 2025 13:39:53 +0530 Subject: [PATCH 1/8] ehnace cache dependency path handling --- __tests__/setup-python.test.ts | 104 +++++++++++++++++++++++++++++++++ dist/setup/index.js | 30 ++++++++++ docs/advanced-usage.md | 2 +- src/setup-python.ts | 38 +++++++++++- 4 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 __tests__/setup-python.test.ts diff --git a/__tests__/setup-python.test.ts b/__tests__/setup-python.test.ts new file mode 100644 index 000000000..5d68482b9 --- /dev/null +++ b/__tests__/setup-python.test.ts @@ -0,0 +1,104 @@ +import * as core from '@actions/core'; +import * as fs from 'fs'; +import * as path from 'path'; +import {cacheDependencies} from '../src/setup-python'; +import {getCacheDistributor} from '../src/cache-distributions/cache-factory'; + +jest.mock('fs', () => { + const actualFs = jest.requireActual('fs'); + return { + ...actualFs, + copyFileSync: jest.fn(), + existsSync: jest.fn(), + mkdirSync: jest.fn(), + promises: { + access: jest.fn(), + writeFile: jest.fn(), + appendFile: jest.fn() + } + }; +}); +jest.mock('@actions/core'); +jest.mock('../src/cache-distributions/cache-factory'); + +const mockedFs = fs as jest.Mocked; +const mockedCore = core as jest.Mocked; +const mockedGetCacheDistributor = getCacheDistributor as jest.Mock; + +describe('cacheDependencies', () => { + const mockRestoreCache = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + process.env.GITHUB_ACTION_PATH = '/github/action'; + process.env.GITHUB_WORKSPACE = '/github/workspace'; + + mockedCore.getInput.mockReturnValue('nested/deps.lock'); + + mockedFs.existsSync.mockImplementation((p: any) => { + const pathStr = typeof p === 'string' ? p : p.toString(); + if (pathStr === '/github/action/nested/deps.lock') return true; + if (pathStr === '/github/workspace/nested') return false; // Simulate missing dir + return true; + }); + + mockedFs.copyFileSync.mockImplementation(() => undefined); + mockedFs.mkdirSync.mockImplementation(() => undefined); + mockedGetCacheDistributor.mockReturnValue({restoreCache: mockRestoreCache}); + }); + + it('copies the dependency file and resolves the path with directory structure', async () => { + await cacheDependencies('pip', '3.12'); + + const sourcePath = path.resolve('/github/action', 'nested/deps.lock'); + const targetPath = path.resolve('/github/workspace', 'nested/deps.lock'); + + expect(mockedFs.existsSync).toHaveBeenCalledWith(sourcePath); + expect(mockedFs.mkdirSync).toHaveBeenCalledWith(path.dirname(targetPath), { + recursive: true + }); + expect(mockedFs.copyFileSync).toHaveBeenCalledWith(sourcePath, targetPath); + expect(mockedCore.info).toHaveBeenCalledWith( + `Copied ${sourcePath} to ${targetPath}` + ); + expect(mockedCore.info).toHaveBeenCalledWith( + `Resolved cache-dependency-path: nested/deps.lock` + ); + expect(mockRestoreCache).toHaveBeenCalled(); + }); + + it('warns if the dependency file does not exist', async () => { + mockedFs.existsSync.mockReturnValue(false); + + await cacheDependencies('pip', '3.12'); + + expect(mockedCore.warning).toHaveBeenCalledWith( + expect.stringContaining('does not exist') + ); + expect(mockedFs.copyFileSync).not.toHaveBeenCalled(); + expect(mockRestoreCache).toHaveBeenCalled(); + }); + + it('warns if file copy fails', async () => { + mockedFs.copyFileSync.mockImplementation(() => { + throw new Error('copy failed'); + }); + + await cacheDependencies('pip', '3.12'); + + expect(mockedCore.warning).toHaveBeenCalledWith( + expect.stringContaining('Failed to copy file') + ); + expect(mockRestoreCache).toHaveBeenCalled(); + }); + + it('skips path logic if no input is provided', async () => { + mockedCore.getInput.mockReturnValue(''); + + await cacheDependencies('pip', '3.12'); + + expect(mockedFs.copyFileSync).not.toHaveBeenCalled(); + expect(mockedCore.warning).not.toHaveBeenCalled(); + expect(mockRestoreCache).toHaveBeenCalled(); + }); +}); diff --git a/dist/setup/index.js b/dist/setup/index.js index 4e3f26736..854f94908 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96905,6 +96905,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.cacheDependencies = void 0; const core = __importStar(__nccwpck_require__(7484)); const finder = __importStar(__nccwpck_require__(6843)); const finderPyPy = __importStar(__nccwpck_require__(2625)); @@ -96923,10 +96924,39 @@ function isGraalPyVersion(versionSpec) { function cacheDependencies(cache, pythonVersion) { return __awaiter(this, void 0, void 0, function* () { const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined; + let resolvedDependencyPath = undefined; + if (cacheDependencyPath) { + const actionPath = process.env.GITHUB_ACTION_PATH || ''; + const workspace = process.env.GITHUB_WORKSPACE || process.cwd(); + const sourcePath = path.resolve(actionPath, cacheDependencyPath); + const relativePath = path.relative(actionPath, sourcePath); + const targetPath = path.resolve(workspace, relativePath); + if (!fs_1.default.existsSync(sourcePath)) { + core.warning(`The resolved cache-dependency-path does not exist: ${sourcePath}`); + } + else { + if (sourcePath !== targetPath) { + try { + const targetDir = path.dirname(targetPath); + if (!fs_1.default.existsSync(targetDir)) { + fs_1.default.mkdirSync(targetDir, { recursive: true }); + } + fs_1.default.copyFileSync(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); + } + catch (error) { + core.warning(`Failed to copy file from ${sourcePath} to ${targetPath}: ${error}`); + } + } + } + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); + } const cacheDistributor = (0, cache_factory_1.getCacheDistributor)(cache, pythonVersion, cacheDependencyPath); yield cacheDistributor.restoreCache(); }); } +exports.cacheDependencies = cacheDependencies; function resolveVersionInputFromDefaultFile() { const couples = [ ['.python-version', utils_1.getVersionsInputFromPlainFile] diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 72b350169..4353b341b 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -411,7 +411,7 @@ steps: - run: pip install -e . # Or pip install -e '.[test]' to install test dependencies ``` - +Note: cache-dependency-path supports files located outside the workspace root by copying them into the workspace to enable proper caching. # Outputs and environment variables ## Outputs diff --git a/src/setup-python.ts b/src/setup-python.ts index 5d585d734..ed76469c2 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -22,9 +22,45 @@ function isGraalPyVersion(versionSpec: string) { return versionSpec.startsWith('graalpy'); } -async function cacheDependencies(cache: string, pythonVersion: string) { +export async function cacheDependencies(cache: string, pythonVersion: string) { const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined; + let resolvedDependencyPath: string | undefined = undefined; + + if (cacheDependencyPath) { + const actionPath = process.env.GITHUB_ACTION_PATH || ''; + const workspace = process.env.GITHUB_WORKSPACE || process.cwd(); + + const sourcePath = path.resolve(actionPath, cacheDependencyPath); + const relativePath = path.relative(actionPath, sourcePath); + const targetPath = path.resolve(workspace, relativePath); + + if (!fs.existsSync(sourcePath)) { + core.warning( + `The resolved cache-dependency-path does not exist: ${sourcePath}` + ); + } else { + if (sourcePath !== targetPath) { + try { + const targetDir = path.dirname(targetPath); + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir, {recursive: true}); + } + + fs.copyFileSync(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); + } catch (error) { + core.warning( + `Failed to copy file from ${sourcePath} to ${targetPath}: ${error}` + ); + } + } + } + + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); + } + const cacheDistributor = getCacheDistributor( cache, pythonVersion, From 0511a23861c115c69f23c2381ad4615416506f6c Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 9 Jun 2025 13:47:16 +0530 Subject: [PATCH 2/8] logic update --- __tests__/setup-python.test.ts | 47 ++++++++++++++++++++-------------- dist/setup/index.js | 38 ++++++++++++++------------- src/setup-python.ts | 47 ++++++++++++++++++---------------- 3 files changed, 73 insertions(+), 59 deletions(-) diff --git a/__tests__/setup-python.test.ts b/__tests__/setup-python.test.ts index 5d68482b9..940cb402a 100644 --- a/__tests__/setup-python.test.ts +++ b/__tests__/setup-python.test.ts @@ -8,11 +8,10 @@ jest.mock('fs', () => { const actualFs = jest.requireActual('fs'); return { ...actualFs, - copyFileSync: jest.fn(), - existsSync: jest.fn(), - mkdirSync: jest.fn(), promises: { access: jest.fn(), + mkdir: jest.fn(), + copyFile: jest.fn(), writeFile: jest.fn(), appendFile: jest.fn() } @@ -21,7 +20,7 @@ jest.mock('fs', () => { jest.mock('@actions/core'); jest.mock('../src/cache-distributions/cache-factory'); -const mockedFs = fs as jest.Mocked; +const mockedFsPromises = fs.promises as jest.Mocked; const mockedCore = core as jest.Mocked; const mockedGetCacheDistributor = getCacheDistributor as jest.Mock; @@ -35,15 +34,25 @@ describe('cacheDependencies', () => { mockedCore.getInput.mockReturnValue('nested/deps.lock'); - mockedFs.existsSync.mockImplementation((p: any) => { + // Simulate file exists by resolving access without error + mockedFsPromises.access.mockImplementation(async (p) => { const pathStr = typeof p === 'string' ? p : p.toString(); - if (pathStr === '/github/action/nested/deps.lock') return true; - if (pathStr === '/github/workspace/nested') return false; // Simulate missing dir - return true; + if (pathStr === '/github/action/nested/deps.lock') { + return Promise.resolve(); + } + // Simulate directory doesn't exist to test mkdir + if (pathStr === path.dirname('/github/workspace/nested/deps.lock')) { + return Promise.reject(new Error('no dir')); + } + return Promise.resolve(); }); - mockedFs.copyFileSync.mockImplementation(() => undefined); - mockedFs.mkdirSync.mockImplementation(() => undefined); + // Simulate mkdir success + mockedFsPromises.mkdir.mockResolvedValue(undefined); + + // Simulate copyFile success + mockedFsPromises.copyFile.mockResolvedValue(undefined); + mockedGetCacheDistributor.mockReturnValue({restoreCache: mockRestoreCache}); }); @@ -53,11 +62,11 @@ describe('cacheDependencies', () => { const sourcePath = path.resolve('/github/action', 'nested/deps.lock'); const targetPath = path.resolve('/github/workspace', 'nested/deps.lock'); - expect(mockedFs.existsSync).toHaveBeenCalledWith(sourcePath); - expect(mockedFs.mkdirSync).toHaveBeenCalledWith(path.dirname(targetPath), { + expect(mockedFsPromises.access).toHaveBeenCalledWith(sourcePath, fs.constants.F_OK); + expect(mockedFsPromises.mkdir).toHaveBeenCalledWith(path.dirname(targetPath), { recursive: true }); - expect(mockedFs.copyFileSync).toHaveBeenCalledWith(sourcePath, targetPath); + expect(mockedFsPromises.copyFile).toHaveBeenCalledWith(sourcePath, targetPath); expect(mockedCore.info).toHaveBeenCalledWith( `Copied ${sourcePath} to ${targetPath}` ); @@ -68,21 +77,21 @@ describe('cacheDependencies', () => { }); it('warns if the dependency file does not exist', async () => { - mockedFs.existsSync.mockReturnValue(false); + // Simulate file does not exist by rejecting access + mockedFsPromises.access.mockRejectedValue(new Error('file not found')); await cacheDependencies('pip', '3.12'); expect(mockedCore.warning).toHaveBeenCalledWith( expect.stringContaining('does not exist') ); - expect(mockedFs.copyFileSync).not.toHaveBeenCalled(); + expect(mockedFsPromises.copyFile).not.toHaveBeenCalled(); expect(mockRestoreCache).toHaveBeenCalled(); }); it('warns if file copy fails', async () => { - mockedFs.copyFileSync.mockImplementation(() => { - throw new Error('copy failed'); - }); + // Simulate copyFile failure + mockedFsPromises.copyFile.mockRejectedValue(new Error('copy failed')); await cacheDependencies('pip', '3.12'); @@ -97,7 +106,7 @@ describe('cacheDependencies', () => { await cacheDependencies('pip', '3.12'); - expect(mockedFs.copyFileSync).not.toHaveBeenCalled(); + expect(mockedFsPromises.copyFile).not.toHaveBeenCalled(); expect(mockedCore.warning).not.toHaveBeenCalled(); expect(mockRestoreCache).toHaveBeenCalled(); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 854f94908..76ddee08f 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96931,26 +96931,28 @@ function cacheDependencies(cache, pythonVersion) { const sourcePath = path.resolve(actionPath, cacheDependencyPath); const relativePath = path.relative(actionPath, sourcePath); const targetPath = path.resolve(workspace, relativePath); - if (!fs_1.default.existsSync(sourcePath)) { - core.warning(`The resolved cache-dependency-path does not exist: ${sourcePath}`); + try { + const sourceExists = yield fs_1.default.promises + .access(sourcePath, fs_1.default.constants.F_OK) + .then(() => true) + .catch(() => false); + if (!sourceExists) { + core.warning(`The resolved cache-dependency-path does not exist: ${sourcePath}`); + } + else if (sourcePath !== targetPath) { + const targetDir = path.dirname(targetPath); + // Create target directory if it doesn't exist + yield fs_1.default.promises.mkdir(targetDir, { recursive: true }); + // Copy file asynchronously + yield fs_1.default.promises.copyFile(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); + } + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } - else { - if (sourcePath !== targetPath) { - try { - const targetDir = path.dirname(targetPath); - if (!fs_1.default.existsSync(targetDir)) { - fs_1.default.mkdirSync(targetDir, { recursive: true }); - } - fs_1.default.copyFileSync(sourcePath, targetPath); - core.info(`Copied ${sourcePath} to ${targetPath}`); - } - catch (error) { - core.warning(`Failed to copy file from ${sourcePath} to ${targetPath}: ${error}`); - } - } + catch (error) { + core.warning(`Failed to copy file from ${sourcePath} to ${targetPath}: ${error}`); } - resolvedDependencyPath = path.relative(workspace, targetPath); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } const cacheDistributor = (0, cache_factory_1.getCacheDistributor)(cache, pythonVersion, cacheDependencyPath); yield cacheDistributor.restoreCache(); diff --git a/src/setup-python.ts b/src/setup-python.ts index ed76469c2..2895d8858 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -21,7 +21,6 @@ function isPyPyVersion(versionSpec: string) { function isGraalPyVersion(versionSpec: string) { return versionSpec.startsWith('graalpy'); } - export async function cacheDependencies(cache: string, pythonVersion: string) { const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined; @@ -35,30 +34,34 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { const relativePath = path.relative(actionPath, sourcePath); const targetPath = path.resolve(workspace, relativePath); - if (!fs.existsSync(sourcePath)) { - core.warning( - `The resolved cache-dependency-path does not exist: ${sourcePath}` - ); - } else { - if (sourcePath !== targetPath) { - try { - const targetDir = path.dirname(targetPath); - if (!fs.existsSync(targetDir)) { - fs.mkdirSync(targetDir, {recursive: true}); - } + try { + const sourceExists = await fs.promises + .access(sourcePath, fs.constants.F_OK) + .then(() => true) + .catch(() => false); - fs.copyFileSync(sourcePath, targetPath); - core.info(`Copied ${sourcePath} to ${targetPath}`); - } catch (error) { - core.warning( - `Failed to copy file from ${sourcePath} to ${targetPath}: ${error}` - ); - } + if (!sourceExists) { + core.warning( + `The resolved cache-dependency-path does not exist: ${sourcePath}` + ); + } else if (sourcePath !== targetPath) { + const targetDir = path.dirname(targetPath); + + // Create target directory if it doesn't exist + await fs.promises.mkdir(targetDir, {recursive: true}); + + // Copy file asynchronously + await fs.promises.copyFile(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); } - } - resolvedDependencyPath = path.relative(workspace, targetPath); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); + } catch (error) { + core.warning( + `Failed to copy file from ${sourcePath} to ${targetPath}: ${error}` + ); + } } const cacheDistributor = getCacheDistributor( From b641d7d6ce8655f87a51cc211c1cf5a6b88dcb0e Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 9 Jun 2025 13:50:01 +0530 Subject: [PATCH 3/8] npm run format-check --- __tests__/setup-python.test.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/__tests__/setup-python.test.ts b/__tests__/setup-python.test.ts index 940cb402a..805e56acf 100644 --- a/__tests__/setup-python.test.ts +++ b/__tests__/setup-python.test.ts @@ -35,7 +35,7 @@ describe('cacheDependencies', () => { mockedCore.getInput.mockReturnValue('nested/deps.lock'); // Simulate file exists by resolving access without error - mockedFsPromises.access.mockImplementation(async (p) => { + mockedFsPromises.access.mockImplementation(async p => { const pathStr = typeof p === 'string' ? p : p.toString(); if (pathStr === '/github/action/nested/deps.lock') { return Promise.resolve(); @@ -62,11 +62,20 @@ describe('cacheDependencies', () => { const sourcePath = path.resolve('/github/action', 'nested/deps.lock'); const targetPath = path.resolve('/github/workspace', 'nested/deps.lock'); - expect(mockedFsPromises.access).toHaveBeenCalledWith(sourcePath, fs.constants.F_OK); - expect(mockedFsPromises.mkdir).toHaveBeenCalledWith(path.dirname(targetPath), { - recursive: true - }); - expect(mockedFsPromises.copyFile).toHaveBeenCalledWith(sourcePath, targetPath); + expect(mockedFsPromises.access).toHaveBeenCalledWith( + sourcePath, + fs.constants.F_OK + ); + expect(mockedFsPromises.mkdir).toHaveBeenCalledWith( + path.dirname(targetPath), + { + recursive: true + } + ); + expect(mockedFsPromises.copyFile).toHaveBeenCalledWith( + sourcePath, + targetPath + ); expect(mockedCore.info).toHaveBeenCalledWith( `Copied ${sourcePath} to ${targetPath}` ); From 566d40e37b39633480c386ee4e6def2ed883f677 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 9 Jun 2025 14:01:20 +0530 Subject: [PATCH 4/8] update cacheDependencies tests to cover resolved paths and copy edge cases --- __tests__/setup-python.test.ts | 27 +++++++++++++++++++++++++++ dist/setup/index.js | 27 +++++++++++++++++---------- src/setup-python.ts | 32 +++++++++++++++++++------------- 3 files changed, 63 insertions(+), 23 deletions(-) diff --git a/__tests__/setup-python.test.ts b/__tests__/setup-python.test.ts index 805e56acf..bb27289de 100644 --- a/__tests__/setup-python.test.ts +++ b/__tests__/setup-python.test.ts @@ -119,4 +119,31 @@ describe('cacheDependencies', () => { expect(mockedCore.warning).not.toHaveBeenCalled(); expect(mockRestoreCache).toHaveBeenCalled(); }); + + it('does not copy if dependency file is already inside the workspace but still sets resolved path', async () => { + // Simulate cacheDependencyPath inside workspace + mockedCore.getInput.mockReturnValue('deps.lock'); + + // Override sourcePath and targetPath to be equal + const actionPath = '/github/workspace'; // same path for action and workspace + process.env.GITHUB_ACTION_PATH = actionPath; + process.env.GITHUB_WORKSPACE = actionPath; + + // access resolves to simulate file exists + mockedFsPromises.access.mockResolvedValue(); + + await cacheDependencies('pip', '3.12'); + + const sourcePath = path.resolve(actionPath, 'deps.lock'); + const targetPath = sourcePath; // same path + + expect(mockedFsPromises.copyFile).not.toHaveBeenCalled(); + expect(mockedCore.info).toHaveBeenCalledWith( + `Dependency file is already inside the workspace: ${sourcePath}` + ); + expect(mockedCore.info).toHaveBeenCalledWith( + `Resolved cache-dependency-path: deps.lock` + ); + expect(mockRestoreCache).toHaveBeenCalled(); + }); }); diff --git a/dist/setup/index.js b/dist/setup/index.js index 76ddee08f..70d05b692 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96939,22 +96939,29 @@ function cacheDependencies(cache, pythonVersion) { if (!sourceExists) { core.warning(`The resolved cache-dependency-path does not exist: ${sourcePath}`); } - else if (sourcePath !== targetPath) { - const targetDir = path.dirname(targetPath); - // Create target directory if it doesn't exist - yield fs_1.default.promises.mkdir(targetDir, { recursive: true }); - // Copy file asynchronously - yield fs_1.default.promises.copyFile(sourcePath, targetPath); - core.info(`Copied ${sourcePath} to ${targetPath}`); + else { + if (sourcePath !== targetPath) { + const targetDir = path.dirname(targetPath); + // Create target directory if it doesn't exist + yield fs_1.default.promises.mkdir(targetDir, { recursive: true }); + // Copy file asynchronously + yield fs_1.default.promises.copyFile(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); + } + else { + core.info(`Dependency file is already inside the workspace: ${sourcePath}`); + } + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } - resolvedDependencyPath = path.relative(workspace, targetPath); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } catch (error) { core.warning(`Failed to copy file from ${sourcePath} to ${targetPath}: ${error}`); } } - const cacheDistributor = (0, cache_factory_1.getCacheDistributor)(cache, pythonVersion, cacheDependencyPath); + // Pass resolvedDependencyPath if available, else fallback to original input + const dependencyPathForCache = resolvedDependencyPath !== null && resolvedDependencyPath !== void 0 ? resolvedDependencyPath : cacheDependencyPath; + const cacheDistributor = (0, cache_factory_1.getCacheDistributor)(cache, pythonVersion, dependencyPathForCache); yield cacheDistributor.restoreCache(); }); } diff --git a/src/setup-python.ts b/src/setup-python.ts index 2895d8858..a1758eafa 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -44,19 +44,22 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { core.warning( `The resolved cache-dependency-path does not exist: ${sourcePath}` ); - } else if (sourcePath !== targetPath) { - const targetDir = path.dirname(targetPath); - - // Create target directory if it doesn't exist - await fs.promises.mkdir(targetDir, {recursive: true}); - - // Copy file asynchronously - await fs.promises.copyFile(sourcePath, targetPath); - core.info(`Copied ${sourcePath} to ${targetPath}`); + } else { + if (sourcePath !== targetPath) { + const targetDir = path.dirname(targetPath); + // Create target directory if it doesn't exist + await fs.promises.mkdir(targetDir, {recursive: true}); + // Copy file asynchronously + await fs.promises.copyFile(sourcePath, targetPath); + core.info(`Copied ${sourcePath} to ${targetPath}`); + } else { + core.info( + `Dependency file is already inside the workspace: ${sourcePath}` + ); + } + resolvedDependencyPath = path.relative(workspace, targetPath); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } - - resolvedDependencyPath = path.relative(workspace, targetPath); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } catch (error) { core.warning( `Failed to copy file from ${sourcePath} to ${targetPath}: ${error}` @@ -64,10 +67,13 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { } } + // Pass resolvedDependencyPath if available, else fallback to original input + const dependencyPathForCache = resolvedDependencyPath ?? cacheDependencyPath; + const cacheDistributor = getCacheDistributor( cache, pythonVersion, - cacheDependencyPath + dependencyPathForCache ); await cacheDistributor.restoreCache(); } From 8ae6b15df296d7dabc5c879ead20c1ed96b28938 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Mon, 9 Jun 2025 14:13:03 +0530 Subject: [PATCH 5/8] check failure fix --- dist/setup/index.js | 4 +++- src/setup-python.ts | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 70d05b692..cb1f039f6 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96951,7 +96951,9 @@ function cacheDependencies(cache, pythonVersion) { else { core.info(`Dependency file is already inside the workspace: ${sourcePath}`); } - resolvedDependencyPath = path.relative(workspace, targetPath); + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } diff --git a/src/setup-python.ts b/src/setup-python.ts index a1758eafa..106b415a6 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -21,6 +21,7 @@ function isPyPyVersion(versionSpec: string) { function isGraalPyVersion(versionSpec: string) { return versionSpec.startsWith('graalpy'); } + export async function cacheDependencies(cache: string, pythonVersion: string) { const cacheDependencyPath = core.getInput('cache-dependency-path') || undefined; @@ -57,7 +58,10 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { `Dependency file is already inside the workspace: ${sourcePath}` ); } - resolvedDependencyPath = path.relative(workspace, targetPath); + + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } catch (error) { From e0348c889a89697f34e427cce61861c4fb122942 Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Wed, 18 Jun 2025 13:27:33 +0530 Subject: [PATCH 6/8] depricate-windows-2019 --- .github/workflows/test-pypy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test-pypy.yml b/.github/workflows/test-pypy.yml index 54466e529..6433b7c5d 100644 --- a/.github/workflows/test-pypy.yml +++ b/.github/workflows/test-pypy.yml @@ -88,7 +88,6 @@ jobs: - macos-13 - macos-14 - macos-15 - - windows-2019 - windows-2022 - windows-2025 - ubuntu-22.04 From 6d7172dabe9cbbe2ca951c523a331d600f62ac3c Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 19 Jun 2025 13:17:10 +0530 Subject: [PATCH 7/8] refactored the code --- dist/setup/index.js | 8 ++++---- src/setup-python.ts | 12 +++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index cb1f039f6..19a5c0174 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96947,14 +96947,14 @@ function cacheDependencies(cache, pythonVersion) { // Copy file asynchronously yield fs_1.default.promises.copyFile(sourcePath, targetPath); core.info(`Copied ${sourcePath} to ${targetPath}`); + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } else { core.info(`Dependency file is already inside the workspace: ${sourcePath}`); } - resolvedDependencyPath = path - .relative(workspace, targetPath) - .replace(/\\/g, '/'); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } catch (error) { diff --git a/src/setup-python.ts b/src/setup-python.ts index 106b415a6..ff98008b1 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -53,16 +53,18 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { // Copy file asynchronously await fs.promises.copyFile(sourcePath, targetPath); core.info(`Copied ${sourcePath} to ${targetPath}`); + + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); + core.info( + `Resolved cache-dependency-path: ${resolvedDependencyPath}` + ); } else { core.info( `Dependency file is already inside the workspace: ${sourcePath}` ); } - - resolvedDependencyPath = path - .relative(workspace, targetPath) - .replace(/\\/g, '/'); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } catch (error) { core.warning( From fab5a1e24c28a416bdc215c7a241408a29b20b5d Mon Sep 17 00:00:00 2001 From: Aparna Jyothi Date: Thu, 19 Jun 2025 13:28:45 +0530 Subject: [PATCH 8/8] Check failure fix --- dist/setup/index.js | 8 ++++---- src/setup-python.ts | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 19a5c0174..cb1f039f6 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -96947,14 +96947,14 @@ function cacheDependencies(cache, pythonVersion) { // Copy file asynchronously yield fs_1.default.promises.copyFile(sourcePath, targetPath); core.info(`Copied ${sourcePath} to ${targetPath}`); - resolvedDependencyPath = path - .relative(workspace, targetPath) - .replace(/\\/g, '/'); - core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } else { core.info(`Dependency file is already inside the workspace: ${sourcePath}`); } + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } catch (error) { diff --git a/src/setup-python.ts b/src/setup-python.ts index ff98008b1..106b415a6 100644 --- a/src/setup-python.ts +++ b/src/setup-python.ts @@ -53,18 +53,16 @@ export async function cacheDependencies(cache: string, pythonVersion: string) { // Copy file asynchronously await fs.promises.copyFile(sourcePath, targetPath); core.info(`Copied ${sourcePath} to ${targetPath}`); - - resolvedDependencyPath = path - .relative(workspace, targetPath) - .replace(/\\/g, '/'); - core.info( - `Resolved cache-dependency-path: ${resolvedDependencyPath}` - ); } else { core.info( `Dependency file is already inside the workspace: ${sourcePath}` ); } + + resolvedDependencyPath = path + .relative(workspace, targetPath) + .replace(/\\/g, '/'); + core.info(`Resolved cache-dependency-path: ${resolvedDependencyPath}`); } } catch (error) { core.warning(