mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 00:00:46 +00:00
fix(cli): update wmill script push
This commit is contained in:
+3
-9
@@ -26,8 +26,7 @@ const alreadySynced: string[] = [];
|
||||
export async function pushFlow(
|
||||
workspace: string,
|
||||
remotePath: string,
|
||||
localFlowPath: string,
|
||||
workspaceId: string
|
||||
localFlowPath: string
|
||||
): Promise<void> {
|
||||
if (alreadySynced.includes(localFlowPath)) {
|
||||
return;
|
||||
@@ -36,7 +35,7 @@ export async function pushFlow(
|
||||
let flow: Flow | undefined = undefined;
|
||||
try {
|
||||
flow = await FlowService.getFlowByPath({
|
||||
workspace: workspaceId,
|
||||
workspace: workspace,
|
||||
path: remotePath,
|
||||
});
|
||||
} catch {
|
||||
@@ -102,12 +101,7 @@ async function push(opts: Options, filePath: string, remotePath: string) {
|
||||
const workspace = await resolveWorkspace(opts);
|
||||
await requireLogin(opts);
|
||||
|
||||
await pushFlow(
|
||||
workspace.workspaceId,
|
||||
remotePath,
|
||||
filePath,
|
||||
workspace.workspaceId
|
||||
);
|
||||
await pushFlow(workspace.workspaceId, remotePath, filePath);
|
||||
console.log(colors.bold.underline.green("Flow pushed"));
|
||||
}
|
||||
|
||||
|
||||
+10
-64
@@ -1,5 +1,5 @@
|
||||
// deno-lint-ignore-file no-explicit-any
|
||||
import { GlobalOptions, parseFromFile, removeType } from "./types.ts";
|
||||
import { GlobalOptions } from "./types.ts";
|
||||
import { requireLogin, resolveWorkspace, validatePath } from "./context.ts";
|
||||
import {
|
||||
colors,
|
||||
@@ -38,18 +38,15 @@ async function push(opts: PushOptions, filePath: string) {
|
||||
if (!fstat.isFile) {
|
||||
throw new Error("file path must refer to a file.");
|
||||
}
|
||||
let contentPath: string;
|
||||
let metaPath: string | undefined;
|
||||
|
||||
if (filePath.endsWith(".script.json") || filePath.endsWith(".script.yaml")) {
|
||||
metaPath = filePath;
|
||||
contentPath = await findContentFile(filePath);
|
||||
} else {
|
||||
contentPath = filePath;
|
||||
metaPath = undefined;
|
||||
throw Error(
|
||||
"Cannot push a script metadata file, point to the script content file instead (.py, .ts, .go|.sh)"
|
||||
);
|
||||
}
|
||||
|
||||
await requireLogin(opts);
|
||||
await pushScript(metaPath, contentPath, workspace.workspaceId, remotePath);
|
||||
await handleFile(filePath, workspace.workspaceId, []);
|
||||
log.info(colors.bold.underline.green(`Script ${remotePath} pushed`));
|
||||
}
|
||||
|
||||
@@ -60,12 +57,7 @@ export async function handleScriptMetadata(
|
||||
): Promise<boolean> {
|
||||
if (path.endsWith(".script.json") || path.endsWith(".script.yaml")) {
|
||||
const contentPath = await findContentFile(path);
|
||||
return handleFile(
|
||||
contentPath,
|
||||
await Deno.readTextFile(contentPath),
|
||||
workspace,
|
||||
alreadySynced
|
||||
);
|
||||
return handleFile(contentPath, workspace, alreadySynced);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -73,7 +65,6 @@ export async function handleScriptMetadata(
|
||||
|
||||
export async function handleFile(
|
||||
path: string,
|
||||
content: string,
|
||||
workspace: string,
|
||||
alreadySynced: string[]
|
||||
): Promise<boolean> {
|
||||
@@ -118,6 +109,7 @@ export async function handleFile(
|
||||
} catch {
|
||||
log.debug(`Script ${remotePath} does not exist on remote`);
|
||||
}
|
||||
const content = await Deno.readTextFile(path);
|
||||
|
||||
if (remote) {
|
||||
if (content === remote.content) {
|
||||
@@ -242,52 +234,6 @@ export function inferContentTypeFromFilePath(
|
||||
return language;
|
||||
}
|
||||
|
||||
export async function pushScript(
|
||||
filePath: string | undefined,
|
||||
contentPath: string,
|
||||
workspace: string,
|
||||
remotePath: string
|
||||
) {
|
||||
remotePath = removeType(remotePath, "script");
|
||||
|
||||
const data: ScriptFile | undefined = filePath
|
||||
? parseFromFile(filePath)
|
||||
: undefined;
|
||||
const content = await Deno.readTextFile(contentPath);
|
||||
|
||||
const language = inferContentTypeFromFilePath(contentPath);
|
||||
let parent_hash = data?.parent_hash;
|
||||
if (!parent_hash) {
|
||||
try {
|
||||
parent_hash = (
|
||||
await ScriptService.getScriptByPath({
|
||||
workspace: workspace,
|
||||
path: remotePath,
|
||||
})
|
||||
).hash;
|
||||
} catch {
|
||||
/* no parent. New Script. */
|
||||
}
|
||||
}
|
||||
|
||||
log.info(colors.bold.yellow(`Pushing script ${remotePath}...`));
|
||||
await ScriptService.createScript({
|
||||
workspace: workspace,
|
||||
requestBody: {
|
||||
path: remotePath,
|
||||
summary: data?.summary ?? "",
|
||||
content: content,
|
||||
description: data?.description ?? "",
|
||||
language: language as NewScript.language,
|
||||
is_template: data?.is_template,
|
||||
kind: data?.kind as NewScript.kind,
|
||||
lock: data?.lock,
|
||||
parent_hash: parent_hash,
|
||||
schema: data?.schema,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function list(opts: GlobalOptions & { showArchived?: boolean }) {
|
||||
const workspace = await resolveWorkspace(opts);
|
||||
await requireLogin(opts);
|
||||
@@ -473,9 +419,9 @@ const command = new Command()
|
||||
.action(list as any)
|
||||
.command(
|
||||
"push",
|
||||
"push a local script spec. This overrides any remote versions. Can use a script file (.ts, .js, .py, .sh) or a script spec file (.json). "
|
||||
"push a local script spec. This overrides any remote versions. Use the script file (.ts, .js, .py, .sh)"
|
||||
)
|
||||
.arguments("<file_path:file>")
|
||||
.arguments("<path:file>")
|
||||
.action(push as any)
|
||||
.command("show", "show a scripts content")
|
||||
.arguments("<path:file>")
|
||||
|
||||
+2
-12
@@ -662,12 +662,7 @@ async function push(
|
||||
}
|
||||
continue;
|
||||
} else if (
|
||||
await handleFile(
|
||||
change.path,
|
||||
change.after,
|
||||
workspace.workspaceId,
|
||||
alreadySynced
|
||||
)
|
||||
await handleFile(change.path, workspace.workspaceId, alreadySynced)
|
||||
) {
|
||||
if (!opts.raw && stateExists) {
|
||||
await Deno.writeTextFile(stateTarget, change.after);
|
||||
@@ -700,12 +695,7 @@ async function push(
|
||||
) {
|
||||
continue;
|
||||
} else if (
|
||||
await handleFile(
|
||||
change.path,
|
||||
change.content,
|
||||
workspace.workspaceId,
|
||||
alreadySynced
|
||||
)
|
||||
await handleFile(change.path, workspace.workspaceId, alreadySynced)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-4
@@ -8,7 +8,6 @@ import {
|
||||
} from "https://deno.land/std@0.184.0/yaml/mod.ts";
|
||||
import { equal } from "https://deno.land/x/equal@v1.5.0/equal.ts";
|
||||
import { pushFolder } from "./folder.ts";
|
||||
import { pushScript } from "./script.ts";
|
||||
import { pushFlow } from "./flow.ts";
|
||||
import { pushResource } from "./resource.ts";
|
||||
import { pushResourceType } from "./resource-type.ts";
|
||||
@@ -111,13 +110,11 @@ export function pushObj(
|
||||
pushApp(workspace, p, befObj, newObj, checkForCreate);
|
||||
} else if (typeEnding === "folder") {
|
||||
pushFolder(workspace, p, befObj, newObj, checkForCreate);
|
||||
} else if (typeEnding === "script") {
|
||||
pushScript(workspace, p, befObj, newObj);
|
||||
} else if (typeEnding === "variable") {
|
||||
pushVariable(workspace, p, befObj, newObj, plainSecrets, checkForCreate);
|
||||
} else if (typeEnding === "flow") {
|
||||
const flowName = p.split(".flow/")[0];
|
||||
pushFlow(workspace, flowName, flowName + ".flow", workspace);
|
||||
pushFlow(workspace, flowName, flowName + ".flow");
|
||||
} else if (typeEnding === "resource") {
|
||||
pushResource(workspace, p, befObj, newObj, checkForCreate);
|
||||
} else if (typeEnding === "resource-type") {
|
||||
|
||||
Reference in New Issue
Block a user