diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9522fd4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.env +docker-data/ +output/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24444bf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM n8nio/base:20 +COPY ./entrypoint.sh /entrypoint.sh +RUN chown -R node /entrypoint.sh +USER node +RUN mkdir -p ~/.pnpm-store && pnpm config set store-dir ~/.pnpm-store --global +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index a5ddbe7..0316f91 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,58 @@ # test-workflows n8n workflows used for testing nodes + +## Docker config + +Copy `dot-env.example` to `.env` and add the encryption key there. Also make +sure the n8n repository is checked out at `../n8n`. Then you can run the tests +with: + + +``` +COMMAND=test docker compose up --exit-code-from n8n +``` + +This will create some files and folders in `docker-data/` and an `output/` +folder. The tests will write the results to `output/test-results.json`. + +`output/dot-n8n/` will be mounted to `~/.n8n/` and will contain the database, +which is useful for debugging or when you have started the dev-server (see +below). + +### Running dev server for creating workflows + +The following command will start a dev-server: + +``` +COMMAND=dev docker compose up --exit-code-from n8n +``` + +With this server up, you can create your workflows and/or credentials. Then, +with a new terminal, start a session in the container with: + +``` +docker compose exec n8n /bin/sh +``` + +This allows you to export workflows to `/output/`: + +``` +/n8n/packages/cli/bin/n8n export:workflow --backup --id zFePuiBkF9nlktTH --pretty --separate --output /output/workflow +``` + +This creates the `output/workflow/` directory and exports the workflow +specified there. Any other `n8n` CLI command works similarly. + +### Creating snapshots + +For snapshot, a separate helper command has been created: + +``` +COMMAND="snapshot SNAPSHOT_ID" dc up --exit-code-from n8n +``` + +You can use multiple, comma-separated snapshot ids like so: + +``` +COMMAND="snapshot 251,252" dc up --exit-code-from n8n +``` diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..673840c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +services: + n8n: + build: + context: . + dockerfile: Dockerfile + env_file: ".env" + volumes: + - ../n8n:/n8n + - ./:/test-workflows + - ./output:/output + - ./docker-data/dot-n8n:/home/node/.n8n + ports: + - 5678:5678 + depends_on: + - pgvector + command: ${COMMAND:-test} + pgvector: + image: pgvector/pgvector:pg16 + volumes: + - ./docker-data/pgvector:/var/lib/postgresql/data + environment: + - POSTGRES_PASSWORD=password + - POSTGRES_USER=pgvector + - POSTGRES_DB=pgvector diff --git a/dot-env-example b/dot-env-example new file mode 100644 index 0000000..27e10b0 --- /dev/null +++ b/dot-env-example @@ -0,0 +1,10 @@ +ENCRYPTION_KEY=test-workflow-encryption-key + +## Set the logging level to 'debug' +#N8N_LOG_LEVEL=debug +# +## Set log output to both console and a log file +#N8N_LOG_OUTPUT=console,file +# +## Set a save location for the log file +#N8N_LOG_FILE_LOCATION=/output/n8n.log diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..25a8cf2 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,50 @@ +#!/bin/sh +set -e +mkdir ~/.n8n 2>/dev/null || true +echo '{ "encryptionKey": "'$ENCRYPTION_KEY'" }' > ~/.n8n/config + +cd /n8n + +export DOCKER_BUILD=true + +echo installing dependencies +#rm -rf node_modules +rm -rf **/node_modules **/dist **/.turbo +echo | pnpm clean || echo "skipping clean" +# doing the echo to make the command skip asking questions... +echo | pnpm install + +echo building n8n +pnpm build + +# Follows the set-up steps from Notion. +echo preparing test data +cp assets/* /tmp +cp node_modules/pdf-parse/test/data/04-valid.pdf /tmp +cp node_modules/pdf-parse/test/data/05-versions-space.pdf /tmp + +packages/cli/bin/n8n import:workflow --separate --input=/test-workflows/workflows +packages/cli/bin/n8n import:credentials --input=/test-workflows/credentials.json + +# Check the command argument +case "$1" in + "snapshot") + echo "Creating snapshots" + mkdir -p /output/snapshots + if [ -z "$2" ]; then + echo "No IDs specified. Using default ID 252." + SNAPSHOT_IDS_ARG="" + else + SNAPSHOT_IDS_ARG="--ids=$2" + fi + packages/cli/bin/n8n executeBatch --shallow --retries=0 --snapshot=/output/snapshots --debug $SNAPSHOT_IDS_ARGz + ;; + "dev") + echo "Starting development server" + pnpm run dev + ;; + "test"|*) + echo "Running tests" + packages/cli/bin/n8n executeBatch --concurrency=16 --shortOutput --debug --compare=../test-workflows/snapshots --output=/output/test-results.json --shallow --skipList=../test-workflows/skipList.txt + ;; +esac diff --git a/skipList.txt b/skipList.txt index ca163ee..5ba7c2f 100644 --- a/skipList.txt +++ b/skipList.txt @@ -1 +1 @@ -1,4,5,10,19,20,21,22,26,27,28,29,30,31,33,34,38,39,40,41,42,43,45,46,47,49,50,51,54,56,57,59,64,65,66,68,69,72,73,74,75,76,77,78,79,80,82,85,89,92,94,102,106,109,110,112,113,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,134,133,135,136,137,138,139,141,142,144,145,146,147,148,149,151,157,158,159,160,163,164,165,167,168,169,170,171,173,176,179,180,183,184,185,186,187,188,189,190,191,192,193,196,197,198,199,200,201,204,206,207,208,214,215,217,218,219,220,221,222,224,225,226,227,252 +1,4,5,10,19,20,21,22,26,27,28,29,30,31,33,34,38,39,40,41,42,43,45,46,47,49,50,51,54,56,57,59,64,65,66,68,69,72,73,74,75,76,77,78,79,80,82,85,89,92,94,102,106,109,110,112,113,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,134,133,135,136,137,138,139,141,142,144,145,146,147,148,149,151,157,158,159,160,163,164,165,167,168,169,170,171,173,176,179,180,183,184,185,186,187,188,189,190,191,192,193,196,197,198,199,200,201,204,206,207,208,214,215,217,218,219,220,221,222,224,225,226,227