mirror of
https://github.com/moonrepo/setup-rust.git
synced 2025-04-29 21:40:01 +00:00
Clean cargo.
This commit is contained in:
parent
1df398a624
commit
a15295b988
3 changed files with 35 additions and 3 deletions
|
@ -19,6 +19,7 @@
|
||||||
"@actions/cache": "^3.2.1",
|
"@actions/cache": "^3.2.1",
|
||||||
"@actions/core": "^1.10.0",
|
"@actions/core": "^1.10.0",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
|
"@actions/glob": "^0.4.0",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"@ltd/j-toml": "^1.38.0"
|
"@ltd/j-toml": "^1.38.0"
|
||||||
},
|
},
|
||||||
|
|
10
pnpm-lock.yaml
generated
10
pnpm-lock.yaml
generated
|
@ -10,6 +10,9 @@ dependencies:
|
||||||
'@actions/exec':
|
'@actions/exec':
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
|
'@actions/glob':
|
||||||
|
specifier: ^0.4.0
|
||||||
|
version: 0.4.0
|
||||||
'@actions/tool-cache':
|
'@actions/tool-cache':
|
||||||
specifier: ^2.0.1
|
specifier: ^2.0.1
|
||||||
version: 2.0.1
|
version: 2.0.1
|
||||||
|
@ -82,6 +85,13 @@ packages:
|
||||||
minimatch: 3.1.2
|
minimatch: 3.1.2
|
||||||
dev: false
|
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:
|
/@actions/http-client@2.1.0:
|
||||||
resolution: {integrity: sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==}
|
resolution: {integrity: sha512-BonhODnXr3amchh4qkmjPMUO8mFi/zLaaCeCAJZqch8iQqyDnVIkySjB38VHAC8IJ+bnlgfOqlhpyCUZHlQsqw==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
27
src/cargo.ts
27
src/cargo.ts
|
@ -1,8 +1,12 @@
|
||||||
|
/* eslint-disable node/no-unsupported-features/node-builtins */
|
||||||
|
|
||||||
|
import fs from 'fs';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import * as cache from '@actions/cache';
|
import * as cache from '@actions/cache';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as glob from '@actions/glob';
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||||
export const CARGO_HOME = process.env.CARGO_HOME || path.join(os.homedir(), '.cargo');
|
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')];
|
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() {
|
export async function saveCache() {
|
||||||
if (!CACHE_ENABLED) {
|
if (!CACHE_ENABLED) {
|
||||||
return;
|
return;
|
||||||
|
@ -30,9 +53,7 @@ export async function saveCache() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('Cleaning cache before saving');
|
await cleanCargoRegistry();
|
||||||
|
|
||||||
await exec.exec('cargo', ['cache', '--autoclean']);
|
|
||||||
|
|
||||||
core.info(`Saving cache with key ${primaryKey}`);
|
core.info(`Saving cache with key ${primaryKey}`);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue