You can trigger a GitHub Pages (Jekyll) rebuild with a single API call. This is pretty useful for auto-publishing blog posts from a bot like Zapier in conjunction with future: false in your Jekyll config.yml. Just future-date your posts, and they'll go live when that date rolls around. I use a version of this setup for my blog at greghaskins.com.
-
Create a GitHub personal access token and save it somewhere. It needs to have the
repoaccess scope (at least). -
Create a file at the root of your repo (e.g.
.publish) with some dummy content.$ echo ".publish" > .publish
-
Commit it and push.
$ git add .publish $ git commit -m "add .publish file for scripted publishing" ... $ git push -
Get the blob SHA and base64 content for it via the GitHub API
$ curl -H "Authorization: token $YOUR_TOKEN" \ > https://api.github.com/repos/:owner/:repo/contents/.publish { "name": ".publish", "path": ".publish", "sha": "3f949857e8ed4cb106f9744e40b638a7aabf647f", ... "type": "file", "content": "LnB1Ymxpc2gK\n", "encoding": "base64", ... }
In this case it's 3f949857e8ed4cb106f9744e40b638a7aabf647f and LnB1Ymxpc2gK (strip the trailing \n).
And you're all set.
Just "update" the content for that .publish file with the same content as before. This creates a new commit on the GitHub side and triggers a Pages rebuild.
$ curl -H "Authorization: token $YOUR_TOKEN" \
> -H "Content-Type: application/json; charset=UTF-8" \
> -X PUT \
> -d '{"message": "re-publish GitHub Pages",
> "committer": {
> "name": "PublishBot",
> "email": "[email protected]"
> },
> "content": "LnB1Ymxpc2gK",
> "sha": "3f949857e8ed4cb106f9744e40b638a7aabf647f"}' \
> https://api.github.com/repos/:owner/:repo/contents/.publish
{
"content": {
"name": ".publish",
"path": ".publish",
"sha": "3f949857e8ed4cb106f9744e40b638a7aabf647f",
...
},
"commit": {
"sha": "57af635acad5802c0f5a166f431e4ad19db1e80f",
"message": "re-publish GitHub Pages",
...
}
}You'll notice that the SHA before and after is the same. That means you can simply replay this same request any time you want to trigger a rebuild.
Does this method still work?