Running n8n Workflows Hosted on GitHub

You can share & run n8n workflows directly from GitHub, allowing everyone to have a consistent base of code & distributed development. To do this...

Most of the time, n8n runs workflows stored on the system itself, and you build the workflow in the n8n interface and run it right there.

But there are ways to run workflows stored in different locations, essentially using the workflows like prewritten functions or libraries.

This article will show you how to create workflows that you can then put on GitHub and then run in n8n remotely.

Background Information

n8n has a special node called Execute Workflow. It is designed to reference another workflow, send information to it, and return the results.

The Execute Workflow Node

Most of the time, it is used to reference another workflow stored in the n8n database, referenced by a workflow ID number.

Execute Workflow Parameter Settings

When connected in a workflow, the data output from the previous node is passed to the workflow referenced in the Execute Workflow node. It is then processed by that workflow, returning the workflow results to the Execute Workflow node.

Execute Workflow (Math Router) in an n8n Workflow

Now, let's learn how to use the Execute Workflow node to run a workflow stored on GitHub.

Step 1 - Create the Workflow

The first thing is to create a workflow that you want to store on GitHub. This assumes that you have a public GitHub repository available to everyone.

You can build whatever workflow you want but keep a few things in mind as you create the workflow:

  1. The workflow should generate an output, and this output will be returned to the workflow that called this workflow.
  2. If the workflow branches and has multiple "ending" nodes, the last node that executes will be the one to return the data. It is recommended that only one node end the workflow.
  3. Expect data to be passed into the workflow and interact with that data as required.
The n8n Workflow Created For Hosting on GitHub.

The sample workflow that I have created here can be found on my GitHub repository here:

n8n-pi/Math_Router.json at master · TephlonDude/n8n-pi
Tools and Images to Build a Raspberry Pi n8n server - n8n-pi/Math_Router.json at master · TephlonDude/n8n-pi

Step 2 - Exporting the Workflow

Once you have the workflow created, you need to export it from the Editor UI to be uploaded to GitHub.

  1. Click on the Workflow icon in the UI menu.
  2. Click on the Download option
Steps to Download an n8n Workflow

This will now download a JSON file to your regular download folder. This file contains your entire workflow.

Step 3 - Upload Workflow to GitHub

We now have to get the file downloaded from n8n to GitHub. These are the steps:

  1. Browse to GitHub and log into your GitHub account.
  2. Pick a public repository where you will store the file.
  3. Browse to the location in the repository where you would like to store the file.
  4. Click on the Add file button and then on the Upload files option2022-01-13-21_32_47-n8n-pi_workflows-at-master---TephlonDude_n8n-pi
  5. Drag the file you downloaded from n8n to the GitHub page and then click on the Commit changes button to complete the upload

Your workflow file will now be available on GitHub.

Step 4 - Using the Workflow in n8n

Now that the workflow is available in GitHub, we can now configure n8n to run the workflow remotely.

The workflow that is stored on GitHub takes two number and one string inputs:

  • number1 - first number input
  • number2 - second number input
  • function - function that is to be executed on the two numbers. Accepts the following options:
    • add
    • subtract
    • multiply
    • divide

The workflow then performs the function on the two numbers and returns the result.

You can set this up by following these steps:

  1. Start a new workflow in n8n
  2. Connect a Set node to the Start node
  3. In the Set node parameters, create two number values and one string value like this:
    2022-01-13-21_43_55-n8n------Math-Router
  4. Connect an Execute Workflow node to the Set node
  5. In the Execute Workflow node, change the Source to URL and keep the node open
  6. Go to your GitHub page and click on the file that you uploaded in the previous step
  7. Find the Raw button. Right-click on the button and click on the Copy link address option
  8. Return to the open Execute Workflow dialogue and paste the link you just copied into the Workflow URL field. Your properties should now look similar to this:
    2022-01-13-21_54_16-n8n------Math-Router
    If you don't have a GitHub file to run, you can run the one from my repository: https://raw.githubusercontent.com/TephlonDude/n8n-pi/master/workflows/Math_Router.json
  9. Close the node properties

If you don't want to be bothered manually creating the workflow, you can copy the code below and paste it into the n8n Editor UI:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "number": [
            {
              "name": "number1",
              "value": 23
            },
            {
              "name": "number2",
              "value": 43
            }
          ],
          "string": [
            {
              "name": "function",
              "value": "divide"
            }
          ]
        },
        "options": {}
      },
      "name": "Testing",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        460,
        300
      ],
      "notesInFlow": true,
      "notes": "This node is for testing only. Please disable the node before going live."
    },
    {
      "parameters": {
        "source": "url",
        "workflowUrl": "https://raw.githubusercontent.com/TephlonDude/n8n-pi/master/workflows/Math_Router.json"
      },
      "name": "Math Router",
      "type": "n8n-nodes-base.executeWorkflow",
      "typeVersion": 1,
      "position": [
        680,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Testing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Testing": {
      "main": [
        [
          {
            "node": "Math Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Workflow Code

Step 5 - Run the Workflow

We can now run the workflow. Press the Execute Workflow button at the bottom of the Editor UI. If you set up the workflow correctly and ran my GitHub hosted workflow, you should get the following result in the Execute Workflow node:

[
  {
    "result": 0.5348837209302325
  }
]

The result 0.5348837209302325 is what you get when you divide (function) 23 (number1) by 43 (number2).

You can change the values of number1, number2 and function and see what you get back as a result!

What Next?

This opens up all kinds of different possibilities for people. You can host workflows that can be run by people anywhere in the world by simply sharing a website URL or centrally manage your business's workflows without having to individually change all of your n8n installations.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.