Skip to content

Commit

Permalink
feat(core): Upgrade oclif (no-changelog) (n8n-io#8381)
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy authored Jan 22, 2024
1 parent 2c146cc commit 913c8c6
Show file tree
Hide file tree
Showing 29 changed files with 234 additions and 677 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/e2e-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Cypress run
uses: cypress-io/github-action@v5.8.3
uses: cypress-io/github-action@v6.6.1
with:
install: false
start: pnpm start
Expand All @@ -172,6 +172,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
E2E_TESTS: true
COMMIT_INFO_MESSAGE: 🌳 ${{ inputs.branch }} 🖥️ ${{ inputs.run-env }} 🤖 ${{ inputs.user }} 🗃️ ${{ inputs.spec }}
SHELL: /bin/sh

# Check if all tests passed and set the output variable
check_testing_matrix:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ cypress/screenshots/*
cypress/downloads/*
*.swp
CHANGELOG-*.md
packages/cli/oclif.manifest.json
8 changes: 4 additions & 4 deletions packages/cli/bin/n8n
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if (process.env.NODEJS_PREFER_IPV4 === 'true') {
require('dns').setDefaultResultOrder('ipv4first');
}

require('@oclif/command')
.run()
.then(require('@oclif/command/flush'))
.catch(require('@oclif/errors/handle'));
(async () => {
const oclif = await import('@oclif/core');
await oclif.execute({});
})();
9 changes: 1 addition & 8 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"format": "prettier --write . --ignore-path ../../.prettierignore",
"lint": "eslint . --quiet",
"lintfix": "eslint . --fix",
"postpack": "rm -f oclif.manifest.json",
"prepack": "OCLIF_TS_NODE=0 oclif-dev manifest",
"start": "run-script-os",
"start:default": "cd bin && ./n8n",
"start:windows": "cd bin && n8n",
Expand Down Expand Up @@ -59,12 +57,10 @@
"bin",
"templates",
"dist",
"oclif.manifest.json",
"!dist/**/e2e.*"
],
"devDependencies": {
"@redocly/cli": "^1.6.0",
"@oclif/dev-cli": "^1.22.2",
"@types/basic-auth": "^1.1.3",
"@types/bcryptjs": "^2.4.2",
"@types/compression": "1.0.1",
Expand Down Expand Up @@ -101,10 +97,7 @@
"@n8n/n8n-nodes-langchain": "workspace:*",
"@n8n/permissions": "workspace:*",
"@n8n_io/license-sdk": "2.7.2",
"@oclif/command": "1.8.18",
"@oclif/config": "1.18.17",
"@oclif/core": "1.16.6",
"@oclif/errors": "1.3.6",
"@oclif/core": "3.18.1",
"@rudderstack/rudder-sdk-node": "1.0.6",
"@sentry/integrations": "7.87.0",
"@sentry/node": "7.87.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/BaseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'reflect-metadata';
import { Command } from '@oclif/command';
import { ExitError } from '@oclif/errors';
import { Container } from 'typedi';
import { Command } from '@oclif/core';
import { ExitError } from '@oclif/core/lib/errors';
import { ApplicationError, ErrorReporterProxy as ErrorReporter, sleep } from 'n8n-workflow';
import { BinaryDataService, InstanceSettings, ObjectStoreService } from 'n8n-core';
import type { AbstractServer } from '@/AbstractServer';
Expand Down
15 changes: 8 additions & 7 deletions packages/cli/src/commands/audit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { flags } from '@oclif/command';
import { Container } from 'typedi';
import { Flags } from '@oclif/core';
import { ApplicationError } from 'n8n-workflow';

import { SecurityAuditService } from '@/security-audit/SecurityAudit.service';
import { RISK_CATEGORIES } from '@/security-audit/constants';
import config from '@/config';
import type { Risk } from '@/security-audit/types';
import { BaseCommand } from './BaseCommand';
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { ApplicationError } from 'n8n-workflow';

export class SecurityAudit extends BaseCommand {
static description = 'Generate a security audit report for this n8n instance';
Expand All @@ -18,20 +19,20 @@ export class SecurityAudit extends BaseCommand {
];

static flags = {
help: flags.help({ char: 'h' }),
categories: flags.string({
help: Flags.help({ char: 'h' }),
categories: Flags.string({
default: RISK_CATEGORIES.join(','),
description: 'Comma-separated list of categories to include in the audit',
}),
// eslint-disable-next-line @typescript-eslint/naming-convention
'days-abandoned-workflow': flags.integer({
'days-abandoned-workflow': Flags.integer({
default: config.getEnv('security.audit.daysAbandonedWorkflow'),
description: 'Days for a workflow to be considered abandoned if not executed',
}),
};

async run() {
const { flags: auditFlags } = this.parse(SecurityAudit);
const { flags: auditFlags } = await this.parse(SecurityAudit);

const categories =
auditFlags.categories?.split(',').filter((c): c is Risk.Category => c !== '') ??
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/db/revert.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command, flags } from '@oclif/command';
import { Command, Flags } from '@oclif/core';
import type { DataSourceOptions as ConnectionOptions } from 'typeorm';
import { DataSource as Connection } from 'typeorm';
import { Container } from 'typedi';
Expand All @@ -14,15 +14,15 @@ export class DbRevertMigrationCommand extends Command {
static examples = ['$ n8n db:revert'];

static flags = {
help: flags.help({ char: 'h' }),
help: Flags.help({ char: 'h' }),
};

protected logger = Container.get(Logger);

private connection: Connection;

async init() {
this.parse(DbRevertMigrationCommand);
await this.parse(DbRevertMigrationCommand);
}

async run() {
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/commands/execute.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container } from 'typedi';
import { Flags } from '@oclif/core';
import { promises as fs } from 'fs';
import { flags } from '@oclif/command';
import { PLACEHOLDER_EMPTY_WORKFLOW_ID } from 'n8n-core';
import type { IWorkflowBase } from 'n8n-workflow';
import { ApplicationError, ExecutionBaseError } from 'n8n-workflow';
Expand All @@ -9,7 +10,7 @@ import { WorkflowRunner } from '@/WorkflowRunner';
import type { IWorkflowExecutionDataProcess } from '@/Interfaces';
import { findCliWorkflowStart, isWorkflowIdValid } from '@/utils';
import { BaseCommand } from './BaseCommand';
import { Container } from 'typedi';

import { WorkflowRepository } from '@db/repositories/workflow.repository';
import { OwnershipService } from '@/services/ownership.service';

Expand All @@ -19,14 +20,14 @@ export class Execute extends BaseCommand {
static examples = ['$ n8n execute --id=5', '$ n8n execute --file=workflow.json'];

static flags = {
help: flags.help({ char: 'h' }),
file: flags.string({
help: Flags.help({ char: 'h' }),
file: Flags.string({
description: 'path to a workflow file to execute',
}),
id: flags.string({
id: Flags.string({
description: 'id of the workflow to execute',
}),
rawOutput: flags.boolean({
rawOutput: Flags.boolean({
description: 'Outputs only JSON data, with no other text',
}),
};
Expand All @@ -38,8 +39,7 @@ export class Execute extends BaseCommand {
}

async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(Execute);
const { flags } = await this.parse(Execute);

if (!flags.id && !flags.file) {
this.logger.info('Either option "--id" or "--file" have to be set!');
Expand Down
36 changes: 18 additions & 18 deletions packages/cli/src/commands/executeBatch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-loop-func */
import { Container } from 'typedi';
import { Flags } from '@oclif/core';
import fs from 'fs';
import os from 'os';
import { flags } from '@oclif/command';
import type { IRun, ITaskData } from 'n8n-workflow';
import { ApplicationError, jsonParse, sleep } from 'n8n-workflow';
import { sep } from 'path';
Expand All @@ -12,18 +13,18 @@ import { ActiveExecutions } from '@/ActiveExecutions';
import { WorkflowRunner } from '@/WorkflowRunner';
import type { IWorkflowDb, IWorkflowExecutionDataProcess } from '@/Interfaces';
import type { User } from '@db/entities/User';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
import { OwnershipService } from '@/services/ownership.service';
import { findCliWorkflowStart } from '@/utils';

import { BaseCommand } from './BaseCommand';
import { Container } from 'typedi';
import type {
IExecutionResult,
INodeSpecialCase,
INodeSpecialCases,
IResult,
IWorkflowExecutionProgress,
} from '../types/commands.types';
import { WorkflowRepository } from '@db/repositories/workflow.repository';
import { OwnershipService } from '@/services/ownership.service';

const re = /\d+/;

Expand Down Expand Up @@ -60,49 +61,49 @@ export class ExecuteBatch extends BaseCommand {
];

static flags = {
help: flags.help({ char: 'h' }),
debug: flags.boolean({
help: Flags.help({ char: 'h' }),
debug: Flags.boolean({
description: 'Toggles on displaying all errors and debug messages.',
}),
ids: flags.string({
ids: Flags.string({
description:
'Specifies workflow IDs to get executed, separated by a comma or a file containing the ids',
}),
concurrency: flags.integer({
concurrency: Flags.integer({
default: 1,
description:
'How many workflows can run in parallel. Defaults to 1 which means no concurrency.',
}),
output: flags.string({
output: Flags.string({
description:
'Enable execution saving, You must inform an existing folder to save execution via this param',
}),
snapshot: flags.string({
snapshot: Flags.string({
description:
'Enables snapshot saving. You must inform an existing folder to save snapshots via this param.',
}),
compare: flags.string({
compare: Flags.string({
description:
'Compares current execution with an existing snapshot. You must inform an existing folder where the snapshots are saved.',
}),
shallow: flags.boolean({
shallow: Flags.boolean({
description:
'Compares only if attributes output from node are the same, with no regards to nested JSON objects.',
}),

githubWorkflow: flags.boolean({
githubWorkflow: Flags.boolean({
description:
'Enables more lenient comparison for GitHub workflows. This is useful for reducing false positives when comparing Test workflows.',
}),

skipList: flags.string({
skipList: Flags.string({
description: 'File containing a comma separated list of workflow IDs to skip.',
}),
retries: flags.integer({
retries: Flags.integer({
description: 'Retries failed workflows up to N tries. Default is 1. Set 0 to disable.',
default: 1,
}),
shortOutput: flags.boolean({
shortOutput: Flags.boolean({
description: 'Omits the full execution information from output, displaying only summary.',
}),
};
Expand Down Expand Up @@ -185,8 +186,7 @@ export class ExecuteBatch extends BaseCommand {
}

async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(ExecuteBatch);
const { flags } = await this.parse(ExecuteBatch);
ExecuteBatch.debug = flags.debug;
ExecuteBatch.concurrency = flags.concurrency || 1;

Expand Down
21 changes: 10 additions & 11 deletions packages/cli/src/commands/export/credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from '@oclif/command';
import { Flags } from '@oclif/core';
import fs from 'fs';
import path from 'path';
import { Credentials } from 'n8n-core';
Expand All @@ -20,37 +20,36 @@ export class ExportCredentialsCommand extends BaseCommand {
];

static flags = {
help: flags.help({ char: 'h' }),
all: flags.boolean({
help: Flags.help({ char: 'h' }),
all: Flags.boolean({
description: 'Export all credentials',
}),
backup: flags.boolean({
backup: Flags.boolean({
description:
'Sets --all --pretty --separate for simple backups. Only --output has to be set additionally.',
}),
id: flags.string({
id: Flags.string({
description: 'The ID of the credential to export',
}),
output: flags.string({
output: Flags.string({
char: 'o',
description: 'Output file name or directory if using separate files',
}),
pretty: flags.boolean({
pretty: Flags.boolean({
description: 'Format the output in an easier to read fashion',
}),
separate: flags.boolean({
separate: Flags.boolean({
description:
'Exports one file per credential (useful for versioning). Must inform a directory via --output.',
}),
decrypted: flags.boolean({
decrypted: Flags.boolean({
description:
'Exports data decrypted / in plain text. ALL SENSITIVE INFORMATION WILL BE VISIBLE IN THE FILES. Use to migrate from a installation to another that have a different secret key (in the config file).',
}),
};

async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(ExportCredentialsCommand);
const { flags } = await this.parse(ExportCredentialsCommand);

if (flags.backup) {
flags.all = true;
Expand Down
19 changes: 9 additions & 10 deletions packages/cli/src/commands/export/workflow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from '@oclif/command';
import { Flags } from '@oclif/core';
import fs from 'fs';
import path from 'path';
import { BaseCommand } from '../BaseCommand';
Expand All @@ -17,33 +17,32 @@ export class ExportWorkflowsCommand extends BaseCommand {
];

static flags = {
help: flags.help({ char: 'h' }),
all: flags.boolean({
help: Flags.help({ char: 'h' }),
all: Flags.boolean({
description: 'Export all workflows',
}),
backup: flags.boolean({
backup: Flags.boolean({
description:
'Sets --all --pretty --separate for simple backups. Only --output has to be set additionally.',
}),
id: flags.string({
id: Flags.string({
description: 'The ID of the workflow to export',
}),
output: flags.string({
output: Flags.string({
char: 'o',
description: 'Output file name or directory if using separate files',
}),
pretty: flags.boolean({
pretty: Flags.boolean({
description: 'Format the output in an easier to read fashion',
}),
separate: flags.boolean({
separate: Flags.boolean({
description:
'Exports one file per workflow (useful for versioning). Must inform a directory via --output.',
}),
};

async run() {
// eslint-disable-next-line @typescript-eslint/no-shadow
const { flags } = this.parse(ExportWorkflowsCommand);
const { flags } = await this.parse(ExportWorkflowsCommand);

if (flags.backup) {
flags.all = true;
Expand Down
Loading

0 comments on commit 913c8c6

Please sign in to comment.