Skip to content

Commit

Permalink
feat: Add support for reading ids from file with executeBatch command (
Browse files Browse the repository at this point in the history
  • Loading branch information
krynble authored Mar 19, 2022
1 parent c0611a0 commit 5658593
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
shell: bash
-
name: Run tests
run: n8n/packages/cli/bin/n8n executeBatch --shallow --skipList=test-workflows/skipList.txt --shortOutput --concurrency=16 --compare=test-workflows/snapshots
run: n8n/packages/cli/bin/n8n executeBatch --shallow --ids=test-workflows/safeList.txt --shortOutput --concurrency=16 --compare=test-workflows/snapshots
shell: bash
env:
N8N_ENCRYPTION_KEY: ${{secrets.ENCRYPTION_KEY}}
Expand Down
28 changes: 19 additions & 9 deletions packages/cli/commands/executeBatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export class ExecuteBatch extends Command {
description: 'Toggles on displaying all errors and debug messages.',
}),
ids: flags.string({
description: 'Specifies workflow IDs to get executed, separated by a comma.',
description:
'Specifies workflow IDs to get executed, separated by a comma or a file containing the ids',
}),
concurrency: flags.integer({
default: 1,
Expand Down Expand Up @@ -244,16 +245,25 @@ export class ExecuteBatch extends Command {
}

if (flags.ids !== undefined) {
const paramIds = flags.ids.split(',');
const re = /\d+/;
const matchedIds = paramIds.filter((id) => re.exec(id)).map((id) => parseInt(id.trim(), 10));
if (fs.existsSync(flags.ids)) {
const contents = fs.readFileSync(flags.ids, { encoding: 'utf-8' });
ids.push(...contents.split(',').map((id) => parseInt(id.trim(), 10)));
} else {
const paramIds = flags.ids.split(',');
const re = /\d+/;
const matchedIds = paramIds
.filter((id) => re.exec(id))
.map((id) => parseInt(id.trim(), 10));

if (matchedIds.length === 0) {
console.log(
`The parameter --ids must be a list of numeric IDs separated by a comma or a file with this content.`,
);
return;
}

if (matchedIds.length === 0) {
console.log(`The parameter --ids must be a list of numeric IDs separated by a comma.`);
return;
ids.push(...matchedIds);
}

ids.push(...matchedIds);
}

if (flags.skipList !== undefined) {
Expand Down

0 comments on commit 5658593

Please sign in to comment.