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
134 changes: 134 additions & 0 deletions lexicons/github/surface.snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{
"schemaVersion": 1,
"generatedAt": "2026-07-01T23:01:14.865Z",
"entries": {
"Concurrency": {
"kind": "property",
"resourceType": "GitHub::Actions::Concurrency"
},
"Container": {
"kind": "property",
"resourceType": "GitHub::Actions::Container"
},
"Defaults": {
"kind": "property",
"resourceType": "GitHub::Actions::Defaults"
},
"Environment": {
"kind": "property",
"resourceType": "GitHub::Actions::Environment"
},
"Job": {
"kind": "resource",
"resourceType": "GitHub::Actions::Job",
"props": [
"concurrency:false",
"container:false",
"continue-on-error:false",
"defaults:false",
"env:false",
"environment:false",
"if:false",
"name:false",
"needs:false",
"outputs:false",
"permissions:false",
"runs-on:true",
"services:false",
"snapshot:false",
"steps:false",
"strategy:false",
"timeout-minutes:false"
]
},
"Permissions": {
"kind": "property",
"resourceType": "GitHub::Actions::Permissions"
},
"PullRequestTargetTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::PullRequestTargetTrigger"
},
"PullRequestTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::PullRequestTrigger"
},
"PushTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::PushTrigger"
},
"RepositoryDispatchTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::RepositoryDispatchTrigger"
},
"ReusableWorkflowCallJob": {
"kind": "resource",
"resourceType": "GitHub::Actions::ReusableWorkflowCallJob",
"props": [
"concurrency:false",
"if:false",
"name:false",
"needs:false",
"permissions:false",
"secrets:false",
"strategy:false",
"uses:true",
"with:false"
]
},
"ScheduleTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::ScheduleTrigger"
},
"Service": {
"kind": "property",
"resourceType": "GitHub::Actions::Service"
},
"Step": {
"kind": "property",
"resourceType": "GitHub::Actions::Step"
},
"Strategy": {
"kind": "property",
"resourceType": "GitHub::Actions::Strategy"
},
"Workflow": {
"kind": "resource",
"resourceType": "GitHub::Actions::Workflow",
"props": [
"concurrency:false",
"defaults:false",
"env:false",
"jobs:true",
"name:false",
"on:true",
"permissions:false",
"run-name:false"
]
},
"WorkflowCallTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowCallTrigger"
},
"WorkflowDispatchTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowDispatchTrigger"
},
"WorkflowInput": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowInput"
},
"WorkflowOutput": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowOutput"
},
"WorkflowRunTrigger": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowRunTrigger"
},
"WorkflowSecret": {
"kind": "property",
"resourceType": "GitHub::Actions::WorkflowSecret"
}
}
}
198 changes: 198 additions & 0 deletions packages/core/src/cli/commands/lexicon-rolling-upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
/**
* `chant dev rolling-upgrade <lexicon-dir>` command implementation.
*
* Detects rolling-spec drift for the aws, azure, and github lexicons. These
* lexicons pin no version constant — "latest" is fetched on every regen. This
* command regenerates from current-latest, diffs the produced API surface
* against the committed baseline (surface.snapshot.json), and REPORTS the
* result. It is a dry run: it never opens a PR, updates a branch, or writes the
* baseline. PR automation and scheduling live in #527.
*
* The PR label an eventual automation would apply is derived from severity:
* additive → `minor`, breaking → `major`. This command only prints it.
*/

import { existsSync } from "fs";
import { resolve } from "path";
import {
checkRollingUpgrade,
type RollingUpgradeResult,
} from "../../codegen/rolling-upgrade";

// ── Types ─────────────────────────────────────────────────────────────

export interface RollingUpgradeCliOptions {
/** Resolved path to the lexicon directory. */
lexiconDir: string;
/** Force re-fetch of the upstream spec (bypass cache). */
force?: boolean;
/** Print subprocess output while running. */
verbose?: boolean;
}

