viza 1.7.44 → 1.7.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/cli/options.js +2 -1
- package/dist/src/cli/program.js +2 -0
- package/dist/src/commands/dispatch/register.js +7 -0
- package/dist/src/commands/dispatch/runs/register.js +19 -0
- package/dist/src/commands/dispatch/runs/runs.js +72 -0
- package/dist/src/commands/dispatch/runs/show-runs.js +111 -0
- package/dist/src/commands/infra/command-hub/command-hub.js +3 -2
- package/dist/src/context/hubIntent.js +6 -0
- package/dist/src/types/github.js +1 -0
- package/package.json +1 -1
package/dist/src/cli/options.js
CHANGED
|
@@ -2,5 +2,6 @@ export function registerGlobalOptions(program) {
|
|
|
2
2
|
program
|
|
3
3
|
.option("--status", "Show status only (no execution)")
|
|
4
4
|
.option("--remove-log", "Remove execution logs after completion", false)
|
|
5
|
-
.option("--self-hosted", "Use self-hosted runner (viza-builder)", false)
|
|
5
|
+
.option("--self-hosted", "Use self-hosted runner (viza-builder)", false)
|
|
6
|
+
.option("--cloud-runner", "Use cloud managed runner (GitHub-hosted)", false);
|
|
6
7
|
}
|
package/dist/src/cli/program.js
CHANGED
|
@@ -9,6 +9,7 @@ import { registerInfraCommand } from "../commands/infra/register.js";
|
|
|
9
9
|
import { registerAgeCommand } from "../commands/age/register.js";
|
|
10
10
|
import { registerBillingCommand } from "../commands/billing/register.js";
|
|
11
11
|
import { registerGithubCommand } from "../commands/github/register.js";
|
|
12
|
+
import { registerDispatchCommand } from "../commands/dispatch/register.js";
|
|
12
13
|
export function createProgram() {
|
|
13
14
|
const program = new Command();
|
|
14
15
|
program
|
|
@@ -20,6 +21,7 @@ export function createProgram() {
|
|
|
20
21
|
registerAwsCommand(program);
|
|
21
22
|
registerBillingCommand(program);
|
|
22
23
|
registerBootstrapCommand(program);
|
|
24
|
+
registerDispatchCommand(program);
|
|
23
25
|
registerGithubCommand(program);
|
|
24
26
|
registerInfraCommand(program);
|
|
25
27
|
registerLoginCommand(program);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { runsCommand } from "./runs.js";
|
|
2
|
+
import { getResolvedOptions } from "../../../cli/resolveOptions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Register:
|
|
5
|
+
* viza dispatch runs
|
|
6
|
+
*/
|
|
7
|
+
export function registerDispatchRunsCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command("runs")
|
|
10
|
+
.description("List latest dispatch workflow runs")
|
|
11
|
+
.option("--prod", "Use production environment")
|
|
12
|
+
.option("--dev", "Use development environment")
|
|
13
|
+
.option("--app", "Open GitHub Actions page for app pipelines instead of querying hub")
|
|
14
|
+
.option("--limit <n>", "Limit number of runs to fetch", "20")
|
|
15
|
+
.action(async (opts, command) => {
|
|
16
|
+
const fullOpts = getResolvedOptions(command);
|
|
17
|
+
await runsCommand(fullOpts);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { resolveEnv } from "../../../context/env.js";
|
|
2
|
+
import { resolveRuntimeHubIntent } from "../../../context/hubIntent.js";
|
|
3
|
+
import { dispatchIntentAndWait } from "../../../core/dispatch.js";
|
|
4
|
+
import { showDispatchRuns } from "./show-runs.js";
|
|
5
|
+
const TARGET_TEAMS = {
|
|
6
|
+
"dev": [
|
|
7
|
+
"viza-designer",
|
|
8
|
+
"viza-deployer",
|
|
9
|
+
"viza-manager",
|
|
10
|
+
"viza-admin",
|
|
11
|
+
"viza-super"
|
|
12
|
+
],
|
|
13
|
+
"prod": [
|
|
14
|
+
"viza-publisher",
|
|
15
|
+
"viza-admin",
|
|
16
|
+
"viza-super"
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* viza dispatch runs
|
|
21
|
+
*
|
|
22
|
+
* Flow:
|
|
23
|
+
* 1) Resolve env (deterministic)
|
|
24
|
+
* 2) If --app → show GitHub Actions link locally (no dispatch)
|
|
25
|
+
* 3) Otherwise dispatch intent to hub
|
|
26
|
+
*/
|
|
27
|
+
export async function runsCommand(options) {
|
|
28
|
+
// 1️⃣ Resolve environment
|
|
29
|
+
const env = resolveEnv(options);
|
|
30
|
+
const intent = resolveRuntimeHubIntent();
|
|
31
|
+
// Resolve allowed teams (same contract as other commands)
|
|
32
|
+
const allowedTeams = TARGET_TEAMS[env];
|
|
33
|
+
// 2️⃣ Handle --app locally (do NOT dispatch)
|
|
34
|
+
if (options.app === true) {
|
|
35
|
+
const url = env === "prod"
|
|
36
|
+
? "https://github.com/Modo-Infra/publish-app/actions"
|
|
37
|
+
: "https://github.com/Modo-Infra/build-app/actions";
|
|
38
|
+
console.log("\n📦 App pipeline runs:");
|
|
39
|
+
console.log(url);
|
|
40
|
+
console.log();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// Parse limit option
|
|
44
|
+
let limit = undefined;
|
|
45
|
+
if (options.limit !== undefined) {
|
|
46
|
+
const parsed = Number(options.limit);
|
|
47
|
+
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
48
|
+
limit = parsed;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// 3️⃣ Dispatch intent to hub
|
|
52
|
+
const result = await dispatchIntentAndWait({
|
|
53
|
+
intent,
|
|
54
|
+
commandType: "dispatch.runs",
|
|
55
|
+
infraKey: "core",
|
|
56
|
+
targetEnv: env,
|
|
57
|
+
allowedTeams,
|
|
58
|
+
selfHosted: options.selfHosted === true,
|
|
59
|
+
keepLog: options.removeLog !== true,
|
|
60
|
+
flowGates: {
|
|
61
|
+
secrets: false,
|
|
62
|
+
},
|
|
63
|
+
payload: {
|
|
64
|
+
...(limit ? { limit } : {}),
|
|
65
|
+
},
|
|
66
|
+
}, {
|
|
67
|
+
status: false,
|
|
68
|
+
log: "show",
|
|
69
|
+
});
|
|
70
|
+
await showDispatchRuns(result);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
function formatAge(iso) {
|
|
2
|
+
const diff = Date.now() - new Date(iso).getTime();
|
|
3
|
+
const sec = Math.floor(diff / 1000);
|
|
4
|
+
if (sec < 60)
|
|
5
|
+
return `${sec}s`;
|
|
6
|
+
const min = Math.floor(sec / 60);
|
|
7
|
+
const remSec = sec % 60;
|
|
8
|
+
// < 10 minutes → "Xm Ys"
|
|
9
|
+
if (min < 10)
|
|
10
|
+
return `${min}m ${remSec}s`;
|
|
11
|
+
// < 60 minutes → "Xm"
|
|
12
|
+
if (min < 60)
|
|
13
|
+
return `${min}m`;
|
|
14
|
+
const hr = Math.floor(min / 60);
|
|
15
|
+
const remMin = min % 60;
|
|
16
|
+
// < 10 hours → "Xh Ym"
|
|
17
|
+
if (hr < 10)
|
|
18
|
+
return `${hr}h ${remMin}m`;
|
|
19
|
+
// ≥ 10 hours → "Xh"
|
|
20
|
+
return `${hr}h`;
|
|
21
|
+
}
|
|
22
|
+
function formatDuration(start, end) {
|
|
23
|
+
const diff = new Date(end).getTime() - new Date(start).getTime();
|
|
24
|
+
const sec = Math.floor(diff / 1000);
|
|
25
|
+
if (sec < 60)
|
|
26
|
+
return `${sec}s`;
|
|
27
|
+
const min = Math.floor(sec / 60);
|
|
28
|
+
const rem = sec % 60;
|
|
29
|
+
return `${min}m ${rem}s`;
|
|
30
|
+
}
|
|
31
|
+
function pad(v, n) {
|
|
32
|
+
return v.padEnd(n, " ");
|
|
33
|
+
}
|
|
34
|
+
export async function showDispatchRuns(result) {
|
|
35
|
+
const env = result;
|
|
36
|
+
if (env.status !== "success" ||
|
|
37
|
+
env.kind !== "runtime" ||
|
|
38
|
+
!env.data?.result) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const { runs } = env.data.result;
|
|
42
|
+
if (!Array.isArray(runs)) {
|
|
43
|
+
throw new Error("invalid_dispatch_runs_result_shape");
|
|
44
|
+
}
|
|
45
|
+
console.log("\n📋 Dispatch Runs");
|
|
46
|
+
console.log("─".repeat(118));
|
|
47
|
+
const header = [
|
|
48
|
+
pad("RUN", 12),
|
|
49
|
+
pad("STATUS", 14),
|
|
50
|
+
pad("CONCLUSION", 14),
|
|
51
|
+
pad("COMMITTER", 38),
|
|
52
|
+
pad("AGE", 12),
|
|
53
|
+
pad("DURATION", 12),
|
|
54
|
+
"ATTEMPT",
|
|
55
|
+
].join(" ");
|
|
56
|
+
console.log(header);
|
|
57
|
+
console.log("─".repeat(118));
|
|
58
|
+
for (const run of runs) {
|
|
59
|
+
let status;
|
|
60
|
+
let conclusion;
|
|
61
|
+
if (run.status === "completed") {
|
|
62
|
+
status = "completed";
|
|
63
|
+
switch (run.conclusion) {
|
|
64
|
+
case "success":
|
|
65
|
+
conclusion = "✅ success";
|
|
66
|
+
break;
|
|
67
|
+
case "failure":
|
|
68
|
+
conclusion = "❌ failure";
|
|
69
|
+
break;
|
|
70
|
+
case "cancelled":
|
|
71
|
+
conclusion = "⚪ cancelled";
|
|
72
|
+
break;
|
|
73
|
+
case "timed_out":
|
|
74
|
+
conclusion = "⏱ timed_out";
|
|
75
|
+
break;
|
|
76
|
+
case "skipped":
|
|
77
|
+
conclusion = "⏭ skipped";
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
conclusion = run.conclusion ?? "-";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (run.status === "in_progress") {
|
|
84
|
+
status = "🟡 in_progress";
|
|
85
|
+
conclusion = "-";
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
status = "⏳ queued";
|
|
89
|
+
conclusion = "-";
|
|
90
|
+
}
|
|
91
|
+
const committer = run.committer
|
|
92
|
+
? `${run.committer.name} <${run.committer.email}>`
|
|
93
|
+
: "unknown";
|
|
94
|
+
const age = formatAge(run.createdAt);
|
|
95
|
+
const duration = run.status === "completed"
|
|
96
|
+
? formatDuration(run.createdAt, run.updatedAt)
|
|
97
|
+
: "-";
|
|
98
|
+
const row = [
|
|
99
|
+
pad(String(run.id), 12),
|
|
100
|
+
pad(status, 14),
|
|
101
|
+
pad(conclusion, 14),
|
|
102
|
+
pad(committer, 38),
|
|
103
|
+
pad(age, 12),
|
|
104
|
+
pad(duration, 12),
|
|
105
|
+
`#${run.attempt}`,
|
|
106
|
+
].join(" ");
|
|
107
|
+
console.log(row);
|
|
108
|
+
}
|
|
109
|
+
console.log("─".repeat(118));
|
|
110
|
+
console.log();
|
|
111
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveEnv } from "../../../context/env.js";
|
|
2
|
-
import {
|
|
2
|
+
import { resolveHubIntent } from "../../../context/hubIntent.js";
|
|
3
3
|
import { dispatchIntentAndWait } from "../../../core/dispatch.js";
|
|
4
4
|
/**
|
|
5
5
|
* Target teams for `viza login aws`.
|
|
@@ -29,7 +29,8 @@ const TARGET_TEAMS = {
|
|
|
29
29
|
export async function deployCommandHubCommand(options) {
|
|
30
30
|
// 1) Resolve environment
|
|
31
31
|
const env = resolveEnv(options);
|
|
32
|
-
const
|
|
32
|
+
const cloudRunner = options.cloudRunner === true;
|
|
33
|
+
const intent = resolveHubIntent(env, cloudRunner);
|
|
33
34
|
// Resolve allowed teams
|
|
34
35
|
// - Dispatch mode: restrict by targetEnv
|
|
35
36
|
// - Status mode: allow union of all env teams (read-only query)
|
|
@@ -27,3 +27,9 @@ export function resolveAppHubIntent(env) {
|
|
|
27
27
|
export function resolveRuntimeHubIntent() {
|
|
28
28
|
return RUNTIME_HUB_INTENT;
|
|
29
29
|
}
|
|
30
|
+
export function resolveHubIntent(env, cloudRunner) {
|
|
31
|
+
if (cloudRunner) {
|
|
32
|
+
return resolveAppHubIntent(env);
|
|
33
|
+
}
|
|
34
|
+
return resolveResourceHubIntent(env);
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|