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
13 changes: 9 additions & 4 deletions lib/cli/build/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ export async function build(args: string[]) {
);
}

const { inProgress, done, unmount } = progress();
const { inProgress, done, fail, unmount } = progress();
try {
for (const workflowPath of workflowPaths) {
await inProgress(`Building ${workflowPath}`);
await _buildWorkflow(workflowPath);
await done(getBuildTargetPath(workflowPath));
try {
await inProgress(`Building ${workflowPath}`);
await _buildWorkflow(workflowPath);
await done(getBuildTargetPath(workflowPath));
} catch (error) {
await fail(workflowPath);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consider adding more context to the fail message, such as the specific error that occurred. This would help users diagnose issues more effectively.

Suggested change
await fail(workflowPath);
await fail(`${workflowPath} - ${error.message}`);

throw error;
}
}
} finally {
unmount();
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/install/action-yaml.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { parse as parseYaml } from "yaml";
import { getFileContent } from "../../internal/git";
import { getFileContent } from "../lib/github";

export type ActionYaml = {
inputs?: Record<
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/install/commit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs";
import path from "node:path";
import { getCommit as getCommitFromGithub } from "../../internal/git";
import { getCommit as getCommitFromGithub } from "../lib/github";

type Cache = {
commit: string;
Expand Down
78 changes: 45 additions & 33 deletions lib/cli/install/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
saveActionsJson,
saveActionsLockJson,
} from "../../internal/actions";
import { getLatestRelease } from "../../internal/git";
import { getLatestRelease } from "../lib/github";
import { success } from "../ui/Message";
import { progress } from "../ui/Progress";
import { type ActionYaml, downloadActionYaml } from "./action-yaml";
Expand Down Expand Up @@ -50,47 +50,59 @@ export async function install(args: string[]) {
}
}

const { inProgress, done, clear, unmount } = progress();
const { inProgress, fail, done, clear, unmount } = progress();
try {
for (const parsedAction of Object.values(targetActions)) {
await inProgress(
`Installing ${parsedAction.fullName}@${parsedAction.version}`,
);

// get tag name
const tagName = await (async () => {
if (parsedAction.version == null || parsedAction.version === "latest") {
const latestRelease = await getLatestRelease(
try {
// get tag name
const tagName = await (async () => {
if (
parsedAction.version == null ||
parsedAction.version === "latest"
) {
const latestRelease = await getLatestRelease(
parsedAction.owner,
parsedAction.repo,
);
return latestRelease.tag_name;
}
return parsedAction.version;
})();

// get commit by tag name
const sha = await (async () => {
const lockedSha =
actionsLockJson.actions[`${parsedAction.fullName}@${tagName}`];
if (lockedSha != null) return lockedSha;
return await getCommit(
parsedAction.owner,
parsedAction.repo,
tagName,
);
return latestRelease.tag_name;
}
return parsedAction.version;
})();

// get commit by tag name
const sha = await (async () => {
const lockedSha =
actionsLockJson.actions[`${parsedAction.fullName}@${tagName}`];
if (lockedSha != null) return lockedSha;
return await getCommit(parsedAction.owner, parsedAction.repo, tagName);
})();

// update actions.json and actions-lock.json
actionsJson[parsedAction.fullName] = tagName;
actionsLockJson.actions[`${parsedAction.fullName}@${tagName}`] = sha;

// download action.yml
const actionYaml = await downloadActionYaml(
parsedAction.owner,
parsedAction.repo,
parsedAction.action,
sha,
);
actionYamls[parsedAction.fullName] = actionYaml;

await done(`${parsedAction.fullName}@${tagName}`);
})();

// update actions.json and actions-lock.json
actionsJson[parsedAction.fullName] = tagName;
actionsLockJson.actions[`${parsedAction.fullName}@${tagName}`] = sha;

// download action.yml
const actionYaml = await downloadActionYaml(
parsedAction.owner,
parsedAction.repo,
parsedAction.action,
sha,
);
actionYamls[parsedAction.fullName] = actionYaml;

await done(`${parsedAction.fullName}@${tagName}`);
} catch (error) {
await fail(`${parsedAction.fullName}@${parsedAction.version}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the build process, adding the error message to the fail message would provide more context to the user.

Suggested change
await fail(`${parsedAction.fullName}@${parsedAction.version}`);
await fail(`${parsedAction.fullName}@${parsedAction.version} - ${error.message}`);

throw error;
}
}

await inProgress("Building type definitions...");
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/install/type-def.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toUpperCamelCase } from "../../internal/util";
import { toUpperCamelCase } from "../lib/util";
import type { ActionYaml } from "./action-yaml";

const actionJs = `import * as fs from "node:fs";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
23 changes: 22 additions & 1 deletion lib/cli/ui/Progress.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, Static, Text } from "ink";
import Spinner from "./Spinner";

export type ProgressStatus = "in-progress" | "done";
export type ProgressStatus = "in-progress" | "done" | "fail";

export type ProgressProps = {
status: ProgressStatus;
Expand Down Expand Up @@ -32,6 +32,24 @@ export default function Progress({ status, title }: ProgressProps) {
</Static>
);
}

if (status === "fail") {
return (
<Static items={[title]}>
{(title) => (
<Text key={title}>
<Text color="red" bold>
</Text>
<Text color="red" bold>
{" "}
{title}
</Text>
</Text>
)}
</Static>
);
}
}

export function progress() {
Expand All @@ -45,6 +63,9 @@ export function progress() {
done: async (title: string) => {
rerender(<Progress status="done" title={title} />);
},
fail: async (title: string) => {
rerender(<Progress status="fail" title={title} />);
},
clear: async () => {
rerender(null);
await new Promise((resolve) => setTimeout(resolve)); // wait for the message to be cleared
Expand Down