Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ jobs:
env:
TEST_USER_TOKEN: ${{ secrets.APIFY_TEST_USER_API_TOKEN }}
APIFY_CLI_DISABLE_TELEMETRY: 1
NO_SILENT_TESTS: 1
run: yarn test-python

docs:
Expand Down
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,15 @@
"cors": "~2.8.5",
"detect-indent": "~7.0.1",
"escape-string-regexp": "~5.0.0",
"execa": "^9.5.2",
"express": "~4.21.0",
"fs-extra": "^11.2.0",
"globby": "~14.1.0",
"handlebars": "~4.7.8",
"inquirer": "~12.5.0",
"is-ci": "~4.1.0",
"is-online": "~11.0.0",
"istextorbinary": "~9.5.0",
"jju": "~1.4.0",
"load-json-file": "~7.0.1",
"lodash.clonedeep": "^4.5.0",
"mime": "~4.0.4",
"mixpanel": "~0.18.0",
Expand All @@ -99,8 +98,7 @@
"rimraf": "~6.0.1",
"semver": "~7.7.0",
"tiged": "~2.12.7",
"underscore": "~1.13.7",
"write-json-file": "~6.0.0"
"which": "^5.0.0"
},
"devDependencies": {
"@apify/eslint-config": "^0.4.0",
Expand All @@ -110,11 +108,12 @@
"@crawlee/types": "^3.11.1",
"@cucumber/cucumber": "^11.0.0",
"@oclif/test": "^4.0.8",
"@sapphire/result": "^2.6.6",
"@sapphire/result": "^2.7.2",
"@types/adm-zip": "^0.5.5",
"@types/archiver": "^6.0.2",
"@types/chai": "^4.3.17",
"@types/cors": "^2.8.17",
"@types/execa": "^2.0.2",
"@types/express": "^4.17.21",
"@types/fs-extra": "^11",
"@types/inquirer": "^9.0.7",
Expand All @@ -124,7 +123,7 @@
"@types/mime": "^4.0.0",
"@types/node": "^22.0.0",
"@types/semver": "^7.5.8",
"@types/underscore": "^1.11.15",
"@types/which": "^3.0.4",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.0.2",
"@yarnpkg/core": "^4.1.2",
Expand All @@ -133,7 +132,6 @@
"cross-env": "^7.0.3",
"eslint": "^8.57.0",
"eslint-config-prettier": "^10.0.0",
"execa": "^9.5.2",
"lint-staged": "^15.2.8",
"mdast-util-from-markdown": "^2.0.2",
"mock-stdin": "^1.0.0",
Expand Down
20 changes: 9 additions & 11 deletions src/commands/actors/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import tiged from 'tiged';

import { ApifyCommand } from '../../lib/apify_command.js';
import { CommandExitCodes, LOCAL_CONFIG_PATH } from '../../lib/consts.js';
import { useActorConfig } from '../../lib/hooks/useActorConfig.js';
import { error, success } from '../../lib/outputs.js';
import { getLocalConfigOrThrow, getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';
import { getLocalUserInfo, getLoggedClientOrThrow } from '../../lib/utils.js';

const extractGitHubZip = async (url: string, directoryPath: string) => {
const { data } = await axios.get(url, { responseType: 'arraybuffer' });
Expand Down Expand Up @@ -51,19 +52,16 @@ export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {
async run() {
const cwd = process.cwd();

let localConfig: Record<string, unknown>;
const actorConfigResult = await useActorConfig({ cwd });

try {
localConfig = (await getLocalConfigOrThrow(cwd))!;
} catch (_error) {
const casted = _error as Error;
const cause = casted.cause as Error;

error({ message: `${casted.message}\n ${cause.message}` });
if (actorConfigResult.isErr()) {
error({ message: actorConfigResult.unwrapErr().message });
process.exitCode = CommandExitCodes.InvalidActorJson;
return;
}

const { config: actorConfig } = actorConfigResult.unwrap();

const userInfo = await getLocalUserInfo();
const apifyClient = await getLoggedClientOrThrow();

Expand All @@ -72,8 +70,8 @@ export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {

const actorId =
this.args?.actorId ||
(localConfig?.id as string | undefined) ||
(localConfig?.name ? `${usernameOrId}/${localConfig.name}` : undefined);
(actorConfig?.id as string | undefined) ||
(actorConfig?.name ? `${usernameOrId}/${actorConfig.name}` : undefined);

if (!actorId) throw new Error('Cannot find Actor in this directory.');

Expand Down
37 changes: 17 additions & 20 deletions src/commands/actors/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import open from 'open';
import { ApifyCommand } from '../../lib/apify_command.js';
import { CommandExitCodes, DEPRECATED_LOCAL_CONFIG_NAME, LOCAL_CONFIG_PATH } from '../../lib/consts.js';
import { sumFilesSizeInBytes } from '../../lib/files.js';
import { useActorConfig } from '../../lib/hooks/useActorConfig.js';
import { error, info, link, run, success, warning } from '../../lib/outputs.js';
import { transformEnvToEnvVars } from '../../lib/secrets.js';
import {
createActZip,
createSourceFiles,
getActorLocalFilePaths,
getLocalConfigOrThrow,
getLocalUserInfo,
getLoggedClientOrThrow,
outputJobLog,
Expand Down Expand Up @@ -131,19 +131,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {

const apifyClient = await getLoggedClientOrThrow();

let localConfig: Record<string, unknown>;
const actorConfigResult = await useActorConfig({ cwd });

try {
localConfig = (await getLocalConfigOrThrow(cwd))!;
} catch (_error) {
const casted = _error as Error;
const cause = casted.cause as Error;

error({ message: `${casted.message}\n ${cause.message}` });
if (actorConfigResult.isErr()) {
error({ message: actorConfigResult.unwrapErr().message });
process.exitCode = CommandExitCodes.InvalidActorJson;
return;
}

const { config: actorConfig } = actorConfigResult.unwrap();

const userInfo = await getLocalUserInfo();
const isOrganizationLoggedIn = !!userInfo.organizationOwnerUserId;
const redirectUrlPart = isOrganizationLoggedIn ? `/organization/${userInfo.id}` : '';
Expand All @@ -154,9 +151,9 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {

// User can override Actor version and build tag, attributes in localConfig will remain same.
const version =
this.flags.version || (localConfig?.version as string | undefined) || DEFAULT_ACTOR_VERSION_NUMBER;
this.flags.version || (actorConfig?.version as string | undefined) || DEFAULT_ACTOR_VERSION_NUMBER;

let buildTag = this.flags.buildTag || (localConfig!.buildTag as string | undefined);
let buildTag = this.flags.buildTag || (actorConfig?.buildTag as string | undefined);

// We can't add the default build tag to everything. If a user creates a new
// version, e.g. for testing, but forgets to add a tag, it would use the default
Expand All @@ -180,16 +177,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
actorId = actor.id;
} else {
const usernameOrId = userInfo.username || userInfo.id;
actor = (await apifyClient.actor(`${usernameOrId}/${localConfig!.name}`).get())!;
actor = (await apifyClient.actor(`${usernameOrId}/${actorConfig!.name}`).get())!;
if (actor) {
actorId = actor.id;
} else {
const { templates } = await fetchManifest();
const actorTemplate = templates.find((t) => t.name === localConfig!.template);
const actorTemplate = templates.find((t) => t.name === actorConfig!.template);
const defaultRunOptions = (actorTemplate?.defaultRunOptions ||
DEFAULT_RUN_OPTIONS) as ActorDefaultRunOptions;
const newActor: ActorCollectionCreateOptions = {
name: localConfig!.name as string,
name: actorConfig!.name as string,
defaultRunOptions,
versions: [
{
Expand All @@ -204,11 +201,11 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
actor = await apifyClient.actors().create(newActor);
actorId = actor.id;
isActorCreatedNow = true;
info({ message: `Created Actor with name ${localConfig!.name} on Apify.` });
info({ message: `Created Actor with name ${actorConfig!.name} on Apify.` });
}
}

info({ message: `Deploying Actor '${localConfig!.name}' to Apify.` });
info({ message: `Deploying Actor '${actorConfig!.name}' to Apify.` });

const filesSize = await sumFilesSizeInBytes(filePathsToPush, cwd);
const actorClient = apifyClient.actor(actorId);
Expand All @@ -235,10 +232,10 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
!this.flags.force &&
actorModifiedMs &&
mostRecentModifiedFileMs < actorModifiedMs &&
(localConfig?.name || forceActorId)
(actorConfig?.name || forceActorId)
) {
throw new Error(
`Actor with identifier "${localConfig?.name || forceActorId}" is already on the platform and was modified there since modified locally.
`Actor with identifier "${actorConfig?.name || forceActorId}" is already on the platform and was modified there since modified locally.
Skipping push. Use --force to override.`,
);
}
Expand Down Expand Up @@ -268,8 +265,8 @@ Skipping push. Use --force to override.`,

// Update Actor version
const actorCurrentVersion = await actorClient.version(version).get();
const envVars = localConfig!.environmentVariables
? transformEnvToEnvVars(localConfig!.environmentVariables as Record<string, string>)
const envVars = actorConfig!.environmentVariables
? transformEnvToEnvVars(actorConfig!.environmentVariables as Record<string, string>)
: undefined;

if (actorCurrentVersion) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/actors/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Args } from '@oclif/core';
import type { ApifyApiError } from 'apify-client';

import { ApifyCommand } from '../../lib/apify_command.js';
import { confirmAction } from '../../lib/commands/confirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { confirmAction } from '../../lib/utils/confirm.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';

export class ActorRmCommand extends ApifyCommand<typeof ActorRmCommand> {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/builds/rm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Args } from '@oclif/core';
import type { ActorTaggedBuild, ApifyApiError } from 'apify-client';

import { ApifyCommand } from '../../lib/apify_command.js';
import { confirmAction } from '../../lib/commands/confirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { confirmAction } from '../../lib/utils/confirm.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';

export class BuildsRmCommand extends ApifyCommand<typeof BuildsRmCommand> {
Expand Down
Loading