@yolo-labs/yolo-cli 1.2.0 → 1.4.0
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/cli.js +2 -1
- package/dist/deploy-ship.js +113 -0
- package/dist/tileapp-personal.js +45 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -92,7 +92,8 @@ function printHelp() {
|
|
|
92
92
|
' bundle. Runtime (manifest has `runtime`): builds the image in-pod',
|
|
93
93
|
' + mediated-push to your registry namespace. Worker (`runtime.kind:',
|
|
94
94
|
" 'worker'`): uploads the bundle incl. its _worker/ backend, no build.",
|
|
95
|
-
' [--live]
|
|
95
|
+
' [--live] An in-progress edit, owner only: a worker app\'s backend runs on Dynamic Workers;',
|
|
96
|
+
' an interface-only app is shown only on your own tile (customers keep the published version).',
|
|
96
97
|
' [--bundle-dir <dir>] Pure-UI: override the static-bundle directory to upload.',
|
|
97
98
|
' [--include <path>] Upload a README*/*.md file that is skipped by default (repeatable).',
|
|
98
99
|
' [--context <dir>] [--dockerfile <f>] Runtime: build context + Dockerfile (default: the manifest dir).',
|
package/dist/deploy-ship.js
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
import * as path from 'node:path';
|
|
22
22
|
import * as fs from 'node:fs';
|
|
23
|
+
import * as os from 'node:os';
|
|
23
24
|
import { spawn, execFileSync } from 'node:child_process';
|
|
24
25
|
import { readDeployConfig } from './deploy-config.js';
|
|
25
26
|
import { detectProjectShape, readWranglerCrons } from './deploy-detect.js';
|
|
@@ -44,6 +45,8 @@ export async function runDeployShip(options) {
|
|
|
44
45
|
const runBuild = deps.runBuildImpl ?? defaultRunBuild;
|
|
45
46
|
const readAssetFile = deps.readAssetFileImpl ?? defaultReadAssetFile;
|
|
46
47
|
const resolveGitSha = deps.resolveGitShaImpl ?? defaultResolveGitSha;
|
|
48
|
+
const resolveGitTreeState = deps.resolveGitTreeStateImpl ?? defaultResolveGitTreeState;
|
|
49
|
+
const warn = options.warn ?? ((line) => process.stderr.write(`${line}\n`));
|
|
47
50
|
const resolveRepoOrigin = deps.resolveRepoOriginImpl ?? defaultResolveRepoOrigin;
|
|
48
51
|
// 1. Link — .yolo/deploy.json with a projectId is the durable bond.
|
|
49
52
|
const readResult = readConfig(cwd);
|
|
@@ -238,6 +241,21 @@ export async function runDeployShip(options) {
|
|
|
238
241
|
const gitSha = resolveGitSha(cwd);
|
|
239
242
|
if (gitSha)
|
|
240
243
|
request.gitSha = gitSha;
|
|
244
|
+
// gitSha names HEAD, which is NOT what was built when the tree is dirty. Say
|
|
245
|
+
// so on the release (gitDirty) and record the hash of the tree actually on
|
|
246
|
+
// disk (gitTreeHash), so a dirty release is never mistaken for HEAD. Both are
|
|
247
|
+
// sent whenever git could answer (gitDirty:false included, so "clean" is a
|
|
248
|
+
// recorded fact rather than an absence); a non-git dir omits both.
|
|
249
|
+
const treeState = resolveGitTreeState(cwd);
|
|
250
|
+
if (treeState) {
|
|
251
|
+
request.gitDirty = treeState.dirty;
|
|
252
|
+
request.gitTreeHash = treeState.treeHash;
|
|
253
|
+
if (treeState.dirty) {
|
|
254
|
+
warn(`Warning: deploying from a dirty working tree (${treeState.changedFiles} changed file${treeState.changedFiles === 1 ? '' : 's'}). ` +
|
|
255
|
+
`The release records gitSha ${gitSha ?? '(none)'} with dirty: true and treeHash ${treeState.treeHash}; ` +
|
|
256
|
+
'commit first for a reproducible release.');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
241
259
|
// The source repo these exact bytes were built from. This is the only place
|
|
242
260
|
// in the system that can know it — the server sees a bundle, and the owning
|
|
243
261
|
// workspace may be gone by the time anyone asks. Best-effort in the same
|
|
@@ -340,6 +358,9 @@ export async function runDeployShip(options) {
|
|
|
340
358
|
for (const line of pageCheckLines(pageCheck))
|
|
341
359
|
progress(line);
|
|
342
360
|
}
|
|
361
|
+
const sharedData = parseSharedData(finalized.value.sharedData);
|
|
362
|
+
if (sharedData)
|
|
363
|
+
progress(`deploy: warn — ${sharedData.notice}`);
|
|
343
364
|
return {
|
|
344
365
|
ok: true,
|
|
345
366
|
dryRun: false,
|
|
@@ -349,6 +370,7 @@ export async function runDeployShip(options) {
|
|
|
349
370
|
url: finalized.value.url,
|
|
350
371
|
...(bootCheck ? { bootCheck } : {}),
|
|
351
372
|
...(pageCheck ? { pageCheck } : {}),
|
|
373
|
+
...(sharedData ? { sharedData } : {}),
|
|
352
374
|
};
|
|
353
375
|
}
|
|
354
376
|
/**
|
|
@@ -378,6 +400,9 @@ async function resumeStagedShip(ctx, resume, io) {
|
|
|
378
400
|
for (const line of pageCheckLines(pageCheck))
|
|
379
401
|
progress(line);
|
|
380
402
|
}
|
|
403
|
+
const sharedData = parseSharedData(finalized.value.sharedData);
|
|
404
|
+
if (sharedData)
|
|
405
|
+
progress(`deploy: warn — ${sharedData.notice}`);
|
|
381
406
|
return {
|
|
382
407
|
ok: true,
|
|
383
408
|
dryRun: false,
|
|
@@ -397,6 +422,7 @@ async function resumeStagedShip(ctx, resume, io) {
|
|
|
397
422
|
// warning goes to stderr and the structured verdict + samples would
|
|
398
423
|
// otherwise be lost entirely for a resumed (approval-parked) ship.
|
|
399
424
|
...(pageCheck ? { pageCheck } : {}),
|
|
425
|
+
...(sharedData ? { sharedData } : {}),
|
|
400
426
|
};
|
|
401
427
|
}
|
|
402
428
|
// Still parked: the grant hasn't landed yet (approval-pending), or the
|
|
@@ -470,6 +496,22 @@ async function resumeStagedShip(ctx, resume, io) {
|
|
|
470
496
|
function describeErrorMessage(err) {
|
|
471
497
|
return err instanceof Error ? err.message : String(err);
|
|
472
498
|
}
|
|
499
|
+
/** Narrow the backend's optional preview `sharedData` warning; ignore anything malformed. */
|
|
500
|
+
function parseSharedData(raw) {
|
|
501
|
+
if (!raw || typeof raw !== 'object')
|
|
502
|
+
return undefined;
|
|
503
|
+
const r = raw;
|
|
504
|
+
if (typeof r.notice !== 'string' || !r.notice)
|
|
505
|
+
return undefined;
|
|
506
|
+
const names = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
|
|
507
|
+
return {
|
|
508
|
+
d1: names(r.d1),
|
|
509
|
+
kv: names(r.kv),
|
|
510
|
+
r2: names(r.r2),
|
|
511
|
+
secretCount: typeof r.secretCount === 'number' ? r.secretCount : 0,
|
|
512
|
+
notice: r.notice,
|
|
513
|
+
};
|
|
514
|
+
}
|
|
473
515
|
/** Narrow the backend's optional `bootCheck` envelope; ignore anything malformed. */
|
|
474
516
|
function parseBootCheck(raw) {
|
|
475
517
|
if (!raw || typeof raw !== 'object')
|
|
@@ -745,6 +787,77 @@ function defaultResolveGitSha(cwd) {
|
|
|
745
787
|
return undefined;
|
|
746
788
|
}
|
|
747
789
|
}
|
|
790
|
+
const TREE_HASH_RE = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
|
|
791
|
+
/**
|
|
792
|
+
* `git status --porcelain` for dirtiness, then the tree hash of what is on
|
|
793
|
+
* disk. Clean ⇒ `HEAD^{tree}`. Dirty ⇒ a SCRATCH index (GIT_INDEX_FILE in
|
|
794
|
+
* os.tmpdir) seeded from HEAD, `add -A`, `write-tree` — the user's real index
|
|
795
|
+
* is never read or written, and .gitignore is honoured exactly as `git add`
|
|
796
|
+
* would. Side effect: `add -A` writes the dirty files' blobs into the object
|
|
797
|
+
* store as loose objects (unreferenced; a normal `git gc` reaps them).
|
|
798
|
+
*
|
|
799
|
+
* Best-effort: any failure (not a repo, no commits yet, git missing, timeout)
|
|
800
|
+
* ⇒ undefined, and the ship proceeds without the fields.
|
|
801
|
+
*/
|
|
802
|
+
export function defaultResolveGitTreeState(cwd) {
|
|
803
|
+
const git = (args, env) => execFileSync('git', args, {
|
|
804
|
+
cwd,
|
|
805
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
806
|
+
timeout: 30000,
|
|
807
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
808
|
+
...(env ? { env } : {}),
|
|
809
|
+
}).toString();
|
|
810
|
+
let scratchDir;
|
|
811
|
+
try {
|
|
812
|
+
// -z: one NUL-terminated record per entry (renames carry a 2nd path field).
|
|
813
|
+
const status = git(['status', '--porcelain', '-z', '--untracked-files=all']);
|
|
814
|
+
const changedFiles = countPorcelainZEntries(status);
|
|
815
|
+
let treeHash;
|
|
816
|
+
if (changedFiles === 0) {
|
|
817
|
+
treeHash = git(['rev-parse', 'HEAD^{tree}']).trim();
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
scratchDir = fs.mkdtempSync(path.join(os.tmpdir(), 'yolo-deploy-index-'));
|
|
821
|
+
const env = { ...process.env, GIT_INDEX_FILE: path.join(scratchDir, 'index') };
|
|
822
|
+
git(['read-tree', 'HEAD'], env);
|
|
823
|
+
// `:/` — the whole worktree even when cwd is a subdirectory, matching
|
|
824
|
+
// what status reported and what HEAD^{tree} describes when clean.
|
|
825
|
+
git(['add', '-A', '--', ':/'], env);
|
|
826
|
+
treeHash = git(['write-tree'], env).trim();
|
|
827
|
+
}
|
|
828
|
+
if (!TREE_HASH_RE.test(treeHash))
|
|
829
|
+
return undefined;
|
|
830
|
+
return { dirty: changedFiles > 0, changedFiles, treeHash };
|
|
831
|
+
}
|
|
832
|
+
catch {
|
|
833
|
+
return undefined;
|
|
834
|
+
}
|
|
835
|
+
finally {
|
|
836
|
+
if (scratchDir) {
|
|
837
|
+
try {
|
|
838
|
+
fs.rmSync(scratchDir, { recursive: true, force: true });
|
|
839
|
+
}
|
|
840
|
+
catch {
|
|
841
|
+
// best-effort cleanup of a tmp dir
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
/** Count entries in `git status --porcelain -z` output (renames/copies carry two fields). */
|
|
847
|
+
function countPorcelainZEntries(out) {
|
|
848
|
+
const fields = out.split('\0');
|
|
849
|
+
let count = 0;
|
|
850
|
+
for (let i = 0; i < fields.length; i++) {
|
|
851
|
+
const field = fields[i];
|
|
852
|
+
if (field.length < 4)
|
|
853
|
+
continue;
|
|
854
|
+
count++;
|
|
855
|
+
const x = field[0];
|
|
856
|
+
if (x === 'R' || x === 'C')
|
|
857
|
+
i++; // skip the original-path field
|
|
858
|
+
}
|
|
859
|
+
return count;
|
|
860
|
+
}
|
|
748
861
|
const CONTENT_TYPES = {
|
|
749
862
|
'.html': 'text/html',
|
|
750
863
|
'.htm': 'text/html',
|
package/dist/tileapp-personal.js
CHANGED
|
@@ -532,8 +532,10 @@ export async function runTileAppPublishPersonal(opts) {
|
|
|
532
532
|
return { ok: false, kind: 'validation', message: `manifest "id" must be a lowercase kebab-case slug, 2-32 chars (got '${localId}')` };
|
|
533
533
|
}
|
|
534
534
|
const isWorker = isWorkerRuntimeManifest(read.manifest);
|
|
535
|
-
|
|
536
|
-
|
|
535
|
+
// --live on an image/container runtime app has nothing to run live; on a pure-UI app it is a
|
|
536
|
+
// static live edit (an owner-only preview), on a worker app its backend runs on Dynamic Workers.
|
|
537
|
+
if (opts.live && isRuntimeManifest(read.manifest)) {
|
|
538
|
+
return { ok: false, kind: 'usage', message: "--live applies to an interface-only or runtime.kind 'worker' app; publish without --live" };
|
|
537
539
|
}
|
|
538
540
|
// Runtime app (has `runtime`/`image`): build the image in-pod + mediated push.
|
|
539
541
|
// A worker app is NOT one (isRuntimeManifest excludes it): it falls through to
|
|
@@ -623,6 +625,9 @@ export async function runTileAppPublishPersonal(opts) {
|
|
|
623
625
|
const missingRoute = res.status === 404 && json.code !== 'feature-disabled';
|
|
624
626
|
if (!missingRoute) {
|
|
625
627
|
if (!res.ok) {
|
|
628
|
+
if (res.status === 409 && text.includes(STATIC_LIVE_DISABLED)) {
|
|
629
|
+
return { ok: false, kind: 'http', message: STATIC_LIVE_DISABLED_MESSAGE };
|
|
630
|
+
}
|
|
626
631
|
if (res.status === 409 && text.includes(DYNAMIC_WORKERS_DISABLED)) {
|
|
627
632
|
return { ok: false, kind: 'http', message: DYNAMIC_WORKERS_DISABLED_MESSAGE };
|
|
628
633
|
}
|
|
@@ -674,6 +679,9 @@ export async function runTileAppPublishPersonal(opts) {
|
|
|
674
679
|
return staged;
|
|
675
680
|
if (!res.ok) {
|
|
676
681
|
const body = await safeText(res);
|
|
682
|
+
if (res.status === 409 && body.includes(STATIC_LIVE_DISABLED)) {
|
|
683
|
+
return { ok: false, kind: 'http', message: STATIC_LIVE_DISABLED_MESSAGE };
|
|
684
|
+
}
|
|
677
685
|
if (res.status === 409 && body.includes(DYNAMIC_WORKERS_DISABLED)) {
|
|
678
686
|
return { ok: false, kind: 'http', message: DYNAMIC_WORKERS_DISABLED_MESSAGE };
|
|
679
687
|
}
|
|
@@ -691,8 +699,25 @@ export async function runTileAppPublishPersonal(opts) {
|
|
|
691
699
|
const summary = `Published ${appId} (${collected.files.length} file${collected.files.length === 1 ? '' : 's'}, ${collected.totalBytes} bytes)`
|
|
692
700
|
+ (collected.skipped.length > 0 ? `\n skipped (docs are not uploaded; --include <path> to upload one): ${collected.skipped.join(', ')}` : '');
|
|
693
701
|
const next = installNextLines(appId, workspaceId, installReport);
|
|
702
|
+
if (!isWorker && opts.live) {
|
|
703
|
+
// A static live edit: stored beside the published bundle, shown only on the owner's tile.
|
|
704
|
+
if (uploadJson.live !== true) {
|
|
705
|
+
return { ok: false, kind: 'http', message: `${appId}: the server did not store a live version; publish without --live, or check the deployment has live edits on` };
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
ok: true,
|
|
709
|
+
output: [
|
|
710
|
+
summary,
|
|
711
|
+
' live: true (owner-only preview)',
|
|
712
|
+
" Only your own tile shows this version (relaunch or reload the tile). Customers' portals and the published",
|
|
713
|
+
' version are unchanged; publish without --live to ship it.',
|
|
714
|
+
...next,
|
|
715
|
+
].join('\n'),
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
const pinLines = portalPinLines(uploadJson.portalPins);
|
|
694
719
|
if (!isWorker)
|
|
695
|
-
return { ok: true, output: [summary, ...next].join('\n') };
|
|
720
|
+
return { ok: true, output: [summary, ...pinLines, ...next].join('\n') };
|
|
696
721
|
// A worker app's bundle is stored either way; `publish` says whether its
|
|
697
722
|
// backend made it, and `live` whether that backend runs on Dynamic Workers.
|
|
698
723
|
// A version with no backend serves a UI whose /api/* is dead, so it is a failure.
|
|
@@ -714,12 +739,15 @@ export async function runTileAppPublishPersonal(opts) {
|
|
|
714
739
|
else {
|
|
715
740
|
lines.push(' backend: no worker placement report — the worker placement may be off on this deployment, so the backend was not published.');
|
|
716
741
|
}
|
|
717
|
-
lines.push(...next);
|
|
742
|
+
lines.push(...pinLines, ...next);
|
|
718
743
|
return { ok: true, output: lines.join('\n') };
|
|
719
744
|
}
|
|
720
745
|
/** The refusal code (HTTP 409) for a live worker tile when Dynamic Workers is off on the deployment. */
|
|
721
746
|
const DYNAMIC_WORKERS_DISABLED = 'dynamic-workers-disabled';
|
|
722
747
|
export const DYNAMIC_WORKERS_DISABLED_MESSAGE = 'live worker tiles are not enabled on this deployment; publish without --live';
|
|
748
|
+
/** The refusal code (HTTP 409) for a live edit of an interface-only app where it is off. */
|
|
749
|
+
const STATIC_LIVE_DISABLED = 'static-live-disabled';
|
|
750
|
+
export const STATIC_LIVE_DISABLED_MESSAGE = 'live edits of interface-only apps are not enabled on this deployment; publish without --live';
|
|
723
751
|
/**
|
|
724
752
|
* This pod's workspace id (`WORKSPACE_ID`, set in every session pod), or
|
|
725
753
|
* undefined. Only when the API is the one the pod belongs to (production, or the
|
|
@@ -763,6 +791,19 @@ export function installNextLines(appId, workspaceId, report) {
|
|
|
763
791
|
return [` next: if it's already installed, ${install} moves the install to this version; if not, also run ${addTile}`];
|
|
764
792
|
}
|
|
765
793
|
}
|
|
794
|
+
/** The publish report's lines for portal pins: a pin that stopped serving says so, with the fix. */
|
|
795
|
+
export function portalPinLines(pins) {
|
|
796
|
+
if (!Array.isArray(pins) || pins.length === 0)
|
|
797
|
+
return [];
|
|
798
|
+
return pins.slice(0, 20).map((p) => {
|
|
799
|
+
const where = p.scope === 'project' ? `pinned as project default on ${p.projectId}` : `pinned for customer ${p.relationshipId} (project ${p.projectId})`;
|
|
800
|
+
if (p.follow === 'latest-published')
|
|
801
|
+
return ` portal: ${where}, follows latest published — customers now get ${p.servingVersion ?? 'this version'}`;
|
|
802
|
+
if (p.serving)
|
|
803
|
+
return ` portal: ${where} — serving ${p.servingVersion ?? 'the pinned version'}`;
|
|
804
|
+
return ` portal: ${where} — not serving until re-pinned (mogul.portal_app_set; add follow: "latest-published" to skip this next time)`;
|
|
805
|
+
});
|
|
806
|
+
}
|
|
766
807
|
/**
|
|
767
808
|
* Build the app image in-pod with podman, `save` it to an OCI archive in the
|
|
768
809
|
* workspace, and hand it to common-api's MEDIATED push endpoint — common-api
|