// ── Main entry ────────────────────────────────────────────────────────

/**
* Run the rolling-upgrade check and return the result.
* Returns a synthetic failed result when the directory is missing.
*/
export async function runRollingUpgrade(
opts: RollingUpgradeCliOptions,
): Promise<RollingUpgradeResult> {
const dir = resolve(opts.lexiconDir);

if (!existsSync(dir)) {
return {
lexicon: "aws",
hasUpgrade: false,
severity: "none",
delta: { added: [], changed: [], removed: [], severity: "none" },
deltaText: "",
validationOk: false,
failures: [{ step: "setup", output: `Lexicon directory not found: ${dir}` }],
apiVersionDelta: [],
freshSnapshot: null,
};
}

return checkRollingUpgrade({
lexiconDir: dir,
force: opts.force,
verbose: opts.verbose,
});
}

/**
* Map surface severity to the semver PR label an upgrade would carry.
* additive → minor, breaking → major, none → none.
*/
export function severityToLabel(severity: RollingUpgradeResult["severity"]): string {
if (severity === "breaking") return "major";
if (severity === "additive") return "minor";
return "none";
}

// ── Human-readable output ─────────────────────────────────────────────

const COLORS = {
green: "\x1b[32m",
yellow: "\x1b[33m",
red: "\x1b[31m",
gray: "\x1b[90m",
bold: "\x1b[1m",
reset: "\x1b[0m",
};

function useColors(): boolean {
return !process.env.NO_COLOR && process.stdout.isTTY !== false;
}

function c(text: string, code: string): string {
return useColors() ? `${code}${text}${COLORS.reset}` : text;
}

/**
* Print the rolling-upgrade result to stdout.
*/
export function printRollingUpgradeResult(result: RollingUpgradeResult, json: boolean): void {
if (json) {
console.log(
JSON.stringify(
{
lexicon: result.lexicon,
hasUpgrade: result.hasUpgrade,
severity: result.severity,
label: severityToLabel(result.severity),
validationOk: result.validationOk,
delta: result.delta,
apiVersionDelta: result.apiVersionDelta,
failures: result.failures,
},
null,
2,
),
);
return;
}

console.log(c(`Rolling upgrade check: ${result.lexicon}`, COLORS.bold));
console.log("");

// Surface delta — the review payload
if (result.deltaText) {
console.log(result.deltaText);
} else {
console.log(c("No surface changes.", COLORS.green));
}

// azure API-version delta
if (result.apiVersionDelta.length > 0) {
console.log("");
console.log(c(`API version changes (${result.apiVersionDelta.length}):`, COLORS.bold));
for (const v of result.apiVersionDelta) {
const arrow =
v.kind === "added"
? `+ ${v.provider} (${v.after})`
: v.kind === "removed"
? `- ${v.provider} (was ${v.before})`
: `~ ${v.provider}: ${v.before} -> ${v.after}`;
console.log(` ${arrow}`);
}
}

// Failures
if (result.failures.length > 0) {
console.log("");
console.log(c(`${result.failures.length} step(s) failed:`, COLORS.bold));
for (const f of result.failures) {
console.log(
c(
` FAIL [${f.step}]${f.exitCode !== undefined ? ` (exit ${f.exitCode})` : ""}`,
COLORS.red,
),
);
if (f.output) {
const indented = f.output
.split("\n")
.map((l) => ` ${l}`)
.join("\n");
console.log(c(indented, COLORS.gray));
}
}
}

console.log("");

// Decision line
const severityColor =
result.severity === "breaking"
? COLORS.red
: result.severity === "additive"
? COLORS.yellow
: COLORS.green;

const label = severityToLabel(result.severity);
const validationLabel = result.validationOk
? c("ok", COLORS.green)
: c("FAILED", COLORS.red);

console.log(
`Upgrade: ${result.hasUpgrade} Severity: ${c(result.severity, severityColor)} ` +
`Label: ${label} Validation: ${validationLabel}`,
);

if (result.hasUpgrade && result.validationOk) {
console.log(
c(
`A PR would be opened: chore(${result.lexicon}): regen from latest spec [${label}]`,
COLORS.gray,
),
);
} else if (result.hasUpgrade && !result.validationOk) {
console.log(
c("Surface moved but validation failed — no PR; surfaces as a report/issue (#527).", COLORS.yellow),
);
} else {
console.log(c("No surface change — no PR.", COLORS.gray));
}
}
14 changes: 13 additions & 1 deletion packages/core/src/cli/handlers/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,22 @@ export async function runDevPinnedUpgrade(ctx: CommandContext): Promise<number>
return 0;
}

