Skip to content

Commit 0716d00

Browse files
committed
new: Delete cache older than 14 days.
1 parent c30f25c commit 0716d00

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The following optimizations and considerations are taken into account when cachi
9393
crate, a checkout will be performed on-demand.
9494
- The `/registry` directory is _cleaned_ before saving the cache. This includes removing `src`,
9595
`.cache`, and any other unnecessary files.
96+
- Registry artifacts older than 14 days will be removed.
9697
- `/target/debug`
9798
- Only the `debug` profile is cached, as this profile is typically used for formatting, linting,
9899
and testing.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@moonrepo/setup-rust",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "A GitHub action for setting up Rust and Cargo.",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "ncc build ./index.ts && ncc build ./post.ts --out ./dist/post",
8-
"check": "npm run lint && npm run typecheck",
8+
"check": "pnpm run lint && pnpm run typecheck",
99
"lint": "eslint --ext .ts,.js --fix .",
1010
"typecheck": "tsc --noEmit"
1111
},

src/cargo.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as core from '@actions/core';
77
import * as exec from '@actions/exec';
88
import * as glob from '@actions/glob';
99
import * as tc from '@actions/tool-cache';
10-
import { rmrf } from './fs';
10+
import { padDate, rmrf } from './helpers';
1111
import { RUST_HASH, RUST_VERSION } from './rust';
1212

1313
export const CARGO_HOME = process.env.CARGO_HOME ?? path.join(os.homedir(), '.cargo');
@@ -129,7 +129,19 @@ export async function cleanCargoRegistry() {
129129
const registryDir = path.join(CARGO_HOME, 'registry');
130130

131131
// .cargo/registry/src - Delete entirely
132-
await exec.exec('cargo', ['cache', '--autoclean']);
132+
const staleDate = new Date();
133+
134+
// eslint-disable-next-line no-magic-numbers
135+
staleDate.setDate(staleDate.getDate() - 14);
136+
137+
await exec.exec('cargo', [
138+
'cache',
139+
'--autoclean',
140+
'--remove-if-older-than',
141+
`${staleDate.getFullYear()}.${padDate(staleDate.getMonth() + 1)}.${padDate(
142+
staleDate.getDate(),
143+
)}`,
144+
]);
133145

134146
// .cargo/registry/index - Delete .cache directories
135147
const indexDir = path.join(registryDir, 'index');

src/fs.ts renamed to src/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ export async function rmrf(dir: string) {
1010
core.warning(`Failed to delete ${dir}: ${error}`);
1111
}
1212
}
13+
14+
export function padDate(value: number) {
15+
return String(value).padStart(2, '0');
16+
}

0 commit comments

Comments
 (0)