Using GitHub Actions To Add Continuous Integration (CI) To A Project (GitHub / Python)

A GitHub Actions job failure email

In this blog post I will be discussing Continuous Integration (CI) with GitHub Actions.

Readers of previous blog entries may remember that I’ve tackled Continuous Integration (CI) with GitLab previously (see: ) and that last autumn (2021) I got into more testing (see: ). 

Thankfully both have helped as the current module of my degree apprenticeship is around Software Engineering and Agile, with the assignment focusing on web development via Python (Django, FastAPI, Flask etc). I’m using Flask, and as the coding will be assessed I really wanted to make sure that it didn’t break as I created / updated it, so I’ve put in some unit tests.The coding for my assignment (eventually) has to be public, so I’m hosting it on public GitHub ( ), and as it’s on GitHub I decided to add some CI in case I forget to run the tests locally before pushing a branch or a commit to main.

Unit Tests

My project contains a directory called “tests” with various Unit Tests inside. As mentioned above, when I make changes, I run the Unit Tests to a) make sure nothing has broken and b) make sure that the functions work as expected (e.g. entering a serial number records the correct data). On my local machine I can run a command (flask test) to see the tests run and the outputs.

  • A Unit Test file with some assertions
  • Python Unit Tests running

GitHub Actions

When pushing to my GitHub Repo (main or a branch) I have a GitHub Actions file (github-actions.yml) written in YAML which asks GitHub to run the same Unit Tests. This is helpful in case I forget to run the tests when making a change. The GitHub Action file resides within a directory called “workflows” within the “.github” directory at the root of my project (e.g. /PROJECT FOLDER/.github/workflows/github-actions.yml).

Screenshot showing directory layout of project
Project Directory Layout

The GitHub Actions file is made up of a name, a trigger and then the actions to carry out. In my case this is “Flask App Tests”, a “push” and then a build of Ubuntu with Python 3.9, an install of my projects dependencies (via pip requirements.txt) and finally the Unit Tests running.

GitHub Actions YAML file
GitHub Actions YAML file

GitHub checks the .github/worklows directory and automatically creates actions from the plans it finds, adding them to the repository under the actions tab as a workflow. If the action runs and has a failure (e.g. due to a Unit Test failing) then GitHub Actions emails to say that the build has failed. 

  • GitHub Actions Workflow screen
  • A GitHub Actions job failure email

One thought on “Using GitHub Actions To Add Continuous Integration (CI) To A Project (GitHub / Python)

Comments are closed.