Skip to content

Validate n8n Workflows #38

Validate n8n Workflows

Validate n8n Workflows #38

name: Validate n8n Workflows
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch: # Allow manual triggering
jobs:
validate-workflows:
name: Validate n8n Workflows
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Run workflow validation
id: validate
run: |
# Run the validator on all JSON files in the repository
# This will fail if any workflow is invalid
echo "Validating all n8n workflows..."
if ! python tools/validate_workflows.py -v; then
echo "::error::One or more workflow validations failed"
exit 1
fi
echo "All workflows are valid!"
- name: Comment on PR with validation results
if: github.event_name == 'pull_request' && steps.validate.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
const { execSync } = require('child_process');
// Get the list of workflow files that were validated
const workflowFiles = execSync('find . -type f -name "*.json" -not -path "*/node_modules/*" -not -path "*/.git/*"')
.toString()
.split('\n')
.filter(Boolean);
// Create a comment
const comment = `✅ All ${workflowFiles.length} n8n workflow files are valid!`;
// Add a comment to the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('n8n workflow')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment,
});
}