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: https://geektechstuff.com/2021/04/05/python-unit-test-and-some-ci-via-gitlab-python/ ) and that last autumn (2021) I got into more testing (see: https://geektechstuff.com/2021/10/06/personal-update-django-and-mvc-mtv/ ).
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 ( https://github.com/geektechdude ), 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.
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.
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).
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 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.
One thought on “Using GitHub Actions To Add Continuous Integration (CI) To A Project (GitHub / Python)”
Comments are closed.