Skip to content

feat: read applyEnvVarsToBuild from actor.json in push (#734) - #1346

Open
MatousMarik wants to merge 7 commits into
masterfrom
feat/actor-json-apply-env-vars-to-build-734
Open

feat: read applyEnvVarsToBuild from actor.json in push (#734)#1346
MatousMarik wants to merge 7 commits into
masterfrom
feat/actor-json-apply-env-vars-to-build-734

Conversation

@MatousMarik

@MatousMarik MatousMarik commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Part of #734, stacked on #1345 (retarget to master once that merges — only the last commit is new here).

What

  • apify push now reads applyEnvVarsToBuild from .actor/actor.json, so the setting persists per repo and applies on every push (useful for CI and Actors needing build-time secrets).
  • Precedence: --[no-]apply-env-vars-to-build flag > applyEnvVarsToBuild in actor.json > omitted (value stored on the platform is kept). An explicit false in actor.json turns the setting off.
  • Documented in docs/vars.md; flag description updated (+ regenerated docs/reference.md).

Tests

  • New [api] test covering field true, field false, flag-over-field precedence, and the negated flag beating a true in the file (the case that pins ?? over ||). Full push API suite passes (14/14), plus test:local, lint, format, build.
  • Note for reviewers: useActorConfig caches by cwd, so the test resets the cache when rewriting actor.json mid-test.

Follow-up (separate PR)

No new dependencies; no install-size impact.

@MatousMarik
MatousMarik force-pushed the feat/push-apply-env-vars-to-build-734 branch from 9c96569 to 923d4a8 Compare August 25, 2026 07:42
@MatousMarik
MatousMarik force-pushed the feat/actor-json-apply-env-vars-to-build-734 branch from 556d4c0 to c53d79f Compare August 25, 2026 07:42
@MatousMarik
MatousMarik force-pushed the feat/actor-json-apply-env-vars-to-build-734 branch from c53d79f to 9cfb129 Compare August 25, 2026 08:08
Allows env vars from actor.json to be applied to the Actor build
process (Docker build args) without flipping the switch in Console.
--no-apply-env-vars-to-build explicitly turns the setting off. When
the flag is omitted, the value stored on the platform is kept.

The flag parser matched provided flags by truthiness, which dropped
scalar false values injected by the test harness (the real CLI path
always yields arrays via multiple: true and was unaffected); it now
checks for presence so harness-injected negated booleans behave the
same as parsed ones.
The field persists the build env vars setting per repo, so it applies
on every push without remembering the flag. The
--apply-env-vars-to-build flag takes precedence over the field, and an
explicit false in actor.json turns the setting off. When both are
omitted, the value stored on the platform is kept.
@MatousMarik
MatousMarik force-pushed the feat/push-apply-env-vars-to-build-734 branch from 923d4a8 to 420860a Compare August 25, 2026 09:16
@MatousMarik
MatousMarik force-pushed the feat/actor-json-apply-env-vars-to-build-734 branch from 9cfb129 to a8a1158 Compare August 25, 2026 09:16
@MatousMarik
MatousMarik marked this pull request as ready for review August 25, 2026 13:23
@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.

@szaganek szaganek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Three suggestions from me to improve readability.

Comment thread docs/vars.md Outdated
Comment thread docs/vars.md Outdated
Comment thread src/commands/actors/push.ts Outdated
'apply-env-vars-to-build': Flags.boolean({
description:
'Make the environment variables also available to the Actor build process. Use --no-apply-env-vars-to-build to turn the setting off. When omitted, the setting currently stored on the platform is kept.',
description: `Make the environment variables also available to the Actor build process. Use --no-apply-env-vars-to-build to turn the setting off. Overrides the 'applyEnvVarsToBuild' field in the '${LOCAL_CONFIG_PATH}' file. When both are omitted, the setting currently stored on the platform is kept.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
description: `Make the environment variables also available to the Actor build process. Use --no-apply-env-vars-to-build to turn the setting off. Overrides the 'applyEnvVarsToBuild' field in the '${LOCAL_CONFIG_PATH}' file. When both are omitted, the setting currently stored on the platform is kept.`,
description: `Make the environment variables also available to the Actor build process. To turn the setting off, use --no-apply-env-vars-to-build. Overrides the value of the 'applyEnvVarsToBuild' field in the '${LOCAL_CONFIG_PATH}' file. Without a flag, the setting currently stored on the platform is kept.`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[claude] -> original version seems to be better, platform is kept when both are omitted, not just flag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

feel free to resolve as you like cc @szaganek

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah. Let's make it explicit then:
When both the field and the flag are omitted, the setting currently stored on the platform is kept.

MatousMarik and others added 3 commits August 27, 2026 15:44
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>
Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com>

@l2ysho l2ysho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thx @MatousMarik
pre-aprooving as nothing blocking here but I think pnpm run update-docs should be made, also I left one comment in docs thread where It looks like original version was more inline with code

@patrikbraborec

Copy link
Copy Markdown
Contributor

@MatousMarik - please can you check the request changes? 🙏 Thanks!

MatousMarik and others added 2 commits September 9, 2026 15:41
The flag description and vars.md both said the platform setting is kept
"without a flag", which is wrong when applyEnvVarsToBuild is set in
actor.json — the field wins there. Say "neither the field nor a flag".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MatousMarik

Copy link
Copy Markdown
Contributor Author

@patrikbraborec
Done, you can take over

l2ysho added a commit that referenced this pull request Sep 9, 2026
Part of #734 (the `applyEnvVarsToBuild` toggle half).

## What
- New `--apply-env-vars-to-build` boolean flag on `apify push` — sets
`applyEnvVarsToBuild: true` on the Actor version, so env vars from
`actor.json` are also available during the Docker build.
`--no-apply-env-vars-to-build` explicitly turns the setting off.
- When the flag is omitted, the field is left out of the API payload
entirely, so a value previously set in Console is **preserved** (pushes
to existing Actors don't reset it).
- Flag-parser tweak: `_parseFlags` matched provided flags by truthiness.
The real CLI path is unaffected (`multiple: true` means values always
arrive as arrays, which are truthy), but
`testRunCommand`/`internalRunCommand` inject scalar values, where an
explicit `false` was silently dropped. The matcher now checks for
presence, and the required-flag check is aligned to `undefined`, so
harness-injected negated booleans behave the same as parsed ones (the
new test relies on this).
- Regenerated `docs/` via `pnpm run update-docs`.

## Why
Env vars synced by `apify push` currently apply only at runtime; making
them apply to the build requires flipping a switch in Console. That
breaks CI and fresh pushes of Actors that need build-time secrets (e.g.
a GitHub token as a Docker build arg).

## Tests
- New `[api]` test in `test/api/commands/push.test.ts` covering: flag →
`true`, omitted → preserved, negated flag → `false`. Full push API suite
passes (13/13), plus `test:local`, lint, format, build.

## Follow-ups (separate PRs)
- `applyEnvVarsToBuild` field in `.actor/actor.json` (#1346, stacked on
this).
- `--env KEY=VALUE` passing on push (the other half of #734).

No new dependencies; no install-size impact.

Co-authored-by: Richard Solar <solar.richard@gmail.com>
Base automatically changed from feat/push-apply-env-vars-to-build-734 to master September 9, 2026 18:01
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.

6 participants