Skip to content

Commit 48152d6

Browse files
Workflows commands (#7015)
* add commands * add command description * change private beta message to open beta * refactor to use defineCommand util * add changeset * update snapshots * remove extraneous periods * remove redundant file Co-authored-by: Luís Duarte <[email protected]>
1 parent 244aa57 commit 48152d6

File tree

17 files changed

+776
-0
lines changed

17 files changed

+776
-0
lines changed

.changeset/moody-seals-smash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
add `wrangler workflows ...` commands

packages/wrangler/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@
7575
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
7676
"blake3-wasm": "^2.1.5",
7777
"chokidar": "^3.5.3",
78+
"date-fns": "^4.1.0",
7879
"esbuild": "0.17.19",
80+
"itty-time": "^1.0.6",
7981
"miniflare": "workspace:*",
8082
"nanoid": "^3.3.3",
8183
"path-to-regexp": "^6.3.0",

packages/wrangler/src/__tests__/core/command-registration.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ describe("Command Registration", () => {
191191
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
192192
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
193193
wrangler ai 🤖 Manage AI models
194+
wrangler workflows 🔁 Manage Workflows [open-beta]
194195
wrangler login 🔓 Login to Cloudflare
195196
wrangler logout 🚪 Logout from Cloudflare
196197
wrangler whoami 🕵️ Retrieve your user information

packages/wrangler/src/__tests__/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe("wrangler", () => {
6161
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
6262
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
6363
wrangler ai 🤖 Manage AI models
64+
wrangler workflows 🔁 Manage Workflows [open-beta]
6465
wrangler login 🔓 Login to Cloudflare
6566
wrangler logout 🚪 Logout from Cloudflare
6667
wrangler whoami 🕵️ Retrieve your user information
@@ -117,6 +118,7 @@ describe("wrangler", () => {
117118
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
118119
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
119120
wrangler ai 🤖 Manage AI models
121+
wrangler workflows 🔁 Manage Workflows [open-beta]
120122
wrangler login 🔓 Login to Cloudflare
121123
wrangler logout 🚪 Logout from Cloudflare
122124
wrangler whoami 🕵️ Retrieve your user information

packages/wrangler/src/__tests__/versions/versions.help.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("versions --help", () => {
3737
wrangler pubsub 📮 Manage Pub/Sub brokers [private beta]
3838
wrangler dispatch-namespace 🏗️ Manage dispatch namespaces
3939
wrangler ai 🤖 Manage AI models
40+
wrangler workflows 🔁 Manage Workflows [open-beta]
4041
wrangler login 🔓 Login to Cloudflare
4142
wrangler logout 🚪 Logout from Cloudflare
4243
wrangler whoami 🕵️ Retrieve your user information

packages/wrangler/src/core/teams.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export type Teams =
1414
| "Product: AI"
1515
| "Product: Hyperdrive"
1616
| "Product: Vectorize"
17+
| "Product: Workflows"
1718
| "Product: Cloudchamber";

packages/wrangler/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { generateHandler, generateOptions } from "./generate";
4343
import { hyperdrive } from "./hyperdrive/index";
4444
import { initHandler, initOptions } from "./init";
4545
import "./kv";
46+
import "./workflows";
4647
import { logBuildFailure, logger, LOGGER_LEVELS } from "./logger";
4748
import * as metrics from "./metrics";
4849
import { mTlsCertificateCommands } from "./mtls-certificate/cli";
@@ -608,6 +609,9 @@ export function createCLIParser(argv: string[]) {
608609
return ai(aiYargs.command(subHelp));
609610
});
610611

612+
// workflows
613+
register.registerNamespace("workflows");
614+
611615
// pipelines
612616
wrangler.command("pipelines", false, (pipelinesYargs) => {
613617
return pipelines(pipelinesYargs.command(subHelp));
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { fetchResult } from "../../cfetch";
2+
import { defineCommand } from "../../core";
3+
import { logger } from "../../logger";
4+
import { requireAuth } from "../../user";
5+
6+
defineCommand({
7+
command: "wrangler workflows delete",
8+
metadata: {
9+
description:
10+
"Delete workflow - when deleting a workflow, it will also delete it's own instances",
11+
owner: "Product: Workflows",
12+
status: "open-beta",
13+
},
14+
15+
args: {
16+
name: {
17+
describe: "Name of the workflow",
18+
type: "string",
19+
demandOption: true,
20+
},
21+
},
22+
positionalArgs: ["name"],
23+
24+
async handler(args, { config }) {
25+
const accountId = await requireAuth(config);
26+
27+
await fetchResult(`/accounts/${accountId}/workflows/${args.name}`, {
28+
method: "DELETE",
29+
});
30+
31+
logger.info(`Workflow "${args.name}" was successfully removed`);
32+
},
33+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { logRaw } from "@cloudflare/cli";
2+
import { white } from "@cloudflare/cli/colors";
3+
import { fetchResult } from "../../cfetch";
4+
import { defineCommand } from "../../core";
5+
import { requireAuth } from "../../user";
6+
import formatLabelledValues from "../../utils/render-labelled-values";
7+
import type { Version, Workflow } from "../types";
8+
9+
defineCommand({
10+
command: "wrangler workflows describe",
11+
metadata: {
12+
description: "Describe Workflow resource",
13+
owner: "Product: Workflows",
14+
status: "open-beta",
15+
},
16+
args: {
17+
name: {
18+
describe: "Name of the workflow",
19+
type: "string",
20+
demandOption: true,
21+
},
22+
},
23+
positionalArgs: ["name"],
24+
async handler(args, { config }) {
25+
const accountId = await requireAuth(config);
26+
27+
const workflow = await fetchResult<Workflow>(
28+
`/accounts/${accountId}/workflows/${args.name}`
29+
);
30+
31+
const versions = await fetchResult<Version[]>(
32+
`/accounts/${accountId}/workflows/${args.name}/versions`
33+
);
34+
35+
const latestVersion = versions[0];
36+
37+
logRaw(
38+
formatLabelledValues({
39+
Name: workflow.name,
40+
Id: workflow.id,
41+
"Script Name": workflow.script_name,
42+
"Class Name": workflow.class_name,
43+
"Created On": workflow.created_on,
44+
"Modified On": workflow.modified_on,
45+
})
46+
);
47+
logRaw(white("Latest Version:"));
48+
logRaw(
49+
formatLabelledValues(
50+
{
51+
Id: latestVersion.id,
52+
"Created On": workflow.created_on,
53+
"Modified On": workflow.modified_on,
54+
},
55+
{ indentationCount: 2 }
56+
)
57+
);
58+
},
59+
});

0 commit comments

Comments
 (0)