Using Github Actions for Automated Testing and Deployment

Page content

Background

The source code of tracfee.com is hosted on Github Private.

At a High level, Tracfee’s Architecture involves,

So far, API testing has been automated and we were looking at ways to automate deployment of both UI and API. Steps required to deploy API are less since we are using Docker to run it on VM. However, in case of Netlify, it is required to build and then upload the output folder on Netlify.

Accordingly, it was decided to explore Github actions to automate deployment.

Using Github actions

As per Github,

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

GitHub actions work by provisioning Virtual machine to run an Event based workflow. It provides option to provision Linux/MacOS/Windows based Virtual machines. Steps in Workflow will have to be configured in YAML file. Trigger for Workflow can be (but not limited to) wide variety of events like on Push or commit on branch and so on.

Post trigger, set of action(s) can be configured like,

  • Checkout the branch
  • Setup environment (Install Node.JS)
  • Perform build
  • Deployment

Github has Marketplace which has many pre-built actions available. My requirement was to,

Above workflow needs to be maintained in .github\workflows folder in the repository.

build.yml for tracfee.com looks like,

Refer Gist here.

Testing the Build Workflow

After configuring the workflow steps, next question is to check whether it is possible to test it locally? Luckily, there is tool available to do this. Enter Act , which is a tool to Run your GitHub Actions locally . Local testing is useful for Faster feedback. In Nutshell, Act uses local docker setup to provision container and then runs workflow steps in it. Give it a try !!

As a next step, Plan is to automate deployment of API on Oracle Cloud using OCI CLI interface.

Useful References,

Happy Coding !!