How to use Github actions

Github Actions for Continous Deployments

Github allows users to define a yaml file which defines a workflow to run on certain event.

A common event to run this workflow on is when the code is pushed to a certain branch of a repository.For example when the code is pushed to the main branch we may run workflows to the test and deploy the code. This allows you to set up a Continous Deployment (CD) flow.

In order to use these workflows you must create a ".github" folder in the root of the project directory. Then within this directory create another directory called "workflows". Any file with the extention ".yml" will be processed.

The yaml files are instructions like a docker file on what to run within container compute resource that Github will spin up for you. You can extend from a number of options in the Github actions marketplace. For example you can extend from an action which allows you to send a notification to slack. See the example below. You just need to set a secret in the Github repository for your slack webhook and it will notify you on each push to the main branch.

name: Slack Notification

on:
  push:
    branches:
      - main

jobs:
  slackNotification:
    name: Slack Notification
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Slack Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}

Cost

You get 2000 minutes of actions on the Github free tier. Beyond this point you will need to pay extra.

Alternatives

There are many alternatives to using Github Actions, if you are using Gitlab then they have similar functionality with the CI/CD feature. If you are wanting to use tools within AWS Cloud then you can use CodeBuild and CodePipeline to achieve a similar result.