Skip to content

fix(generate): thread operator inputs, env_inputs, and image refs through hotfix deploys - #708

Open
reka18 wants to merge 9 commits into
mainfrom
fix/hotfix-deploy-inputs-697
Open

reka18 wants to merge 9 commits into
mainfrom
fix/hotfix-deploy-inputs-697

Conversation

@reka18

@reka18 reka18 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

What was wrong

Since #696, the hotfix deploy and rollback lanes call the configured deploy workflow, but they passed only environment, sha and dry_run. A deploy callback that requires any of these couldn't be driven by a hotfix run:

  • Operator inputs:. No hotfix lane had a source for them.
  • env_inputs. These are keyed on the target environment, which a hotfix resolves only at run time from the pull request's base ref.
  • image_tag / image_digest. Neither lane passed them.

What changed

  • The context job is now the hotfix's preflight. It resolves the run-time target environment and builds a one-entry matrix from the same generation-time DEFAULT_INPUTS / ENV_INPUTS JSON promote uses, passed through step env: and selected with jq on TARGET_ENV. ${{ state.* }} refs resolve exactly as they do in promote. deploy-<name> and rollback-<name> fan out on that matrix and pass each input as matrix.<key>.
  • Image refs. The deploy lane passes image_tag / image_digest from the depends_on builds' declared outputs (image_tag, artifact_id). The rollback lane reads the N-1 refs from manifest state in the context job, next to the rollback SHA it already resolves: the target environment's recorded version, and the first non-empty build artifact_id in sorted build order, which is promote's rule.
  • Passthroughs and standard names. Passthrough expressions (${{ vars.x }}) stay verbatim. An operator-wired standard name replaces the standard line instead of duplicating it, as in promote.
  • Every line is gated on the callee's declared inputs. A deploy that declares none of the new surface generates byte-identical output.
  • Generate refuses what no lane can supply. A deploy callback with a required input that no hotfix lane can supply fails generation, naming the deploy and the input. The check is per lane: operator inputs count only on the lanes that pass them. Cross-repo callbacks are skipped.
  • Promote's required-input check now counts operator inputs only on the lanes that pass them. fix(generate): gate promote rollback inputs and dry_run on the callee's declared inputs #705's dry_run rule and its rollback image_tag / image_digest refusal still hold, unchanged.
  • Shared helpers. Promote's matrix input helpers are now package-level, so both generators use them. Promote's output doesn't change. passthroughInputValue now picks env overrides in sorted env order, so generation is deterministic.
  • Docs: guides/hotfix.md and reference/generated-workflows.md describe the input passing and the required-input check.

Rebased onto #705

#705 stopped promote's rollback from passing a SHA as image_tag, and made generation refuse a rollback whose callee requires image_tag or image_digest (#664). One promote subtest on this branch was written before that change and expected the old behavior. It now expects #705's refusal. Nothing else in #705 changed.

How it's tested

  • go build, go vet, gofmt and go test ./... pass. The new tests pin:
    • the matrix, env_inputs and image-ref passing on both lanes;
    • the per-lane required-input check;
    • the byte-identical output for a deploy with none of the new inputs.
  • An actionlint feature-matrix case lints a hotfix deploy with a required image_tag, operator inputs and env_inputs end to end.
  • New e2e scenario: hotfix/hotfix-deploy-callback-inputs.yaml. It needs Docker, so CI runs it; it hasn't run locally yet.

Closes #697
Relates to #664

… threading

Extend the hotfix deploy-input tests around
TestHotfixGenerator_DeployInputGating with the #697 acceptance surface,
written red against the current generator:

- operator inputs: a manifest-declared input the callee declares must
  ride a one-entry matrix the context job resolves for the run-time
  target environment (deploy and rollback lanes both fan out on it); an
  undeclared input keeps today's output shape (no matrix machinery); a
  passthrough expression stays verbatim with no matrix; an
  operator-wired standard name (sha) threads from the matrix without
  duplicating the standard line.
