Add --secret flag to functions:deploy and functions:redeploy#73
Conversation
Repeatable flag that fans out into create + set-secret per pair + redeploy (deploy) or set-secret per pair + update (redeploy), so an agent can land first-deploy secrets in one command instead of the deploy, set, set, redeploy dance.
Greptile SummaryThis PR adds a repeatable
Confidence Score: 4/5Safe to merge after fixing the misleading stderr message in the no-secrets redeploy failure path. In functions-redeploy.ts, runRedeployWithSecrets always calls updateFunction even when no --secret flags are passed. If that call fails, run() unconditionally emits a message stating secrets were written and bindings are not yet live -- which is false when zero secrets were in play. The analogous path in functions-deploy.ts is not affected because it returns early when the secrets list is empty. cli-node/src/oclif/commands/functions-redeploy.ts -- the redeploy stage error hint at line 325 fires unconditionally and needs to be guarded on parsedSecrets.secrets.length > 0. Important Files Changed
Reviews (3): Last reviewed commit: "Merge branch 'main' into functions-deplo..." | Re-trigger Greptile |
| } else if (outcome.stage === "redeploy") { | ||
| const succeeded = | ||
| outcome.succeededKeys.length > 0 | ||
| ? outcome.succeededKeys.join(", ") | ||
| : "(none)"; | ||
| process.stderr.write( | ||
| `Secrets [${succeeded}] were written, but the redeploy step failed; the new bindings are NOT yet live. Re-run \`primitive functions:redeploy --id ${flags.id} --file <bundle>\` once the cause is fixed.\n`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
Misleading stderr hint fires even when no
--secret flags were passed
runRedeployWithSecrets always calls updateFunction, even when the secrets list is empty (there is no fast-path return like the one in runDeployWithSecrets). If that call fails, the outcome stage is "redeploy" with succeededKeys: [], and run() unconditionally emits "Secrets [(none)] were written, but the redeploy step failed; the new bindings are NOT yet live." A user who simply ran functions:redeploy --id foo --file bundle.js with no --secret flags would see this message, implying secrets were involved and are now in a broken intermediate state — neither of which is true.
| } else if (outcome.stage === "redeploy") { | |
| const succeeded = | |
| outcome.succeededKeys.length > 0 | |
| ? outcome.succeededKeys.join(", ") | |
| : "(none)"; | |
| process.stderr.write( | |
| `Secrets [${succeeded}] were written, but the redeploy step failed; the new bindings are NOT yet live. Re-run \`primitive functions:redeploy --id ${flags.id} --file <bundle>\` once the cause is fixed.\n`, | |
| ); | |
| } | |
| } else if (outcome.stage === "redeploy" && parsedSecrets.secrets.length > 0) { | |
| const succeeded = | |
| outcome.succeededKeys.length > 0 | |
| ? outcome.succeededKeys.join(", ") | |
| : "(none)"; | |
| process.stderr.write( | |
| `Secrets [${succeeded}] were written, but the redeploy step failed; the new bindings are NOT yet live. Re-run \`primitive functions:redeploy --id ${flags.id} --file <bundle>\` once the cause is fixed.\n`, | |
| ); | |
| } |
Summary
--secret KEY=VALUEflag tofunctions:deployandfunctions:redeployso an agent can seed (or refresh) function secrets in the same command as the deploy. Keys are validated client-side against the server constraint^[A-Z_][A-Z0-9_]*$before any API call fires; values may contain=since only the first one is treated as a delimiter.deploythe flow is create-function, set-secret per pair, then a final update-function with the same bundle so the running handler picks up the bindings. Onredeploysecrets are written first, then a single update-function call refreshes every new binding. Stage-specific stderr hints tell the caller exactly which keys landed if a downstream step fails.runDeployWithSecrets/runRedeployWithSecretsfunctions withDeployApiSurface/RedeployApiSurfacetypes, mirroring the existingfunctions:set-secretshape. New unit tests cover flag parsing, call ordering, the fast path (zero--secretflags = byte-identical pre-flag behavior), and each failure stage.Test plan
pnpm --dir cli-node lintpnpm --dir cli-node typecheckpnpm --dir cli-node test(195 passed)