export async function runDevRollingUpgrade(ctx: CommandContext): Promise<number> {
const dir = ctx.args.extraPositional ?? ".";
const { runRollingUpgrade, printRollingUpgradeResult } = await import("../commands/lexicon-rolling-upgrade");
const result = await runRollingUpgrade({
lexiconDir: resolve(dir),
force: ctx.args.force,
verbose: ctx.args.verbose,
});
printRollingUpgradeResult(result, ctx.args.format === "json");
return result.validationOk ? 0 : 1;
}

export async function runDevUnknown(ctx: CommandContext): Promise<number> {
console.error(formatError({
message: `Unknown dev subcommand: ${ctx.args.path}`,
hint: "Available: chant dev generate, chant dev publish, chant dev onboard, chant dev check-lexicon, chant dev surface-diff, chant dev pinned-upgrade",
hint: "Available: chant dev generate, chant dev publish, chant dev onboard, chant dev check-lexicon, chant dev surface-diff, chant dev pinned-upgrade, chant dev rolling-upgrade",
}));
return 1;
}
6 changes: 5 additions & 1 deletion packages/core/src/cli/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ENV_VAR, unknownEnvError } from "../env";
import { initRuntime } from "../runtime-adapter";
import { runBuild } from "./handlers/build";
import { runLint } from "./handlers/lint";
import { runDevGenerate, runDevPublish, runDevOnboard, runDevCheckLexicon, runDevSurfaceDiff, runDevPinnedUpgrade, runDevUnknown } from "./handlers/dev";
import { runDevGenerate, runDevPublish, runDevOnboard, runDevCheckLexicon, runDevSurfaceDiff, runDevPinnedUpgrade, runDevRollingUpgrade, runDevUnknown } from "./handlers/dev";
import { runServeLsp, runServeMcp, runServeUnknown } from "./handlers/serve";
import { runInit, runInitLexicon } from "./handlers/init";
import { runList, runDescribe, runImport, runAudit, runUpdate, runDoctor } from "./handlers/misc";
Expand Down Expand Up @@ -240,6 +240,9 @@ Lexicon development:
dev pinned-upgrade <dir> Report if a pinned lexicon (k8s|gcp|docker|gitlab) has a newer
upstream release; dry-run bump + regen + surface-diff, then revert
(reports only; --force bypasses the spec cache, -f json for JSON)
dev rolling-upgrade <dir> Report rolling-spec drift (aws, azure, github): regen from
latest, diff surface vs committed baseline, print delta + PR
label (dry run; --force bypasses the spec cache, --format json)

Servers:
serve lsp Start the LSP server (stdio)
Expand Down Expand Up @@ -347,6 +350,7 @@ const registry: CommandDef[] = [
{ name: "dev check-lexicon", handler: runDevCheckLexicon },
{ name: "dev surface-diff", handler: runDevSurfaceDiff },
{ name: "dev pinned-upgrade", handler: runDevPinnedUpgrade },
{ name: "dev rolling-upgrade", handler: runDevRollingUpgrade },

// Op / run subcommands
{ name: "run list", handler: runOpList },
Expand Down
Loading
Loading