hook-runner

hook-runner is a small server written in node which runs your shell scripts via webhooks…

npm install hook-runner
8 downloads in the last month

hook-runner

hook-runner is a small server written in nodejs, which executes shell scripts after pushing your project to your GitHub repository (WebHooks). I use it to deploy web applications automatically.

Installation and Usage

You can install hook with npm:

npm install hook-runner

Then, create a js file for running your server, for example server.js:

require('hook-runner')
.addWorkspace(__dirname)
.listen(3000);

You can add more than one Workspace if you want to. hook-runner will browse these directories recursively for *.hook files, which are built like:

{
    "branches": {
        "master": [
            "git pull",
            "./deploy/update_production.sh"
        ],
        "stage": [
            "git pull",
            "./deploy/update_stage.sh"
        ]
    }
}

As soon as hook-runner detects these files, it will add an ID for each of it:

{
    "id": "6afedcb2c2e9963c93f99abc95e66066fd1387f7434c17b407aefeb5fa0045d117b6399…",
    "branches": {
        "master": [
            "git pull",
            "./deploy/update_production.sh"
        ],
        "stage": [
            "git pull",
            "./deploy/update_stage.sh"
        ]
    }
}

Now you know the ID, so you can add the WebHook URL: http://host:3000/6afedcb2…. As soon as you push master to GitHub, all the scripts listed in array master are executed in sequence.

Reload Workspaces

You can reload all workspaces and *.hook-files by opening http://host:3000/refresh in a browser.

Send Mails

hook-runner is able to send emails to all affected users (repo owner and comitter) when it did anything. For more information about the second object read the nodemailer readme.

require('hook-runner')
.addWorkspace(__dirname)
.sendMails({
    transport: 'SMTP',
    from: 'hook-runner <hooks@example.com>',
    to: ['gets-everything@example.com'],
    replyTo: 'support@example.com'
}, {
    service: "Gmail",
    auth: {
        user: "gmail.user@gmail.com",
        pass: "userpass"
    }
})
.listen(3000);

ignore Errors

You can ignore a script's error by prepending [e]:

{ "id": "6afedcb2c2e9963c93f99abc95e66066fd1387f7434c17b407aefeb5fa0045d117b6399…", "branches": { "master": [ "git pull", "[e] ./deploy/produces_errors.sh" ] } }

npm loves you