flow run: a declined confirmation stops the flow; --apply --yes confirms write steps
confirm() prints 'declined: <reason>' and exits 3 whenever the answer is no or nobody can answer (not a terminal without --yes, serve without the owner's dialog), so no command reports success after declining. flow run stops at such a step with 'step N declined: <reason>' (status declined), never ok. flow run --apply --yes passes --yes to write steps only; --yes without --apply is refused. Pitfall 24.
This commit is contained in:
parent
5fbb9e63e3
commit
366362d62b
12 changed files with 116 additions and 19 deletions
26
cli/flow.ts
26
cli/flow.ts
|
|
@ -1,11 +1,14 @@
|
|||
// Repo-local workflows: named, ordered storebound steps kept in the project (definitions and rules: lib/flow.ts).
|
||||
// storebound flow list [--json] the flows of this project and their steps
|
||||
// storebound flow validate [--json] definitions, sub-flow cycles, commands, variables; exit 1 on a problem
|
||||
// storebound flow run <name> [NAME=value ...] [--dry | --apply] [--from <step> | --resume] [--json]
|
||||
// storebound flow run <name> [NAME=value ...] [--dry | --apply [--yes]] [--from <step> | --resume] [--json]
|
||||
// default: read steps run, write steps run with --dry (nothing changes), wait steps check once, shell steps are
|
||||
// skipped, owner steps (submit, release, rollout ...) are shown as "your click" and never run
|
||||
// --dry: only the plan: nothing runs at all
|
||||
// --apply: write steps and shell steps run for real; every write command still asks the owner itself
|
||||
// --apply --yes: the owner's approval for this run: write steps get --yes (owner steps still never run)
|
||||
// A step whose command declined its confirmation ("declined: ...", e.g. not a terminal without --yes) stops the flow:
|
||||
// "step N declined: <reason>", never ok.
|
||||
// --from <step>: start at that step (variables captured by the last run are reused); --resume: from the first step
|
||||
// the last run did not finish (.storebound/flows/<name>.json)
|
||||
// Progress: "[flow] 3/9 upload: storebound apple upload --no-wait --dry" before each step, the step's own output
|
||||
|
|
@ -20,6 +23,7 @@ import {
|
|||
type CondCtx, expand, type Flow, flowsOfFile, kindOf, type Mode, parseParams, planStep, type PlannedStep, resumePoint, type RunState, startIndex,
|
||||
type StepResult, validateFlows,
|
||||
} from './lib/flow';
|
||||
import { DECLINED_MARK } from './lib/ctx';
|
||||
import { done, log, printJson, step, warn } from './lib/log';
|
||||
import { childEnv, pump, selfCommand } from './lib/runner';
|
||||
import { PREBUILD_DONE_ENV, prebuildFor, prebuildsDone } from './lib/web-assets';
|
||||
|
|
@ -77,6 +81,12 @@ async function condCtx(root: string): Promise<CondCtx & { config: ShipConfig | n
|
|||
return { apple: !!config?.apple, play: !!config?.play, exists: p => existsSync(join(root, p)), config };
|
||||
}
|
||||
|
||||
/** The reason of a declined confirmation in a step's output (the "declined: ..." line of confirm()), else null. Pure. */
|
||||
export function declinedReason(out: string): string | null {
|
||||
const l = out.split('\n').reverse().find(x => x.startsWith(DECLINED_MARK));
|
||||
return l ? l.slice(DECLINED_MARK.length).trim() : null;
|
||||
}
|
||||
|
||||
/** The prebuild a finished build step ran (apple build / play build, for real, without --no-prebuild), else null:
|
||||
* later build steps of the same flow run skip that command (build.prebuild runs once per run, not per store). Pure. */
|
||||
export function prebuildRan(argv: string[], config: ShipConfig | null): string | null {
|
||||
|
|
@ -140,6 +150,7 @@ async function runFlow(args: Args, root: string): Promise<void> {
|
|||
const name = args._[1];
|
||||
if (!name) throw new Error('usage: storebound flow run <name> [NAME=value ...] [--dry | --apply] [--from <step> | --resume]');
|
||||
if (args.has('dry') && args.has('apply')) throw new Error('--dry or --apply, not both');
|
||||
if (args.has('yes') && !args.has('apply')) throw new Error('--yes only with --apply (it confirms the write steps of this run)');
|
||||
const { flows, errors } = await loadFlows(root);
|
||||
const problems = [...errors, ...validateFlows(flows)];
|
||||
if (problems.length) throw new Error(`flow definitions have problems (storebound flow validate):\n ${problems.join('\n ')}`);
|
||||
|
|
@ -174,7 +185,7 @@ async function runFlow(args: Args, root: string): Promise<void> {
|
|||
const runPart = async (part: PlannedStep['part'], steps: typeof parts.steps, offset = 0): Promise<boolean> => {
|
||||
for (let i = offset; i < steps.length; i++) {
|
||||
const s = steps[i]!;
|
||||
const p = planStep(s, part, mode, vars, c, env);
|
||||
const p = planStep(s, part, mode, vars, c, env, args.has('yes'));
|
||||
const label = `${part === 'steps' ? '' : `${part} `}${step(i + 1, steps.length, s.id)}`;
|
||||
const r: StepResult = { id: s.id, part, kind: p.kind, status: 'planned', command: describe(p) };
|
||||
if (p.skip) {
|
||||
|
|
@ -198,12 +209,13 @@ async function runFlow(args: Args, root: string): Promise<void> {
|
|||
}
|
||||
if (!json) log(TAG, `${label}: ok (${(r.ms / 1000).toFixed(1)}s)${r.detail ? ` ${r.detail}` : ''}`);
|
||||
} else {
|
||||
r.status = 'failed';
|
||||
r.detail = x.out.split('\n').filter(Boolean).slice(-1)[0]?.slice(0, 300);
|
||||
if (!json) warn(TAG, `${label}: failed (exit ${x.code})${p.continueOnError ? ', continueOnError: going on' : ''}`);
|
||||
const why = declinedReason(x.out);
|
||||
r.status = why ? 'declined' : 'failed';
|
||||
r.detail = why ?? x.out.split('\n').filter(Boolean).slice(-1)[0]?.slice(0, 300);
|
||||
if (!json) warn(TAG, why ? `step ${i + 1} declined: ${why}${s.id ? ` (${s.id})` : ''}` : `${label}: failed (exit ${x.code})${p.continueOnError ? ', continueOnError: going on' : ''}`);
|
||||
}
|
||||
state.vars = vars; state.results.push(r); save();
|
||||
if (r.status === 'failed' && !p.continueOnError) return false;
|
||||
if (r.status === 'declined' || (r.status === 'failed' && !p.continueOnError)) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
@ -217,7 +229,7 @@ async function runFlow(args: Args, root: string): Promise<void> {
|
|||
if (json) printJson({ ...state, stateFile: mode === 'plan' ? null : relative(root, statePath(root, name)) });
|
||||
else {
|
||||
if (owner.length) { console.log('\nYour clicks (storebound never does these):'); for (const r of owner) console.log(` - ${r.command}`); }
|
||||
const failed = state.results.find(r => r.status === 'failed' && r.part === 'steps');
|
||||
const failed = state.results.find(r => (r.status === 'failed' || r.status === 'declined') && r.part === 'steps');
|
||||
if (!ok && failed) log(TAG, `stopped at ${failed.id}. Fix it, then: storebound flow run ${name} --resume${mode === 'apply' ? ' --apply' : ''}`);
|
||||
done(TAG, `${name}: ${ok ? 'done' : 'failed'} (${mode === 'plan' ? 'plan only' : mode === 'dry' ? 'dry run: nothing changed' : 'applied'})`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue