Skip to content

feat: add repeatable --env flag to push (#734) - #1352

Open
MatousMarik wants to merge 2 commits into
feat/actor-json-apply-env-vars-to-build-734from
feat/push-env-flag-734
Open

feat: add repeatable --env flag to push (#734)#1352
MatousMarik wants to merge 2 commits into
feat/actor-json-apply-env-vars-to-build-734from
feat/push-env-flag-734

Conversation

@MatousMarik

@MatousMarik MatousMarik commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Completes #734, stacked on #1346 (retarget to master as the stack merges — only the last two commits are new here).

What

  • Repeatable --env KEY=VALUE flag on apify push, primarily for passing build args / env vars in CI without touching actor.json or the Console.
  • Values are merged with environmentVariables from .actor/actor.json; on key conflict the --env value wins. @secret references resolve the same way as in the file (via apify secrets add). Malformed values (no KEY=) fail fast with exit code 5 before anything is uploaded.
  • Framework (own commit): Flags.string({ multiple: true }) — multi-value string flags typed as string[]. The parser already registered every flag with multiple: true and collapsed the array in _parseFlags; flags tagged multi-value now keep it. Includes the 'strings' flag tag in type inference and both help renderers. choices and default are type-forbidden together with multiple: true (unimplemented in parsing); The short-form -x=value leading-= strip is applied per element and now fires only on genuine short-form usage (parseArgs reports the canonical long name in token.name for both forms, so detection uses rawName — previously --flag '=x' was also stripped); stdin (-) is disabled for multi-value flags instead of being silently broken.

Resulting env var semantics

environmentVariables in actor.json --env Env vars on the platform after push
absent none Preserved (field omitted from the API call — unchanged behavior)
absent --env A=1 Replaced with the CLI vars — Console-set vars are removed (documented with a caution in vars.md and the flag description)
{...} none Replaced by the file's vars (unchanged behavior)
{} (empty object) none Cleared (unchanged behavior — an explicit empty value)
{...} --env ... Replaced by the merge; CLI wins per key

Tests

  • Unit tests for the KEY=VALUE parser (merge order, = in values, empty value, malformed entries, and __proto__ as a key — the accumulator is null-prototype so it can't be swallowed).
  • Unit tests for multi-value flag parsing (repeated values collect, scalars wrap, absent stays undefined, single-value flags still reject repeats).
  • New [api] tests: file + CLI vars merge with CLI winning; @secret refs from both actor.json and --env land as isSecret: true and never come back in plain text; platform vars preserved when the field is absent and cleared by an explicit {} (pins the table above). Full push API suite passes (17/17), plus test:local, lint, format, build.
  • Manually verified the real argv path: repeated --env parses, malformed value exits 5.

No new dependencies; no install-size impact.

@MatousMarik
MatousMarik force-pushed the feat/push-env-flag-734 branch 4 times, most recently from 348713b to 414f9dc Compare August 25, 2026 18:31
Flags.string({ multiple: true }) collects repeated flag values into a
string[] instead of rejecting the second occurrence. The parser already
registered every flag with multiple: true; the value was collapsed and
guarded in _parseFlags, which now keeps the array for flags tagged as
multi-value.
Passes environment variables in KEY=VALUE format directly to the
Actor version, primarily for CI. The values are merged with
environmentVariables from actor.json, with the CLI value winning on
key conflicts. @secret references resolve the same way as in the
file.
@MatousMarik
MatousMarik force-pushed the feat/push-env-flag-734 branch from 414f9dc to 60c5b8d Compare August 25, 2026 19:33
@MatousMarik
MatousMarik marked this pull request as ready for review August 26, 2026 08:21
@l2ysho
l2ysho requested a review from apify-factory August 26, 2026 08:40

@apify-factory apify-factory left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nothing blocking.

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.

3 participants