Hi, it’s me, blogging after a long time.
I was lazy to setup the local environment for updating anything on this site for all these days.
Well, those days are gone. I just finished setting up a simple auto-deployment for this website.
So here will be my thoughts but more faster.
The real pain for starting/editing blog posts is that I have to setup a local development environment. Bring up vagrant, install all prereqs and clone the source code and theme and ….. You get it, it needs work and needs a computer all the time, even just to do simple things like adding a quote here.
I was wanting to give Github Actions a try from when it was in beta. So I gave it a try during this process.
When I started looking at it, I came across it’s marketplace and got very excited. Since I was using hexo blogging framework for the site, my natural intution was to try any of these actions in the marketplace. I went with hexo-deploy-with-cname-enabled.
That was a disastrous decision. After commiting the workflow yaml, the action ran and force pushed to master.
The action basically took all the source code and generated a hexo site (probably by running
hexo generate) and force pushed to master.
I usually have the source files (markdown blog posts and other pages) in the root and have the generated hexo site in
/docs folder. So, now all the markdown files are gone. Only the hexo generated html files are there. Boom! thankfully, it the data is still there, but just a different format.
At this point, I started searching for some local backup, which I didn’t find at first. PANIC!
After a while, I found an old copy probably missing the last 3 blog posts I posted. LESS PANIC!
The hard lesson here is making a simple backup before being adventurous. Example, I could have been chill throughout this entire situation, if I had did a git clone before trying out the action or just used two mouse clicks to create a backup branch from Github.
Always backup and ask the question if there is a backup somewhere
The recovery process involved converting html to markdown back again and stitching it together with the old backup I had. The site was down for a while (shame on me, can’t keep a static site running 100% of time). It was running an older version for sometime and then now it is fully updated.
The entire recovery process took me working on the terminal for a quite while with html->markdown converters and copy-paste.
But wait, recovery does not stop here. True recovery is recovering from the root cause of the problem.
The root cause of the problem is that master branch was not force-push protected. I usually do this, but this got missed somehow. (What to do. We humans, right?)
I changed in Github Settings to restrict force push for master.
And I took a backup just in case :D
I like hexo. You can learn why here. But in order to get instant flow of editing and publishing, I want an environment like Wordpress or Medium. Sophistication is setting high expectations all the time. So I want to keep using Hexo, but publish Medium or Wordpress style.
First I was thinking of writing a fresh blogging platform that will try to address this. But I can’t draw lines on what I should be building. So I wanted to see if there is a way to publish content from something more accessible (like a markdown editor on the web). How about Github’s markdown editor. I am pretty familiar with it and like it.
In the spirit of exploring Github Actions again, I started writing yaml configurations for it that will build and generate the hexo site. The whole disaster I was speaking about before gave me the idea that you could push some code easily from your github action.
Here is my YAML config.
(messy script, but gets the job done. So going to leave it like that)
It is bunch of git commands + this github action
ad-m/github-push-action@master which helps us to push changes with Github token, rather than a private key.
If you wonder how the job looks like for deployment,
There are more things behind the story, which would have been fun if I had blogged it like a live journal. But I didn’t have that setup before. But now I have it.
All I have to do is, open up the github repository and commit the changes with the commit message starting with
[deploy] and it will automatically deploy the site.
The next level of automation would be to deploy a staging environment for each pull requests and see a live version of the site before merging the PR. But for now, I am just happy with this setup.
Oh and Github gives this cool badge,
~ ~ ~
NOTE: This is the first blog post that was auto deployed - https://github.com/scriptnull/vishnubharathi.codes/pull/9