Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79382,12 +79382,72 @@ async function maybeGetScarbTargetDirPath(scarbLockPathInput) {
}
}

// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
var io = __nccwpck_require__(7436);
// EXTERNAL MODULE: external "fs"
var external_fs_ = __nccwpck_require__(7147);
var external_fs_default = /*#__PURE__*/__nccwpck_require__.n(external_fs_);
;// CONCATENATED MODULE: ./lib/cleanup.js






async function cleanTargetDir(targetDir) {
core.info(`cleaning target directory "${targetDir}"`);

// remove all *files* from the target directory, except for `CACHEDIR.TAG`
// remove `scarb doc` and `scarb package` output directories
let dir = await external_fs_default().promises.opendir(targetDir);
for await (const dirent of dir) {
if (dirent.isDirectory()) {
let dirName = external_path_default().join(dir.path, dirent.name);
try {
if (dirent.name in ["doc", "package", "execute"]) {
// There is no point to cache directories created by `scarb doc`, `scarb package` or `scarb execute`.
await rm(dir.path, dirent);
continue;
}
await cleanProfileTarget(dirName);
} catch {}
} else if (dirent.name !== "CACHEDIR.TAG") {
await rm(dir.path, dirent);
}
}
}

async function cleanProfileTarget(profileDir) {
core.debug(`cleaning profile directory "${profileDir}"`);

// remove all files, but keep all directories
let dir = await external_fs_default().promises.opendir(profileDir);
for await (const dirent of dir) {
if (!dirent.isDirectory()) {
await rm(dir.path, dirent);
}
}
}

async function rm(parent, dirent) {
try {
const fileName = external_path_default().join(parent, dirent.name);
core.debug(`deleting "${fileName}"`);
if (dirent.isFile()) {
await external_fs_default().promises.unlink(fileName);
} else if (dirent.isDirectory()) {
await io.rmRF(fileName);
}
} catch {}
}

;// CONCATENATED MODULE: ./lib/cache-save.js






async function saveCache() {
const enableCache = core.getBooleanInput("cache");
const enableTargetsCache = core.getBooleanInput("cache-targets");
Expand All @@ -79408,6 +79468,7 @@ async function saveCache() {
if (enableTargetsCache) {
let targetCache = await maybeGetScarbTargetDirPath(scarbLockPathInput);
if (!!targetCache) {
await cleanTargetDir(targetCache);
cacheDirs.push(targetCache);
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/cache-save/index.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/cache-save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
State,
maybeGetScarbTargetDirPath,
} from "./cache-utils";
import { cleanTargetDir } from "./cleanup";

async function saveCache() {
const enableCache = core.getBooleanInput("cache");
Expand All @@ -27,6 +28,7 @@ async function saveCache() {
if (enableTargetsCache) {
let targetCache = await maybeGetScarbTargetDirPath(scarbLockPathInput);
if (!!targetCache) {
await cleanTargetDir(targetCache);
cacheDirs.push(targetCache);
}
}
Expand Down
52 changes: 52 additions & 0 deletions lib/cleanup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as core from "@actions/core";
import * as io from "@actions/io";

import fs from "fs";
import path from "path";

export async function cleanTargetDir(targetDir) {
core.info(`cleaning target directory "${targetDir}"`);

// remove all *files* from the target directory, except for `CACHEDIR.TAG`
// remove `scarb doc` and `scarb package` output directories
Comment thread
DelevoXDG marked this conversation as resolved.
let dir = await fs.promises.opendir(targetDir);
for await (const dirent of dir) {
if (dirent.isDirectory()) {
let dirName = path.join(dir.path, dirent.name);
try {
if (dirent.name in ["doc", "package", "execute"]) {
// There is no point to cache directories created by `scarb doc`, `scarb package` or `scarb execute`.
await rm(dir.path, dirent);
continue;
}
await cleanProfileTarget(dirName);
} catch {}
} else if (dirent.name !== "CACHEDIR.TAG") {
await rm(dir.path, dirent);
}
}
}

async function cleanProfileTarget(profileDir) {
core.debug(`cleaning profile directory "${profileDir}"`);

// remove all files, but keep all directories
let dir = await fs.promises.opendir(profileDir);
for await (const dirent of dir) {
if (!dirent.isDirectory()) {
await rm(dir.path, dirent);
}
Comment thread
DelevoXDG marked this conversation as resolved.
}
}

async function rm(parent, dirent) {
try {
const fileName = path.join(parent, dirent.name);
core.debug(`deleting "${fileName}"`);
if (dirent.isFile()) {
await fs.promises.unlink(fileName);
} else if (dirent.isDirectory()) {
await io.rmRF(fileName);
}
} catch {}
}
Loading