- env_inputs: the context job routes promote-style DEFAULT_INPUTS /
  ENV_INPUTS JSON through step env: and selects the resolved target
  environment with jq on TARGET_ENV; state.* refs resolve at generation
  time into the per-env payload exactly as promote resolves them (an
  unresolved ref keeps the raw expression, promote's semantics); an
  env-inputs-only key threads without a default; a matrix.*-referencing
  value is left out (the hotfix matrix is synthetic, so no leg resolves
  it).
- image refs: the deploy lane threads image_tag / image_digest from the
  depends_on build's declared workflow_call outputs (image_tag and
  artifact_id), gated on declaration and on the build actually declaring
  the output; the rollback lane threads rollback_image_tag
  (state.<env>.version) and rollback_image_digest (first non-empty
  builds artifact_id, sorted like promote's first-non-empty rule) from
  the context job, component-scoped under state.components.<name>.
- generate check: a required input no hotfix lane can supply (contract
  inputs, image refs via the rollback lane's state source, manifest
  inputs/env_inputs, passthroughs) fails generation with a message
  naming the deploy and the input; cross-repo callbacks are skipped.
- actionlint feature matrix: a hotfix deploy declaring image_tag
  required plus operator inputs and env_inputs against a build callback
  with image_tag/artifact_id outputs must lint clean end to end.

Closes #697
Relates to #664

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…rough hotfix deploys

Close the #697 gap: since #696 the hotfix deploy and rollback lanes call
the configured deploy workflow but passed only environment, sha, and
dry_run, so a deploy whose callback requires operator inputs, env_inputs,
image_tag, or image_digest could not be driven by a hotfix run.

The context job becomes the deploy lane's preflight, resolving like
promote does:

- Per deploy whose operator inputs ride the matrix, it builds a one-entry
  matrix for the run-time-resolved target environment from promote's
  generation-time DEFAULT_INPUTS/ENV_INPUTS JSON, routed through step
  env: indirection (the injection-hardened pattern), with ${{ state.* }}
  refs resolved through SetState exactly as promote resolves them and the
  target env selected with jq on TARGET_ENV. deploy-<name> and
  rollback-<name> fan out on that matrix (strategy: fail-fast: false,
  matrix.include: fromJSON(...)) and thread each input as matrix.<key>;
  the contract environment comes from matrix.environment there.
- The deploy lane threads image_tag / image_digest from the depends_on
  builds' declared workflow_call outputs (needs.build-<dep>.outputs
  .image_tag / .artifact_id, orchestrate's direct-dependency rule; a
  cross-repo build assumes the contract's artifact_id output).
- The rollback lane reads the N-1 image refs from live manifest state in
  the context job, alongside the rollback SHA it already resolves:
  rollback_image_tag is the target env's recorded version,
  rollback_image_digest the first non-empty builds artifact_id in sorted
  build-name order (promote's first-non-empty rule). The output names
  pair with a future target_image_tag preflight output (#664).
- Passthrough expressions (${{ vars.x }}) stay verbatim in with:, and an
  operator-wired standard name suppresses the standard line instead of
  duplicating it (promote's manifest-wiring-wins rule). Every line stays
  gated on the callee's declared inputs, so a deploy declaring none of
  the new surface generates byte-identical output to before.
- Port promote's validateRequiredInputs: a deploy callback that declares
  a required input no hotfix lane can supply fails generation naming the
  deploy and the input. image_tag/image_digest count as supplied because
  the rollback lane reads them from manifest state; matrix.*-referencing
  values do not (the synthetic matrix resolves no placeholder); cross-repo
  callbacks are skipped.

Supporting changes: promote's matrixDefaultInputs / matrixEnvInputs /
matrixInputsJSON become package-level functions shared with the hotfix
lane (promote output unchanged), and passthroughInputValue picks the env
override in sorted env order so generation is deterministic when a
passthrough key has overrides in several envs and no default.

The two test edits correct ENV_INPUTS JSON key-order expectations to
json.Marshal's sorted order.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Model on hotfix-build-callback-inputs.yaml, driving the deploy half of
#697 as a runtime outcome: the hotfix_merged step's expect_log asserts
the deploy callback's dedicated log line carrying the run-time-resolved
target environment (test), the build callback's image_tag output threaded
from the depends_on build job, and the env_inputs[test] operator input
selected at run time by the context job's jq merge. The callback declares
release_channel as required, so a caller that drops it fails the
reusable-workflow dispatch instead of silently logging an empty value.

The rollback lane cannot run under act: driving it requires the deploy to
fail, and act v0.2.99 skips every later stage of a plan whose reusable
callee failed. Its proof here is the first step's wiring assertion (the
rollback job threads rollback_image_tag / rollback_image_digest from the
context job's manifest-state reads and re-invokes the same callback keyed
on the pre-hotfix SHA), alongside the internal/generate tests and the
live fleet; the scenario description records the ceiling.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…heck

Update reference/generated-workflows.md, guides/hotfix.md, and the
CHANGELOG for #697: the hotfix deploy and rollback lanes now thread the
deploy's operator inputs (through the one-entry matrix the context job
resolves for the run-time target environment, using promote's serialized
payload), image_tag/image_digest (from the depends_on builds' outputs on
the deploy lane, from manifest state on the rollback lane), and
passthrough expressions verbatim. Document that env_inputs' ${{ state.* }}
references resolve at generation time as promote's do, and that
cascade generate-workflow refuses a deploy callback declaring a required
input no hotfix lane can supply, naming the deploy and the input.

The reference previously called the omission deliberate; that statement
is replaced by the threading model and the check.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
One round of review on the branch diff; the real findings and their fixes:

- Duplicate mapping keys: an operator-wired image_tag/image_digest (or
  environment/sha/dry_run) emitted both the lane's line and the
  matrix/passthrough line, producing a with: block GitHub rejects. The
  cascade-owned names now always win - the plan drops operator inputs
  carrying environment, sha, dry_run, image_tag, or image_digest - which
  also keeps each lane's own sha load-bearing (an operator-wired sha on
  the rollback lane would have deployed a fixed SHA instead of the
  pre-hotfix N-1 SHA the lane is gated on). This matches the hotfix build
  lane's seen() skip and promote's standard-value-wins jq merge.
- Unresolvable operator values threaded verbatim: a passthrough
  referencing matrix.* (for example ${{ format('{0}', matrix.os) }}) or
  needs.<job> other than context passed through the passthrough
  classification; the rollback lane cannot resolve a needs.build-*
  reference, so actionlint rejects the file. Both filters now run on every
  declared value of a key, the same predicates the hotfix build lane
  uses.
- Wrong-environment passthroughs: promote's passthroughInputValue picks
  the alphabetically-first env override when no default exists, which on
  the hotfix lane would pass another environment's expression to the
  resolved target. Only a passthrough whose inputs: default is itself a
  passthrough threads now; env-only passthroughs (and passthrough
  overrides of a non-passthrough default) drop.
- Promote's required-input validation rejected manifests it actually
  generates correctly: the matrix deploy job threads every inputs: key,
  but the check counted only the contract names, so a callback declaring
  a manifest-passed input required: true failed generation - and blocked
  the new e2e scenario, whose repo the harness generates as a set. The
  check now counts the deploy's manifest-declared inputs and names them
  in the available list.
- The context job's digest read tolerates an env with no builds map
  (builds // {} before to_entries) instead of depending on the runner's
  yq treating null input the same way; the tag read composes the same
  stateScopePrefix as the digest read.
- Plans are computed once in Generate and threaded through validation and
  emission (the callee file was being read three times per deploy), and
  the plan builder is renamed newHotfixDeployPlan so the method stops
  sharing its name with the type.

Tests: reserved-name collisions pin exactly-once lines on both lanes, a
byte-equality oracle pins the undeclared-operator-input shape against a
no-inputs manifest, the matrix-referencing case gains a threadable
neighbor so the payload assertions are non-vacuous, needs-referencing
and env-only passthrough cases are pinned, and the component-scoped
digest read is asserted. Promote gets the validation/emission agreement
test for the manifest-input counting.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…d them

PromoteGenerator.validateRequiredInputs counted every key under a
deploy's inputs: as available, but only the matrix deploy job threads
operator inputs. The prod deploy job, the rollback job, and the
single-environment deploy path call the same callback without them, so a
callee requiring an operator input generated calls GitHub rejects at
dispatch - the exact shape actionlint's [workflow-call] check refuses
(the scenario's own manifest produced two such promote errors and one on
the rollback workflow before this change).

The check now models the lanes writeJobs emits (matrix deploy job,
single-environment deploy job, prod deploy job, rollback job) with their
emission conditions, and an operator input counts as available only on a
lane that threads it: with one or more environments the prod and
rollback jobs are always emitted alongside the matrix job, so a required
operator input fails generate with a message naming the deploy, the
input, and the starving lane(s). The contract inputs
(environment/sha/image_tag/image_digest) stay blanket-available; their
remaining per-lane gaps are tracked separately (#664, #698). A required
input no lane threads keeps the unchanged refusal.

The hotfix deploy callback inputs scenario's callee now declares
release_channel optional: promote's prod and rollback lanes (and the
rollback workflow's deploy job) call it without operator inputs, so a
required operator input cannot generate; the runtime expect_log
assertion still proves the hotfix lane threads the env_inputs override.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
The hotfix required-input check treated image_tag and image_digest as
supplied whenever any lane supplied them, and the rollback lane always
reads both refs from manifest state. But the deploy job calls the same
callback and threads them only from a depends_on build's declared
workflow_call output, so a required image_tag with no producing build
passed generate and the deploy lane then failed the dispatch at run
time.

The check now evaluates each lane that will call the callee - the
deploy job and the rollback job are both emitted for every configured
deploy - and a required input must be suppliable on each. On the deploy
lane image_tag and image_digest count only when a depends_on build
declares the matching output (image_tag, artifact_id); when the rollback
lane supplies an input the deploy lane cannot, the error names the
deploy, the input, the deploy lane, and the output the lane would
source it from. An input no lane supplies keeps the unchanged union
message; contract inputs and threaded operator inputs are suppliable on
both lanes and still pass. The docs and changelog now describe the
per-lane rule.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
Two findings from the review round on the lane-aware checks:

- The hotfix check's threaded() helper hand-rolled two membership loops
  over the plan's matrix and passthrough keys right next to the
  slices.Contains call the same function already uses; collapse it to the
  stdlib form.

- The promote check's doc comment claimed the contract inputs are
  threaded on every lane, which is not true of the matrix deploy job: it
  auto-threads only environment and sha beyond the manifest's inputs:
  keys, so image_tag/image_digest reach it only when the manifest wires
  them under inputs:. State the real per-lane gaps - matrix job: image
  inputs only via inputs:, prod and rollback jobs: image_tag when
  declared but never image_digest - alongside the existing #664/#698
  deferral, so the carve-out the check makes is documented accurately.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>
…h path

The hotfix workflow carries two triggers in one file: workflow_dispatch
runs the plan/apply jobs, pull_request(closed) runs the
context/build/deploy/rollback/finalize chain. The deploy and rollback
jobs' matrix include was a bare fromJSON of
needs.context.outputs.deploy_<name>_matrix, and the context job runs only
on the merged path - so on the dispatch path (the hotfix plan run) that
output is unresolved.

act v0.2.99 evaluates every job's strategy while planning, before any if:
gate, and a skipped job's declared outputs are never interpolated:
needs.context.outputs.deploy_service_matrix reads as the raw
"${{ steps.ctx.outputs.deploy_service_matrix }}" text, fromJSON rejects
it ("invalid character '$'"), and the unresolved include scalar then
fails the matrix decode with a fatal - killing the whole run right after
the plan job succeeds. This is what failed e2e step 5 of the "Hotfix
Deploy Callback Inputs" scenario on every CI attempt (line 332 of the
generated workflow, the deploy-service include).

The include expression now guards on needs.context.result == 'success'
and falls back to '[]': on the dispatch path (context skipped) the matrix
evaluates to a zero-entry list and the job stays skipped exactly as its
if: gate already decided, and on the merged path the guard is a no-op -
the deploy job's needs gate and the rollback job's rollback_sha output
gate both mean the matrix is evaluated only after the context job
succeeded, so GitHub behavior is unchanged. Replaying act v0.2.99's own
plan-executor code path against the generated workflow confirms both
directions: the unguarded emission exits fatally on the dispatch path,
while the guarded emission survives it and resolves the identical
merged-path entry (matrix.environment=test,
matrix.release_channel=hotfix-stable).

The scenario's include assertion tracks the corrected line with the same
exact-line strength, the unit tests pin the guard next to the existing
matrix pins, and the docs and changelog describe it. A deploy declaring
none of the new inputs still generates byte-identical output.

Signed-off-by: Ray Karnes <ray.karnes@stablekernel.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hotfix deploys drop operator inputs, env_inputs and image_tag

1 participant