Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GHA] ccache cleanup #26789

Merged
merged 8 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 62 additions & 1 deletion .github/actions/cache/__tests__/cleanup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const getInputMock = jest.spyOn(core, 'getInput').mockImplementation();
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation();

const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-cleanup-'));
const cacheRemotePath = path.join(tempDir, 'cache_remote');
const cacheRemotePath = path.join(
tempDir,
'subdir_1',
'subdir_2',
'cache_remote'
);

const cacheFiles = ['cache_1.cache', 'cache_2.cache', 'cache_3.cache'];
const minAccessTime = 7 * 24 * 60 * 60 * 1000; // 1 week
Expand Down Expand Up @@ -283,4 +288,60 @@ describe('cleanup', () => {
// check that sub directory exists
expect(fs.existsSync(cacheSubPath)).toBe(true);
});

it('Cleanup directory with subdirectories and files (recursive=true)', async () => {
const cacheSubPath = path.join(tempDir, 'subdir_1');
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'cache-path':
return cacheSubPath;
case 'restore-keys':
return 'cache';
case 'cache-size':
return 1;
case 'recursive':
return true;
default:
return '';
}
});

await cleanupImpl.cleanUp();

expect(runMock).toHaveReturned();
// cache2 and cache3 should be removed
for (const cache of cacheFiles.slice(1, 2)) {
expect(fs.existsSync(path.join(cacheRemotePath, cache))).toBe(false);
}
// check that file1 exists
expect(fs.existsSync(path.join(cacheRemotePath, cacheFiles[0]))).toBe(true);
});

it('Cleanup directory with subdirectories and files (recursive=false)', async () => {
const cacheSubPath = path.join(tempDir, 'subdir_1');
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation(name => {
switch (name) {
case 'cache-path':
return cacheSubPath;
case 'restore-keys':
return 'cache';
case 'cache-size':
return 1;
case 'recursive':
return false;
default:
return '';
}
});

await cleanupImpl.cleanUp();

expect(runMock).toHaveReturned();
// cache2 and cache3 should be removed
for (const cache of cacheFiles) {
expect(fs.existsSync(path.join(cacheRemotePath, cache))).toBe(true);
}
});
});
6 changes: 5 additions & 1 deletion .github/actions/cache/__tests__/save.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ describe('save', () => {

it('Cache files: absent remote cache dir', async () => {
// Set the action's inputs as return values from core.getInput()
const cacheRemotePathAbsent = path.join(tempDir, 'cache_remote_absent');
const cacheRemotePathAbsent = path.join(
tempDir,
'cache_remote_absent',
'subdir'
);
getInputMock.mockImplementation(name => {
switch (name) {
case 'cache-path':
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/cache/cleanup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
evicted to limit the total cache storage'
default: 50
required: false
recursive:
description: 'Scan the current directory only or all subdirectories'
default: false
required: false

runs:
using: 'node20'
Expand Down
Loading
Loading