From 420860a35410664e2e7b30b44a9ebf69dfffd75a Mon Sep 17 00:00:00 2001 From: Matous Marik Date: Mon, 24 Aug 2026 16:24:11 +0200 Subject: [PATCH 1/7] feat: add --apply-env-vars-to-build flag to apify push 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. --- docs/reference.md | 9 ++++- src/commands/actors/push.ts | 10 ++++- src/lib/command-framework/apify-command.ts | 6 ++- test/api/commands/push.test.ts | 46 ++++++++++++++++++++++ 4 files changed, 66 insertions(+), 5 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index a9f4d6b38..996f94fe4 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -760,8 +760,8 @@ DESCRIPTION USAGE $ apify actors push [actorId] [--allow-missing-secrets] - [-b ] [--dir ] [-f] [--json] [--open] - [-v ] [-w ] + [--apply-env-vars-to-build] [-b ] [--dir ] + [-f] [--json] [--open] [-v ] [-w ] ARGUMENTS actorId Name or ID of the Actor to push (e.g. "apify/hello-world" or @@ -772,6 +772,11 @@ FLAGS --allow-missing-secrets Allow the command to continue even when secret values are not found in the local secrets storage. + --apply-env-vars-to-build 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. -b, --build-tag= Build tag to be applied to the successful Actor build. By default, it is taken from the '.actor/actor.json' file. diff --git a/src/commands/actors/push.ts b/src/commands/actors/push.ts index d2d2c546a..c97f121bc 100644 --- a/src/commands/actors/push.ts +++ b/src/commands/actors/push.ts @@ -191,6 +191,11 @@ export class ActorsPushCommand extends ApifyCommand { required: false, default: false, }), + '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.', + required: false, + }), }; static override args = { @@ -406,9 +411,11 @@ Skipping push. Use --force to override.`, allowMissing: this.flags.allowMissingSecrets, }) : undefined; + // true/false when --[no-]apply-env-vars-to-build is passed, undefined when omitted so the value stored on the platform is preserved + const { applyEnvVarsToBuild } = this.flags; if (actorCurrentVersion) { - const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType, envVars }; + const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType, envVars, applyEnvVarsToBuild }; // TODO: fix this type too -.- await actorClient.version(version).update(actorVersionModifier as never); run({ message: `Updated version ${version} for Actor ${actor.name}.` }); @@ -420,6 +427,7 @@ Skipping push. Use --force to override.`, buildTag, sourceType, envVars, + applyEnvVarsToBuild, }; await actorClient.versions().create({ diff --git a/src/lib/command-framework/apify-command.ts b/src/lib/command-framework/apify-command.ts index 06b024537..f4718581e 100644 --- a/src/lib/command-framework/apify-command.ts +++ b/src/lib/command-framework/apify-command.ts @@ -500,7 +500,9 @@ export abstract class ApifyCommand rawFlags[matcher]); + // Check for presence, not truthiness: the real CLI path always yields arrays (`multiple: true`), but + // internalRunCommand/testRunCommand inject scalar values, where an explicit `false` must match too + const matchingFlags = allMatchers.filter((matcher) => typeof rawFlags[matcher] !== 'undefined'); if (matchingFlags.length > 1) { throw new CommandError({ @@ -514,7 +516,7 @@ export abstract class ApifyCommand { TEST_TIMEOUT, ); + it( + 'should set applyEnvVarsToBuild when the flag is passed and keep it when omitted', + async () => { + const testActor = await testUserClient.actors().create(TEST_ACTOR); + actorsForCleanup.add(testActor.id); + const testActorClient = testUserClient.actor(testActor.id); + const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8')); + + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + flags_applyEnvVarsToBuild: true, + }); + + const versionWithFlag = await testActorClient.version(actorJson.version).get(); + + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + }); + + const versionWithoutFlag = await testActorClient.version(actorJson.version).get(); + + // false is what --no-apply-env-vars-to-build parses to + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + flags_applyEnvVarsToBuild: false, + }); + + const versionWithNegatedFlag = await testActorClient.version(actorJson.version).get(); + + await testActorClient.delete(); + + expect(versionWithFlag!.applyEnvVarsToBuild).to.be.eql(true); + // omitting the flag must preserve the value stored on the platform + expect(versionWithoutFlag!.applyEnvVarsToBuild).to.be.eql(true); + // the negated flag must actively turn the setting off + expect(versionWithNegatedFlag!.applyEnvVarsToBuild).to.be.eql(false); + }, + TEST_TIMEOUT, + ); + it( 'should upload zip for source files larger that 3MB', async () => { From a8a1158ea971efb58bfcf8bb9756d7f28c3f4d00 Mon Sep 17 00:00:00 2001 From: Matous Marik Date: Mon, 24 Aug 2026 16:57:20 +0200 Subject: [PATCH 2/7] feat: read applyEnvVarsToBuild from actor.json in apify push 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. --- docs/reference.md | 7 +++- docs/vars.md | 19 +++++++++ src/commands/actors/push.ts | 8 ++-- test/api/commands/push.test.ts | 70 ++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 6 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index 996f94fe4..cb707be19 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -775,8 +775,11 @@ FLAGS --apply-env-vars-to-build 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. + the setting off. Overrides the + 'applyEnvVarsToBuild' field in the + '.actor/actor.json' file. When both are omitted, + the setting currently stored on the platform is + kept. -b, --build-tag= Build tag to be applied to the successful Actor build. By default, it is taken from the '.actor/actor.json' file. diff --git a/docs/vars.md b/docs/vars.md index 2ca91338e..c342c3151 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -74,3 +74,22 @@ You can use the CLI to manage secrets environment variables: ... } ``` + +### Apply environment variables to the build + +By default, custom environment variables are available only at runtime. To also make them available to the Actor build process (for example, as Docker build arguments), set `applyEnvVarsToBuild` in `.actor/actor.json`: + +```json +{ + "actorSpecification": 1, + "name": "dataset-to-mysql", + "version": "0.1", + "buildTag": "latest", + "applyEnvVarsToBuild": true, + "environmentVariables": { + "MYSQL_PASSWORD": "@mySecretPassword" + } +} +``` + +Alternatively, pass the `--apply-env-vars-to-build` flag to `apify push` for a one-off push, or `--no-apply-env-vars-to-build` to turn the setting off. The flag overrides the `applyEnvVarsToBuild` field. When both are omitted, the setting currently stored on the Apify platform is kept. diff --git a/src/commands/actors/push.ts b/src/commands/actors/push.ts index c97f121bc..e822d1043 100644 --- a/src/commands/actors/push.ts +++ b/src/commands/actors/push.ts @@ -192,8 +192,7 @@ export class ActorsPushCommand extends ApifyCommand { default: false, }), '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.`, required: false, }), }; @@ -411,8 +410,9 @@ Skipping push. Use --force to override.`, allowMissing: this.flags.allowMissingSecrets, }) : undefined; - // true/false when --[no-]apply-env-vars-to-build is passed, undefined when omitted so the value stored on the platform is preserved - const { applyEnvVarsToBuild } = this.flags; + // undefined when neither the flag nor the actor.json field is set, so the value stored on the platform is preserved + const applyEnvVarsToBuild = + this.flags.applyEnvVarsToBuild ?? (actorConfig!.applyEnvVarsToBuild as boolean | undefined); if (actorCurrentVersion) { const actorVersionModifier = { tarballUrl, sourceFiles, buildTag, sourceType, envVars, applyEnvVarsToBuild }; diff --git a/test/api/commands/push.test.ts b/test/api/commands/push.test.ts index 2eaea9814..2e781db7b 100644 --- a/test/api/commands/push.test.ts +++ b/test/api/commands/push.test.ts @@ -261,6 +261,76 @@ describe('[api] apify push', () => { TEST_TIMEOUT, ); + it( + 'should read applyEnvVarsToBuild from actor.json, with the flag taking precedence', + async () => { + const testActor = await testUserClient.actors().create(TEST_ACTOR); + actorsForCleanup.add(testActor.id); + const testActorClient = testUserClient.actor(testActor.id); + const actorJson = JSON.parse(readFileSync(joinPath(LOCAL_CONFIG_PATH), 'utf8')); + + try { + actorJson.applyEnvVarsToBuild = true; + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + }); + + const versionWithFieldTrue = await testActorClient.version(actorJson.version).get(); + + actorJson.applyEnvVarsToBuild = false; + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + // the actor config is cached per cwd, so mid-test rewrites need a reset + resetCwdCaches(); + + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + }); + + const versionWithFieldFalse = await testActorClient.version(actorJson.version).get(); + + // the file still says false, but the flag must win + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + flags_applyEnvVarsToBuild: true, + }); + + const versionWithFlagOverride = await testActorClient.version(actorJson.version).get(); + + // and the negated flag must also win over a true in the file + actorJson.applyEnvVarsToBuild = true; + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + resetCwdCaches(); + + await testRunCommand(ActorsPushCommand, { + args_actorId: testActor.id, + flags_noPrompt: true, + flags_force: true, + flags_applyEnvVarsToBuild: false, + }); + + const versionWithNegatedFlagOverride = await testActorClient.version(actorJson.version).get(); + + expect(versionWithFieldTrue!.applyEnvVarsToBuild).to.be.eql(true); + expect(versionWithFieldFalse!.applyEnvVarsToBuild).to.be.eql(false); + expect(versionWithFlagOverride!.applyEnvVarsToBuild).to.be.eql(true); + expect(versionWithNegatedFlagOverride!.applyEnvVarsToBuild).to.be.eql(false); + } finally { + delete actorJson.applyEnvVarsToBuild; + writeFileSync(joinPath(LOCAL_CONFIG_PATH), JSON.stringify(actorJson, null, '\t'), { flag: 'w' }); + await testActorClient.delete(); + } + }, + TEST_TIMEOUT, + ); + it( 'should upload zip for source files larger that 3MB', async () => { From ad650e75402415a580736bb1d9df37c7c496802e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ma=C5=99=C3=ADk?= Date: Thu, 27 Aug 2026 15:44:31 +0200 Subject: [PATCH 3/7] Update docs/vars.md Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com> --- docs/vars.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/vars.md b/docs/vars.md index c342c3151..73587f582 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -77,7 +77,7 @@ You can use the CLI to manage secrets environment variables: ### Apply environment variables to the build -By default, custom environment variables are available only at runtime. To also make them available to the Actor build process (for example, as Docker build arguments), set `applyEnvVarsToBuild` in `.actor/actor.json`: +By default, custom environment variables are available only at runtime. To make them available also to the Actor build process, for example, as Docker build arguments, set `applyEnvVarsToBuild` in `.actor/actor.json`: ```json { From e151eb021dda7e2d57b59b83ea1d86b7849571ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ma=C5=99=C3=ADk?= Date: Thu, 27 Aug 2026 15:44:52 +0200 Subject: [PATCH 4/7] Update docs/vars.md Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com> --- docs/vars.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/vars.md b/docs/vars.md index 73587f582..47a2308d2 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -92,4 +92,4 @@ By default, custom environment variables are available only at runtime. To make } ``` -Alternatively, pass the `--apply-env-vars-to-build` flag to `apify push` for a one-off push, or `--no-apply-env-vars-to-build` to turn the setting off. The flag overrides the `applyEnvVarsToBuild` field. When both are omitted, the setting currently stored on the Apify platform is kept. +To apply the environment variables to a single push, add the `--apply-env-vars-to-build` flag to the `apify push` command. To turn off the setting for a single push, add the `--no-apply-env-vars-to-build` flag. The flag overrides the value of the `applyEnvVarsToBuild` field. If you don't use a flag, the Apify platform keeps the stored setting. From efd24753bc42cc5c20680dae30fa539b8259f2e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matou=C5=A1=20Ma=C5=99=C3=ADk?= Date: Thu, 27 Aug 2026 15:45:13 +0200 Subject: [PATCH 5/7] Update src/commands/actors/push.ts Co-authored-by: Edyta <142720610+szaganek@users.noreply.github.com> --- src/commands/actors/push.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/actors/push.ts b/src/commands/actors/push.ts index e822d1043..ef3071b45 100644 --- a/src/commands/actors/push.ts +++ b/src/commands/actors/push.ts @@ -192,7 +192,7 @@ export class ActorsPushCommand extends ApifyCommand { default: false, }), '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. 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.`, required: false, }), }; From e212cdaa239ae15c3ec2306cb76d6982ab968350 Mon Sep 17 00:00:00 2001 From: Matous Marik Date: Wed, 9 Sep 2026 15:41:04 +0200 Subject: [PATCH 6/7] docs: clarify when the platform-stored applyEnvVarsToBuild is kept MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- docs/vars.md | 2 +- src/commands/actors/push.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/vars.md b/docs/vars.md index 47a2308d2..27f3fd3c2 100644 --- a/docs/vars.md +++ b/docs/vars.md @@ -92,4 +92,4 @@ By default, custom environment variables are available only at runtime. To make } ``` -To apply the environment variables to a single push, add the `--apply-env-vars-to-build` flag to the `apify push` command. To turn off the setting for a single push, add the `--no-apply-env-vars-to-build` flag. The flag overrides the value of the `applyEnvVarsToBuild` field. If you don't use a flag, the Apify platform keeps the stored setting. +To apply the environment variables to a single push, add the `--apply-env-vars-to-build` flag to the `apify push` command. To turn off the setting for a single push, add the `--no-apply-env-vars-to-build` flag. The flag overrides the value of the `applyEnvVarsToBuild` field. If you use neither the field nor a flag, the Apify platform keeps the stored setting. diff --git a/src/commands/actors/push.ts b/src/commands/actors/push.ts index ef3071b45..a5214f32f 100644 --- a/src/commands/actors/push.ts +++ b/src/commands/actors/push.ts @@ -192,7 +192,7 @@ export class ActorsPushCommand extends ApifyCommand { default: false, }), 'apply-env-vars-to-build': Flags.boolean({ - 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.`, + 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. When both the field and the flag are omitted, the setting currently stored on the platform is kept.`, required: false, }), }; From 703e69a3f8c381bbe06ed0e97c28b1b22b09ce65 Mon Sep 17 00:00:00 2001 From: Matous Marik Date: Wed, 9 Sep 2026 15:42:11 +0200 Subject: [PATCH 7/7] docs: regenerate reference.md Co-Authored-By: Claude Opus 5 (1M context) --- docs/reference.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index cb707be19..e43788078 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -774,12 +774,12 @@ FLAGS the local secrets storage. --apply-env-vars-to-build 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 - '.actor/actor.json' file. When both are omitted, - the setting currently stored on the platform is - kept. + process. To turn the setting off, use + --no-apply-env-vars-to-build. Overrides the value + of the 'applyEnvVarsToBuild' field in the + '.actor/actor.json' file. When both the field and + the flag are omitted, the setting currently stored + on the platform is kept. -b, --build-tag= Build tag to be applied to the successful Actor build. By default, it is taken from the '.actor/actor.json' file.