summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.sample.json2
-rwxr-xr-xjekyll-hook.js37
-rw-r--r--readme.md12
3 files changed, 40 insertions, 11 deletions
diff --git a/config.sample.json b/config.sample.json
index eba0920..566b329 100644
--- a/config.sample.json
+++ b/config.sample.json
@@ -3,8 +3,10 @@
"temp": "/home/ubuntu/jekyll-hook",
"public_repo": true,
"scripts": {
+ "#default": {
"build": "./scripts/build.sh",
"publish": "./scripts/publish.sh"
+ }
},
"secret": "",
"email": {
diff --git a/jekyll-hook.js b/jekyll-hook.js
index 5f2453a..baf26df 100755
--- a/jekyll-hook.js
+++ b/jekyll-hook.js
@@ -32,18 +32,12 @@ app.use(express.bodyParser({
err.status = 403;
throw err;
}
-
- req.request_verified = true;
}
}));
// Receive webhook post
app.post('/hooks/jekyll/*', function(req, res) {
- // Prevent non verified request from reaching this.
- if (!req.request_verified) {
- return res.status(403).send('The request could not be verified.');
- }
// Close connection
res.send(202);
@@ -87,8 +81,35 @@ app.post('/hooks/jekyll/*', function(req, res) {
/* source */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'code');
/* build */ params.push(config.temp + '/' + data.owner + '/' + data.repo + '/' + data.branch + '/' + 'site');
+ // Script by branch.
+ var build_script = null;
+ try {
+ build_script = config.scripts[data.branch].build;
+ }
+ catch(err) {
+ try {
+ build_script = config.scripts['#default'].build;
+ }
+ catch(err) {
+ throw new Error('No default build script defined.');
+ }
+ }
+
+ var publish_script = null;
+ try {
+ publish_script = config.scripts[data.branch].publish;
+ }
+ catch(err) {
+ try {
+ publish_script = config.scripts['#default'].publish;
+ }
+ catch(err) {
+ throw new Error('No default publish script defined.');
+ }
+ }
+
// Run build script
- run(config.scripts.build, params, function(err) {
+ run(build_script, params, function(err) {
if (err) {
console.log('Failed to build: ' + data.owner + '/' + data.repo);
send('Your website at ' + data.owner + '/' + data.repo + ' failed to build.', 'Error building site', data);
@@ -98,7 +119,7 @@ app.post('/hooks/jekyll/*', function(req, res) {
}
// Run publish script
- run(config.scripts.publish, params, function(err) {
+ run(publish_script, params, function(err) {
if (err) {
console.log('Failed to publish: ' + data.owner + '/' + data.repo);
send('Your website at ' + data.owner + '/' + data.repo + ' failed to publish.', 'Error publishing site', data);
diff --git a/readme.md b/readme.md
index 44d91e9..1759576 100644
--- a/readme.md
+++ b/readme.md
@@ -62,8 +62,12 @@ Configuration attributes:
- `temp` A directory to store code and site files
- `public-repo` Whether the repo is public or private (default is public)
- `scripts`
- - `build` A script to run to build the site
- - `publish` A script to run to publish the site
+ - `[branch-name]` (optional)
+ - `build` The build script to run for a specific branch.
+ - `publish` The publish script to run for a specific branch.
+ - `#default`
+ - `build` The build script to run if no match was found for the branch specified in the webhook.
+ - `publish` The publish script to run if match was found for the branch specified in the webhook.
- `email` Optional. Settings for sending email alerts
- `isActivated` If set to true email will be sent after each trigger
- `user` Sending email account's user name (e.g. `example@gmail.com`)
@@ -81,6 +85,8 @@ they generate a site with Jekyll and publish it to an NGINX web directory.
Set a [Web hook](https://developer.github.com/webhooks/) on your GitHub repository
that points to your jekyll-hook server `http://example.com:8080/hooks/jekyll/:branch`, where `:branch` is the branch you want to publish. Usually this is `gh-pages` or `master` for `*.github.com` / `*.github.io` repositories.
+For every branch you want to build/publish (as defined in the `scripts`) you need to set up a different webhook.
+
## Configure a webserver (nginx)
The default `publish.sh` is setup for nginx and copies `_site` folder to `/usr/share/nginx/html/rep_name`.
@@ -150,4 +156,4 @@ server {
Replace this script with whatever you need for your particular hosting environment.
You probably want to configure your server to only respond POST requests from GitHub's
-public IP addresses, found on the webhooks settings page.
+public IP addresses, found on the webhooks settings page. \ No newline at end of file