Skip to content

Commit

Permalink
fix: use ts-dedent
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Dec 5, 2023
1 parent f8b4795 commit d952be2
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 26 deletions.
16 changes: 15 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@actions/io": "^1.1.2"
"@actions/io": "^1.1.2",
"ts-dedent": "^2.2.0"
},
"devDependencies": {
"@types/jest": "^27.5.2",
Expand Down
3 changes: 1 addition & 2 deletions src/gc.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as core from "@actions/core";
import { exec } from "@actions/exec";

import { Inputs } from "./constants";
import * as utils from "./utils/actionUtils";

export async function collectGarbage() {
core.info("Collecting garbage");
utils.info("Collecting garbage");

await exec("bash", ["-c", "sudo rm -rf /nix/.[!.]* /nix/..?*"]);

Expand Down
10 changes: 5 additions & 5 deletions src/purge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function purgeByTime({

const maxDate = utils.getMaxDate({ doUseLastAccessedTime, time });

core.info(
utils.info(
`
${
lookupOnly ? "Searching for" : "Purging"
Expand All @@ -36,7 +36,7 @@ async function purgeByTime({
maxDate
});

core.info(
utils.info(
`
Found ${caches.length} cache(s):
${utils.stringify(caches)}
Expand All @@ -57,7 +57,7 @@ async function purgeByTime({
const atDate = new Date(at);
const atDatePretty = atDate.toISOString();
if (atDate < maxDate) {
core.info(
utils.info(
`Deleting the cache having the key '${cache.key}' and ${verb} at ${atDatePretty}`
);

Expand All @@ -69,7 +69,7 @@ async function purgeByTime({
cache_id: cache.id
});
} catch (error) {
core.info(
utils.info(
`
Failed to delete cache ${cache.key}
Expand All @@ -78,7 +78,7 @@ async function purgeByTime({
);
}
} else {
core.info(
utils.info(
`Skipping the cache having the key '${cache.key}' and ${verb} at ${atDatePretty}`
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/restoreExtraCaches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function restoreExtraCaches() {

const token = core.getInput(Inputs.Token, { required: true });

core.info(
utils.info(
`
Restoring extra caches with keys:
${utils.stringify(extraRestoreKeys)}
Expand All @@ -21,7 +21,7 @@ export async function restoreExtraCaches() {

const results = await utils.getCachesByKeys(token, extraRestoreKeys);

core.info(
utils.info(
`
Found ${results.length} cache(s):
${utils.stringify(results)}
Expand All @@ -31,7 +31,7 @@ export async function restoreExtraCaches() {
const cachePaths = utils.paths;

results.forEach(async cache => {
core.info(`Restoring a cache with the key ${cache.key}`);
utils.info(`Restoring a cache with the key ${cache.key}`);

if (cache.key !== undefined) {
const restoreKey = await utils.getCacheKey({
Expand All @@ -42,7 +42,7 @@ export async function restoreExtraCaches() {
});

if (restoreKey) {
core.info(`Restored a cache with the key ${cache.key}`);
utils.info(`Restored a cache with the key ${cache.key}`);
}
}
});
Expand Down
16 changes: 8 additions & 8 deletions src/restoreImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { IStateProvider } from "./stateProvider";
import * as utils from "./utils/actionUtils";

export async function restoreWithKey(key: string, paths: string[]) {
core.info(`Restoring a cache with the key "${key}"...`);
utils.info(`Restoring a cache with the key "${key}"...`);

core.info(
utils.info(
`::group::Logs while restoring. Errors are due to attempts to overwrite read-only paths.`
);

Expand All @@ -19,9 +19,9 @@ export async function restoreWithKey(key: string, paths: string[]) {
lookupOnly: false
});

core.info(`::endgroup::`);
utils.info(`::endgroup::`);

core.info(`Finished restoring a cache with the key "${key}"...`);
utils.info(`Finished restoring a cache with the key "${key}"...`);
}

async function restoreImpl(
Expand Down Expand Up @@ -50,7 +50,7 @@ async function restoreImpl(
const failOnCacheMiss = utils.getInputAsBool(Inputs.FailOnCacheMiss);
const restoreKeyHit = utils.getInputAsBool(Inputs.RestoreKeyHit);

core.info(`Searching for a cache with the key "${primaryKey}"...`);
utils.info(`Searching for a cache with the key "${primaryKey}"...`);

let cacheKey = await utils.getCacheKey({
paths: cachePaths,
Expand All @@ -62,7 +62,7 @@ async function restoreImpl(
if (cacheKey) {
await restoreWithKey(cacheKey, cachePaths);
} else {
core.info(
utils.info(
`
No cache with the key "${cacheKey}" found.
Searching for a cache using restore keys:
Expand Down Expand Up @@ -96,7 +96,7 @@ async function restoreImpl(
`
);
}
core.info(
utils.info(
`
Cache not found for input keys:
${utils.stringify([primaryKey, ...restoreKeys])}
Expand All @@ -119,7 +119,7 @@ async function restoreImpl(

core.setOutput(Outputs.CacheHit, isExactKeyMatch.toString());

core.info(`Cache restored from key: ${cacheKey}`);
utils.info(`Cache restored from key: ${cacheKey}`);

await restoreExtraCaches();

Expand Down
10 changes: 5 additions & 5 deletions src/saveImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
const time = Date.now();

if (utils.isExactKeyMatch(primaryKey, restoredKey)) {
core.info(`Cache hit occurred on the primary key ${primaryKey}.`);
utils.info(`Cache hit occurred on the primary key ${primaryKey}.`);

const caches = await purgeCaches({
key: primaryKey,
Expand All @@ -67,7 +67,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
});

if (caches.map(cache => cache.key).includes(primaryKey)) {
core.info(`Purging the cache with the key ${primaryKey}...`);
utils.info(`Purging the cache with the key ${primaryKey}...`);

const token = core.getInput(Inputs.Token, { required: true });
const octokit = getOctokit(token);
Expand All @@ -80,7 +80,7 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
ref: github.context.ref
});
} else {
core.info(
utils.info(
`The cache with the key ${primaryKey} won't be purged. Not saving a new cache.`
);

Expand All @@ -92,14 +92,14 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {

await collectGarbage();

core.info(`Saving a new cache with the key ${primaryKey}...`);
utils.info(`Saving a new cache with the key ${primaryKey}...`);

cacheId = await cache.saveCache(cachePaths, primaryKey, {
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
});

if (cacheId != -1) {
core.info(`Cache saved with the key ${primaryKey}.`);
utils.info(`Cache saved with the key ${primaryKey}.`);

await purgeCaches({ key: primaryKey, lookupOnly: false, time });
}
Expand Down
5 changes: 5 additions & 0 deletions src/utils/actionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import * as github from "@actions/github";
import { dedent } from "ts-dedent";

import { Inputs, RefKey } from "../constants";

Expand Down Expand Up @@ -192,3 +193,7 @@ export function getMaxDate({
}

export const stringify = (value: any) => JSON.stringify(value, null, 2);

export const info = (message: string) => {
core.info(dedent(message));
};

0 comments on commit d952be2

Please sign in to comment.