mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +00:00
new: Delete cache older than 14 days.
This commit is contained in:
parent
c30f25ce4b
commit
0716d005db
4 changed files with 21 additions and 4 deletions
16
src/cargo.ts
16
src/cargo.ts
|
@ -7,7 +7,7 @@ import * as core from '@actions/core';
|
|||
import * as exec from '@actions/exec';
|
||||
import * as glob from '@actions/glob';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import { rmrf } from './fs';
|
||||
import { padDate, rmrf } from './helpers';
|
||||
import { RUST_HASH, RUST_VERSION } from './rust';
|
||||
|
||||
export const CARGO_HOME = process.env.CARGO_HOME ?? path.join(os.homedir(), '.cargo');
|
||||
|
@ -129,7 +129,19 @@ export async function cleanCargoRegistry() {
|
|||
const registryDir = path.join(CARGO_HOME, 'registry');
|
||||
|
||||
// .cargo/registry/src - Delete entirely
|
||||
await exec.exec('cargo', ['cache', '--autoclean']);
|
||||
const staleDate = new Date();
|
||||
|
||||
// eslint-disable-next-line no-magic-numbers
|
||||
staleDate.setDate(staleDate.getDate() - 14);
|
||||
|
||||
await exec.exec('cargo', [
|
||||
'cache',
|
||||
'--autoclean',
|
||||
'--remove-if-older-than',
|
||||
`${staleDate.getFullYear()}.${padDate(staleDate.getMonth() + 1)}.${padDate(
|
||||
staleDate.getDate(),
|
||||
)}`,
|
||||
]);
|
||||
|
||||
// .cargo/registry/index - Delete .cache directories
|
||||
const indexDir = path.join(registryDir, 'index');
|
||||
|
|
|
@ -10,3 +10,7 @@ export async function rmrf(dir: string) {
|
|||
core.warning(`Failed to delete ${dir}: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function padDate(value: number) {
|
||||
return String(value).padStart(2, '0');
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue