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

Organize Main Function to Separate File #157

Merged
merged 1 commit into from
Feb 19, 2024
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
22 changes: 21 additions & 1 deletion dist/index.js

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

35 changes: 1 addition & 34 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,4 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { getCacheKey, getCachePaths } from "./cache.js";
import { enableYarn, yarnInstall } from "./yarn/index.js";

async function main(): Promise<void> {
await core.group("Enabling Yarn", async () => {
await enableYarn();
});

const cacheKey = await core.group("Getting cache key", getCacheKey);
const cachePaths = await core.group("Getting cache paths", getCachePaths);

const cacheFound = await core.group("Restoring cache", async () => {
const cacheId = await cache.restoreCache(cachePaths.slice(), cacheKey);
if (cacheId === undefined) {
core.warning("Cache not found");
return false;
}
return true;
});

if (cacheFound) {
core.info("Cache restored successfully");
return;
}

await core.group("Installing dependencies", async () => {
return yarnInstall();
});

await core.group("Saving cache", async () => {
return cache.saveCache(cachePaths.slice(), cacheKey);
});
}
import { main } from "./main.js";

main().catch((err) => core.setFailed(err));
35 changes: 35 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as cache from "@actions/cache";
import * as core from "@actions/core";
import { getCacheKey, getCachePaths } from "./cache.js";
import { enableYarn, yarnInstall } from "./yarn/index.js";

export async function main(): Promise<void> {
await core.group("Enabling Yarn", async () => {
await enableYarn();
});

const cacheKey = await core.group("Getting cache key", getCacheKey);
const cachePaths = await core.group("Getting cache paths", getCachePaths);

const cacheFound = await core.group("Restoring cache", async () => {
const cacheId = await cache.restoreCache(cachePaths.slice(), cacheKey);
if (cacheId === undefined) {
core.warning("Cache not found");
return false;
}
return true;
});

if (cacheFound) {
core.info("Cache restored successfully");
return;
}

await core.group("Installing dependencies", async () => {
return yarnInstall();
});

await core.group("Saving cache", async () => {
return cache.saveCache(cachePaths.slice(), cacheKey);
});
}
Loading