Clean cargo.

This commit is contained in:
Miles Johnson 2023-04-17 14:46:44 -07:00
parent 1df398a624
commit a15295b988
3 changed files with 35 additions and 3 deletions

View file

@ -19,6 +19,7 @@
"@actions/cache": "^3.2.1",
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.4.0",
"@actions/tool-cache": "^2.0.1",
"@ltd/j-toml": "^1.38.0"
},

10
pnpm-lock.yaml generated
View file

@ -10,6 +10,9 @@ dependencies:
'@actions/exec':
specifier: ^1.1.1
version: 1.1.1
'@actions/glob':
specifier: ^0.4.0
version: 0.4.0
'@actions/tool-cache':
specifier: ^2.0.1
version: 2.0.1
@ -82,6 +85,13 @@ packages:
minimatch: 3.1.2
dev: false
/@actions/glob@0.4.0:
resolution: {integrity: sha512-+eKIGFhsFa4EBwaf/GMyzCdWrXWymGXfFmZU3FHQvYS8mPcHtTtZONbkcqqUMzw9mJ/pImEBFET1JNifhqGsAQ==}
dependencies:
'@actions/core': 1.10.0
minimatch: 3.1.2
dev: false
/@actions/http-client@2.1.0:
resolution: {integrity: sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==}
dependencies:

View file

@ -1,8 +1,12 @@
/* eslint-disable node/no-unsupported-features/node-builtins */
import fs from 'fs';
import os from 'os';
import path from 'path';
import * as cache from '@actions/cache';
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as glob from '@actions/glob';
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
export const CARGO_HOME = process.env.CARGO_HOME || path.join(os.homedir(), '.cargo');
@ -17,6 +21,25 @@ export function getPathsToCache(): string[] {
return [path.join(CARGO_HOME, 'registry')];
}
export async function cleanCargoRegistry() {
core.info('Cleaning cache before saving');
const registryDir = path.join(CARGO_HOME, 'registry');
// .cargo/registry/src - Delete entirely
await exec.exec('cargo', ['cache', '--autoclean']);
// .cargo/registry/index - Delete .cache directories
const globber = await glob.create(path.join(registryDir, 'index/**/.cache'));
for await (const file of globber.globGenerator()) {
core.debug(`Deleting ${file}`);
await fs.promises.unlink(file);
}
// .cargo/registry/cache - Do nothing?
}
export async function saveCache() {
if (!CACHE_ENABLED) {
return;
@ -30,9 +53,7 @@ export async function saveCache() {
return;
}
core.info('Cleaning cache before saving');
await exec.exec('cargo', ['cache', '--autoclean']);
await cleanCargoRegistry();
core.info(`Saving cache with key ${primaryKey}`);