diff --git a/docs/reference.md b/docs/reference.md index a9f4d6b38..f5e6ab996 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,10 @@ 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. 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..4b5ab64d8 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. 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; + // undefined when the flag is omitted, so the value stored on the platform is preserved + const applyEnvVarsToBuild = this.flags.applyEnvVarsToBuild || undefined; 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/test/api/commands/push.test.ts b/test/api/commands/push.test.ts index 5a4dc194b..31443f49e 100644 --- a/test/api/commands/push.test.ts +++ b/test/api/commands/push.test.ts @@ -215,6 +215,40 @@ describe('[api] apify push', () => { 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(); + + 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); + }, + TEST_TIMEOUT, + ); + it( 'should upload zip for source files larger that 3MB', async () => {