Quick overview
This workflow triggers on GitHub push events, fetches the changed n8n workflow JSON from the repository, cleans deployment-specific metadata, and then uses the n8n REST API to update an existing workflow or create a new one in a production n8n instance.
How it works
- Triggers when a push event is received from GitHub.
- Validates that the push targets the main branch, is not a branch deletion, and includes at least one added or modified file.
- Requests the changed workflow JSON file from the GitHub Contents API.
- Extracts the workflow name from the fetched JSON and searches the production n8n instance for a workflow with the same name via the n8n REST API.
- If a matching workflow exists, retrieves its details, strips IDs and other metadata from the GitHub JSON, and updates the production workflow via the n8n REST API.
- If no matching workflow exists, strips IDs and other metadata from the GitHub JSON and creates a new workflow in production via the n8n REST API.
Setup
- Create and add GitHub OAuth2 credentials in n8n with access to the repository you want to deploy from.
- Create and add n8n API credentials for your production instance (API key or compatible credential) with permission to read and write workflows.
- Update the repository owner/name and the production n8n base URL in the workflow’s configuration (and ensure the trigger is set to the branch you deploy from, such as main).
- Ensure your GitHub repo stores exported n8n workflows as JSON files and that pushes include the workflow file as an added or modified change.