Skip to content

Conversation

@roeiba
Copy link

@roeiba roeiba commented May 20, 2025

Add CI/CD Pipeline for n8n Workflow Validation and Visualization

This PR introduces a comprehensive CI/CD pipeline for validating and visualizing n8n workflows. The implementation includes a Python package for workflow validation and visualization, along with GitHub Actions workflows for automated testing and reporting.

🚀 Features Added

1. n8n Workflow Validator (n8n_utils.ci.validator)

  • Validates n8n workflow JSON files against a schema
  • Checks for required fields and proper structure
  • Can be used both locally and in CI pipelines

2. Workflow Visualizer (n8n_utils.visualization.visualizer)

  • Generates visual representations of n8n workflows
  • Colors nodes by type for better readability
  • Supports saving visualizations as image files

3. GitHub Actions Workflow (.github/workflows/validate-workflows.yml)

  • Triggers on pushes and pull requests to main/master branches
  • Runs workflow validation on all JSON files in the repository
  • Creates visualizations for valid workflows
  • Uploads visualizations as build artifacts
  • Posts a comment on PRs with validation results

4. CI Setup Script (setup-ci.sh)

  • Sets up a Python virtual environment
  • Installs all required dependencies
  • Provides helpful commands for local development
  • Can be used in CI environments

🛠 How It Works

On every push or PR to main/master branches:

  1. The workflow checks out the code
  2. Sets up Python 3.10
  3. Installs the required dependencies
  4. Validates all JSON files in the repository
  5. Generates visualizations for valid workflows
  6. Uploads visualizations as build artifacts

For Pull Requests:

  • The workflow posts a comment with validation results
  • Shows how many workflows were validated
  • Indicates if visualizations were generated
  • Provides a link to download the visualizations

🚦 Testing

Local Testing

  1. Run the setup script:
    ./setup-ci.sh
  2. Activate the virtual environment:
    source venv/bin/activate
  3. Validate workflows:
    cd lib && n8n-validate .. && cd ..
  4. Visualize a workflow:
    cd lib && n8n-visualize ../path/to/workflow.json && cd ..

CI Testing

The GitHub Actions workflow will automatically run on push or PR. Check the "Actions" tab in your GitHub repository to see the results.

📦 Package Structure

lib/
├── n8n_utils/           # Main package
│   ├── __init__.py
│   ├── ci/              # CI validation tools
│   ├── visualization/   # Visualization tools
│   └── tests/           # Test files
├── examples/            # Example scripts
├── requirements.txt     # Python dependencies
└── setup.py            # Package configuration

📝 Notes

  • The validator uses a schema to ensure workflow files are properly formatted
  • Visualizations are generated using NetworkX and Matplotlib
  • The CI workflow is configured to run on all pushes and pull requests
  • All dependencies are pinned to specific versions for reproducibility

🔄 Future Improvements

  • Add more validation rules for specific node types
  • Improve visualization styling and layout
  • Add support for more n8n node types in the visualizer
  • Add more comprehensive tests

🔗 Related Issues

  • Closes #123 # Replace with actual issue number if applicable

📋 Checklist

  • Add workflow validation
  • Add workflow visualization
  • Set up GitHub Actions workflow
  • Add local setup script
  • Update documentation
  • Add tests for new functionality

📸 Screenshots

Screenshots of the visualization output can be found in the workflow artifacts.


Let me know if you'd like any adjustments to this PR description or if you have any questions about the implementation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants