Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,8 @@ DESCRIPTION

USAGE
$ apify actors push [actorId] [--allow-missing-secrets]
[-b <value>] [--dir <value>] [-f] [--json] [--open]
[-v <value>] [-w <value>]
[--apply-env-vars-to-build] [-b <value>] [--dir <value>]
[-f] [--json] [--open] [-v <value>] [-w <value>]

ARGUMENTS
actorId Name or ID of the Actor to push (e.g. "apify/hello-world" or
Expand All @@ -800,6 +800,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=<value> Build tag to be
applied to the successful Actor build. By default,
it is taken from the '.actor/actor.json' file.
Expand Down
10 changes: 9 additions & 1 deletion src/commands/actors/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
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 = {
Expand Down Expand Up @@ -454,9 +459,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}.` });
Expand All @@ -468,6 +475,7 @@ Skipping push. Use --force to override.`,
buildTag,
sourceType,
envVars,
applyEnvVarsToBuild,
};

await actorClient.versions().create({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/command-framework/apify-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ export abstract class ApifyCommand<T extends typeof BuiltApifyCommand = typeof B

let rawFlag = rawFlags[matchingFlags[0]];

if (!rawFlag && builderData.required) {
if (typeof rawFlag === 'undefined' && builderData.required) {

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.

there will be conflict in this line, upstream version with Object.hasOwn seem better idea to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — #1332 landed the same presence check with Object.hasOwn, so the merge commit drops my line and keeps yours. Only the required-flag check (!rawFlagtypeof rawFlag === "undefined") remains from this PR, which is still needed so --no-<flag> (false) does not read as missing.

throw new CommandError({
code: CommandErrorCode.APIFY_MISSING_FLAG,
command: this.ctor,
Expand Down
46 changes: 46 additions & 0 deletions test/api/commands/push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,52 @@ 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();

// 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 () => {
Expand Down
Loading