Controlled Jekyll Republishing with git Commit Messages
Nov 2, 2015
It’s only fitting to start this little scrapbook with a short snippet for Jekyll. I’m a typical engineer in that I am willing to spend five hours setting something up that will save me 20 seconds about every other month, so I was tempted by the
git post-receive hook deployment method from the Jekyll documentation.
Such a complete automatism doesn’t fit my usual workflow, however. I often push unfinished/untested code, mostly for the benefit of a remote backup.And while Jekyll has drafts, that mechanism does not help with changes to the rest of the codebase.
What I wanted was a method to control which pushes lead to redeployments. I’ve settled on the following post-receive hook, which only redeploys if the last commit message contains the string
'p! ' (without quotes). This method is adaptable to perform any conditional post-push action based on commit messages or other information in the
#!/home/<user>/.rvm/bin/rvm-shell # # Republish Jekyll when last commit message # contains p! LOG=`git log -1 --pretty=%B HEAD` if [[ $LOG != *"p! "* ]] then echo "We're keeping this version private." exit; fi echo "Publishing... " GIT_REPO=$HOME/myrepo.git TMP_GIT_CLONE=$HOME/tmp/myrepo PUBLIC_WWW=/var/www/myrepo git clone $GIT_REPO $TMP_GIT_CLONE jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW rm -Rf $TMP_GIT_CLONE echo "Done. Time to die. How fitting for a damn shell script." exit
I have a deep hatred for bash scripting and therefore not invested much time. Consider:
Redeploys only happen when the last commit message contains
'p! '. Any intermediate commits that where not pushed are ignored.
'p! ' trigger can occure anywhere in the commit message, not just at the beginning.
A better method would be to use branches for intermediate code. But we’re publishing a blog here and avoiding work clearly outranks orthodoxy.
Mark Felt-Tipped Feb 25, 2018
Building Tensorflow 1.5.0 on MacOS with CUDA GPU Jan 21, 2018
Contact Jan 1, 2018
Add iterm2 marks to long-running outputs Jun 1, 2017
Trump Documents Atbash Decoded May 23, 2017
Polkit? WTF is this again? Actually... May 23, 2017
lighthouse/chromium/alpine/docker image Mar 9, 2017
Don't know how to build task '#
link_directory must be a directory Jan 2, 2017
Verifying NGINX configurations in ansible May 23, 2016
ANSIBLE-MODULE-PATH and more Apr 29, 2016
'credentials-gcloud.sh' is not a git command Apr 23, 2016
I rule (.svg) Mar 8, 2016
React and Relay error scrapbook Mar 3, 2016
Get a Grid, at least vertically Feb 17, 2016