Sometimes, there are limitations which prevent your deployment flow from working properly. One of these limitations we were facing sometime, was the build and release process.

Usually, we store our code on a GitHub repository, then setup a webhook on it. So each time we push a new commit into the release branch, GitHub will trigger a webhook call to a script our server, which pulls the latest commit, builds the application, and releases the build.

It was a nice deployment flow, everything including pulling, testing, building, releasing,… worked automatically. However, after months, we’ve noticed a few issues with that:

  • When our server receives a webhook call, it has to test and build the projects. As the project continues growing bigger, the build process becomes slower. Everytime it builds, our server’s resources (CPU, RAM, …) spikes up, affects performances of other running applications.
  • It’s hard to rollback to different deployments.

After discovering GitHub workflows, we’ve found a way to improve our deployment process, with many GitHub Actions. And today we’d like to share it with you: We’ve created a GitHub worklow to build and deploy our application into a Git branch.

Our workflow result

With this worklow, we automate all the testing and building steps, then store the ready-to-run build into another branch. Our server just needs to pull the latest build from the deployment branch, and release it. And sometime, if we want to switch between versions, simply switch between commits. We can also trace the build files change back to the commit which made it.

Also, thanks to the actions/cache@v2 action, we could also reduce the building time by caching the dependencies. It allows us to re-use them for future builds.

Here is the example repository using this workflow: https://github.com/ActionsHackathon21/deploy-to-git-branch

Bonus: You can also use it to deploy to Github Pages, by selecting the destination branch as the Github Pages’s branch.