CI/CD with Github Actions

Published on Oct 17, 2020

The way I deploy code to production is pretty archaic. I store my build in the Git repository (yikes, but at least I don't commit my node_modules folder), log in to my web server using a secure shell (ssh), git pull the latest changes from the master branch, restart the express server, and delete the local cache and the Cloudflare cache. It works, but I sometimes run into problems—like forgetting to install new yarn packages, for example—and the server crashes. I can do better with a proper Continuous Integration/Continuous Delivery process.

It's not the first time I look up CI/CD tools to improve my workflow, but I've always found things like Jenkins or Travis CI off-putting: you need to install it, sometimes rent an entire web server, and learn how to set up a pipeline. I did some Jenkins back in college, but I still found it to be too much trouble for my simple use case.

It's only till recently I stumbled upon Github Actions, while making my own JAMStack framework to imitate how Netlify or Vercel implement CI/CD, and I found it a breeze to work with.

Most use cases are already handled by third-party plugins, and there is nothing to pay or install to get started. In less than an hour, I had a pipeline ready to build my static website written in Preact and NodeJS, cache the node_modules folder from one build to another, and store the pre-rendered assets.

For private repositories, the first 2000 Github Actions minutes of each month are free, and then you have to pay $0.008 per minute. In my case, it only takes two minutes to install and build the first time with about 1000 blog articles, and less than a minute to rebuild: even if I were to update my website everyday, I would never have to pay anything. For public repositories, it's entirely free. You can also self-host a Github Actions server to handle more complex use cases, so in that case you'd only pay a web hosting bill.

I'm curious to learn more about Github Actions, but the next concrete step regarding CI/CD in my projects is to set up a webhook request/listener to trigger a git pull, handle caches, and restart the web server.