Skip to content

Commit

Permalink
Update dependencies, clean both debug and release targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Apr 8, 2022
1 parent f8f67b7 commit 74e8e24
Show file tree
Hide file tree
Showing 7 changed files with 6,635 additions and 4,369 deletions.
5,333 changes: 3,225 additions & 2,108 deletions dist/restore/index.js

Large diffs are not rendered by default.

5,332 changes: 3,224 additions & 2,108 deletions dist/save/index.js

Large diffs are not rendered by default.

290 changes: 151 additions & 139 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
},
"homepage": "https://github.com/Swatinem/rust-cache#readme",
"dependencies": {
"@actions/cache": "^1.0.8",
"@actions/cache": "^2.0.2",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/glob": "^0.2.0",
"@actions/io": "^1.1.1"
"@actions/exec": "^1.1.1",
"@actions/glob": "^0.2.1",
"@actions/io": "^1.1.2"
},
"devDependencies": {
"@vercel/ncc": "^0.33.1",
"typescript": "4.5.4"
"@vercel/ncc": "^0.33.3",
"typescript": "4.6.3"
},
"scripts": {
"prepare": "ncc build --target es2020 -o dist/restore src/restore.ts && ncc build --target es2020 -o dist/save src/save.ts"
Expand Down
28 changes: 20 additions & 8 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path from "path";
process.on("uncaughtException", (e) => {
core.info(`[warning] ${e.message}`);
if (e.stack) {
core.info(e.stack)
core.info(e.stack);
}
});

Expand Down Expand Up @@ -192,21 +192,33 @@ export async function getPackages(): Promise<Packages> {

export async function cleanTarget(packages: Packages) {
await fs.promises.unlink(path.join(targetDir, "./.rustc_info.json"));
await io.rmRF(path.join(targetDir, "./debug/examples"));
await io.rmRF(path.join(targetDir, "./debug/incremental"));

await cleanProfileTarget(packages, "debug");
await cleanProfileTarget(packages, "release");
}

async function cleanProfileTarget(packages: Packages, profile: string) {
try {
await fs.promises.access(path.join(targetDir, profile));
} catch {
return;
}

await io.rmRF(path.join(targetDir, profile, "./examples"));
await io.rmRF(path.join(targetDir, profile, "./incremental"));

let dir: fs.Dir;
// remove all *files* from debug
dir = await fs.promises.opendir(path.join(targetDir, "./debug"));
// remove all *files* from the profile directory
dir = await fs.promises.opendir(path.join(targetDir, profile));
for await (const dirent of dir) {
if (dirent.isFile()) {
await rm(dir.path, dirent);
}
}

const keepPkg = new Set(packages.map((p) => p.name));
await rmExcept(path.join(targetDir, "./debug/build"), keepPkg);
await rmExcept(path.join(targetDir, "./debug/.fingerprint"), keepPkg);
await rmExcept(path.join(targetDir, profile, "./build"), keepPkg);
await rmExcept(path.join(targetDir, profile, "./.fingerprint"), keepPkg);

const keepDeps = new Set(
packages.flatMap((p) => {
Expand All @@ -218,7 +230,7 @@ export async function cleanTarget(packages: Packages) {
return names;
}),
);
await rmExcept(path.join(targetDir, "./debug/deps"), keepDeps);
await rmExcept(path.join(targetDir, profile, "./deps"), keepDeps);
}

const oneWeek = 7 * 24 * 3600 * 1000;
Expand Down
5 changes: 5 additions & 0 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import * as core from "@actions/core";
import { cleanTarget, getCacheConfig, getCargoBins, getPackages, stateBins, stateKey } from "./common";

async function run() {
if (!cache.isFeatureAvailable()) {
setCacheHitOutput(false);
return;
}

try {
var cacheOnFailure = core.getInput("cache-on-failure").toLowerCase();
if (cacheOnFailure !== "true") {
Expand Down
4 changes: 4 additions & 0 deletions src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import {
} from "./common";

async function run() {
if (!cache.isFeatureAvailable()) {
return;
}

try {
const { paths: savePaths, key } = await getCacheConfig();

Expand Down

0 comments on commit 74e8e24

Please sign in to comment.