From a15295b98880c807a558850ce43f8ae1c593a544 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 17 Apr 2023 14:46:44 -0700 Subject: [PATCH] Clean cargo. --- package.json | 1 + pnpm-lock.yaml | 10 ++++++++++ src/cargo.ts | 27 ++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9a598a9..f639aa5 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a5aec2c..d56c81f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: diff --git a/src/cargo.ts b/src/cargo.ts index e889c3d..013477c 100644 --- a/src/cargo.ts +++ b/src/cargo.ts @@ -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}`);