Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused import of 'path' in versions.js #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
228 changes: 114 additions & 114 deletions dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73637,122 +73637,122 @@ var external_path_default = /*#__PURE__*/__nccwpck_require__.n(external_path_);
;// CONCATENATED MODULE: external "fs/promises"
const promises_namespaceObject = require("fs/promises");
;// CONCATENATED MODULE: ./lib/cache-utils.js








const State = {
CachePrimaryKey: "primary_key",
CacheMatchedKey: "matched_key",
};

async function getCacheDirectory() {
// NOTE: The `cache path` command was introduced in Scarb 0.7.0. We do not want to break compatibility with older
// versions yet, so we fall back to a well-known cache path if this command is not available.
try {
if (await isScarbMissingCachePathCommand()) {
return wellKnownCachePath();
}
} catch (e) {
core.debug(`scarb cache path fallback failed: ${e.message}`);
}

const { stdout, exitCode } = await exec.getExecOutput("scarb cache path");

if (exitCode > 0) {
throw new Error(
"failed to find cache path: command `scarb cache path` failed",
);
}

return stdout.trim();
}

async function isScarbMissingCachePathCommand() {
const { stdout } = await exec.getExecOutput("scarb -V");
return stdout.match(/^scarb 0\.[0-6]\./) != null;
}

function wellKnownCachePath() {
const platform = external_os_default().platform();
const home = process.env.HOME;

switch (platform) {
case "linux":
return external_path_default().join(home, ".cache/scarb");
case "darwin":
return external_path_default().join(home, `Library/Caches/com.swmansion.scarb`);
case "win32":
return external_path_default().join(process.env.APPDATA, "swmansion/scarb/config");
default:
throw new Error(`caching is not available on this platform: ${platform}`);
}
}

async function getCacheKey(scarbLockPath) {
const platform = process.env.RUNNER_OS;
const fileHash = await glob.hashFiles(await getScarbLockPath(scarbLockPath));

if (!fileHash) {
throw new Error(
"failed to cache dependencies: unable to hash Scarb.lock file",
);
}

return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
}

async function getScarbLockPath(scarbLockPath) {
const lockfilePath = scarbLockPath || "Scarb.lock";

await fs.access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
});

return lockfilePath;
}
const State = {
CachePrimaryKey: "primary_key",
CacheMatchedKey: "matched_key",
};
async function getCacheDirectory() {
// NOTE: The `cache path` command was introduced in Scarb 0.7.0. We do not want to break compatibility with older
// versions yet, so we fall back to a well-known cache path if this command is not available.
try {
if (await isScarbMissingCachePathCommand()) {
return wellKnownCachePath();
}
} catch (e) {
core.debug(`scarb cache path fallback failed: ${e.message}`);
}
const { stdout, exitCode } = await exec.getExecOutput("scarb cache path");
if (exitCode > 0) {
throw new Error(
"failed to find cache path: command `scarb cache path` failed",
);
}
return stdout.trim();
}
async function isScarbMissingCachePathCommand() {
const { stdout } = await exec.getExecOutput("scarb -V");
return stdout.match(/^scarb 0\.[0-6]\./) != null;
}
function wellKnownCachePath() {
const platform = external_os_default().platform();
const home = process.env.HOME;
switch (platform) {
case "linux":
return external_path_default().join(home, ".cache/scarb");
case "darwin":
return external_path_default().join(home, `Library/Caches/com.swmansion.scarb`);
case "win32":
return external_path_default().join(process.env.APPDATA, "swmansion/scarb/config");
default:
throw new Error(`caching is not available on this platform: ${platform}`);
}
}
async function getCacheKey(scarbLockPath) {
const platform = process.env.RUNNER_OS;
const fileHash = await glob.hashFiles(await getScarbLockPath(scarbLockPath));
if (!fileHash) {
throw new Error(
"failed to cache dependencies: unable to hash Scarb.lock file",
);
}
return `scarb-cache-${platform}-${fileHash}`.toLowerCase();
}
async function getScarbLockPath(scarbLockPath) {
const lockfilePath = scarbLockPath || "Scarb.lock";
await fs.access(lockfilePath).catch((_) => {
throw new Error("failed to find Scarb.lock");
});
return lockfilePath;
}

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





async function saveCache() {
try {
const primaryKey = core.getState(State.CachePrimaryKey);
const matchedKey = core.getState(State.CacheMatchedKey);

if (primaryKey !== matchedKey) {
await cache.saveCache([await getCacheDirectory()], primaryKey);
} else if (primaryKey === "" && matchedKey === "") {
// When using action for the first time and the project doesn't have Scarb.lock,
// `restoreCache()` returns an error during `getCacheKey()` method.
// As a result, primaryKey and matchedKey (by default) are empty strings,
// which would satisfy `else` branch, even though no cache would be found.
core.info(`Cache entry not found, not saving cache.`);
} else {
core.info(`Cache hit occurred, not saving cache.`);
}

// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
process.exit(0);
} catch (e) {
core.error(e);
// vide supra
process.exit(1);
}
}

saveCache();
async function saveCache() {
try {
const primaryKey = core.getState(State.CachePrimaryKey);
const matchedKey = core.getState(State.CacheMatchedKey);
if (primaryKey !== matchedKey) {
await cache.saveCache([await getCacheDirectory()], primaryKey);
} else if (primaryKey === "" && matchedKey === "") {
// When using action for the first time and the project doesn't have Scarb.lock,
// `restoreCache()` returns an error during `getCacheKey()` method.
// As a result, primaryKey and matchedKey (by default) are empty strings,
// which would satisfy `else` branch, even though no cache would be found.
core.info(`Cache entry not found, not saving cache.`);
} else {
core.info(`Cache hit occurred, not saving cache.`);
}
// node will stay alive if any promises are not resolved,
// which is a possibility if HTTP requests are dangling
// due to retries or timeouts. We know that if we got here
// that all promises that we care about have successfully
// resolved, so simply exit with success.
process.exit(0);
} catch (e) {
core.error(e);
// vide supra
process.exit(1);
}
}
saveCache();

})();

Expand Down
2 changes: 1 addition & 1 deletion dist/cache-save/index.js.map

Large diffs are not rendered by default.

Loading
Loading