You can use github post commit hooks to send an HTTP payload to a server after every commit. The payload will contain data about the commit that you can then use to trigger arbitrary actions (e.g. run scripts) on the server.
I’ve used a simple go library webhook to do this. To get it up and running I did the following:
go get github.com/adnanh/webhook
- Configure a post-commit webhook on github by:
- Going to the repository settings then «Webhooks and services»
- Clicking «Add webook»
SERVER-IPis the ip address of the server and
HOOK-IDis the name of a hook I will use in the next step
- Enter a «password» in the
secretfield. Will be used later
- Create a
hooks.jsonfile with the contents of this example. In the example
HOOK-IDis given by the
"id"field in the only element of the JSON array.
- Change the
execute-commandto the script I want to run and
command-working-directoryto where I want ro run the script (also change the
secretto what I chose in step 2)
$GOPATH/bin/webhook -hooks hooks.json -verboseto start the server (assumes
$GOPATHis set properly)
That’s it! Now, every time we push a commit to master the script runs locally on our machine.
Note that if we kill the process running webhook the hooks won’t work anymore. I
start the server on a remote machine using
&. The actual command I
nohup $GOPATH/bin/webhook -hooks hooks.json -verbose > webhook.out 2> webhook.err < /dev/null &
See the example
hook.json file here
Jupyter notebooks in gists
Here’s what I do to put a notebook in a gist:
- Go here https://gist.github.com
- Create a new public gist
- Name the file
my_notebook.ipynband write _something_ in it.
- Once the gist has been created and you are viewing it click the url and copy the big long string at the end. It could look like
- Clone the gist as a repo to your computer using
git clone firstname.lastname@example.org:BIGLONGSTRING.git notebook_gistwhere
BIGLONGSTRINGis the thing from step 4 and
notebook_gistis the name of the folder on your comptuer
- Copy your actual notebook into
notebook_gistfolder, then add, commit, push like normal
- After pushing go to nbviewer and paste
BIGLONGSTRINGinto the seach box on their site. This should load up the notebook from your gist and you’re done!
To update the notebook, simply put a new version of it into that
notebook_gist repo, commit, and push. The changes should go live on nbviewer.
If you aren’t seeing an updated version of the notebook after pushing to the gist repo, you might need to visit the url in private mode or reset the browser cache.
Checking out pull requests
This gist explains how to add to the
.git/config file inside a git repo so you can check out pull requests from the remote as if they were branches on the remote.
The tl;dr version is add the following to the file
.git/config within your repo:
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
origin is the name of the remote.
Then you can do
git fetch origin and
git checkout pr/XX where
XX is the pull request number.