Introduction to Self-Updating Programs and GitHub Actions
Now, we'll prepare to make multi-git auto update itself whenever it runs.
We'll cover the following
First, we will discuss the self-update process and then get to know GithubActions, which is a CI/CD pipeline built into Github that we will use to help multi-git become self-updateable.
Overview
Auto-update is more than just a convenience. Some programs perform critical functions and using an out of date version can cause significant damage. At a previous company, we had a CLI program responsible for managing secrets in the AWS parameter store. We discovered the hard way several limitations of AWS parameter store such as values are limited to 4KB and history is limited to one-hundred revisions. When we had to store secrets larger than 4KB, we updated our code to be able to read large secrets in chunks of 4KB. We also updated our CLI to split large secrets into multiple 4KB chunks with a certain naming convention. Unfortunately, it was challenging to get people to update their CLI. For a while we suffered several crises as people used incompatible versions of our code and CLI to read and write secrets from the parameter store.
What if your program could update itself to the latest version automatically? That could have solved a LOT of headaches for us.
Let’s see how it can be done for Go programs, dive into GitHub Actions, and utilize a third party library called [go-github-selfupdate] to accomplish this task and make multi-git auto-updateable.
Self-updating Go programs
The basic idea is simple. First, we need a versioning scheme, so a program can tell its own version. Then, we need to prepare a downloadable release of the program for newer versions. When the program starts, it checks its own version against the latest version. If the latest version is newer, the program downloads the latest version and installs it.
For multi-git, I chose to use git tags as a versioning scheme, Github Actions as a simple CI/CD to build new versions and GitHub releases to store downloadable versions of multi-git.
This is a GitHub-centric workflow, but you can implement a similar approach using a different set of tools and services. For example, you can embed the version in the filename, use a version file in the code, use any CI/CD solution, and download the latest solution from some cloud storage like AWS S3.
Introduction to GitHub Actions
Github Actions is a workflow system that lets you run various tasks and build CI/CD solutions on Github. It is similar to projects like TravisCI and CircleCI. Although, it is still relatively new and somewhat rough around the edges, it has tight integration with GitHub and a growing community of people and organizations that publish actions to perform any number of odd jobs.
GitHub actions revolves around several core concepts:
- Workflows
- Runners
- Events
- Jobs
- Steps
- Actions
The relationship between these concepts is hierarchical. Workflows consist of a set of jobs that are composed of a set of steps where each step contains commands and actions. There is much more to it with environments and secrets, but it’s out of scope. The bottom line is that you can construct full-fledged CI/CD pipelines using these concepts, enjoy lots of existing actions, and build your own when necessary.
In the next lesson, we will dive in and create a couple of workflows for multi-git.
Get hands-on with 1200+ tech skills courses.