In this article, I will explain how to build a CI/CD Testing pipeline using GitHub actions. The work on this project was developed together with Elias Shourosh.
The technological stack used to implement the solution is:
Programing language: Python
Testing Framework: pytest
Reporting Framework: Allure
What is Github Actions?
according to this article:
GitHub Actions is an API for cause and effect on GitHub: orchestrate any workflow, based on any event, while GitHub manages the execution, provides rich feedback, and secures every step along the way. With GitHub Actions, workflows and steps are just code in a repository, so you can create, share, reuse, and fork your software development practices.
GitHub actions is free and support public repositories. the article will be demonstrated using my public repository which contains a suite of E2E tests written in python.
Implementing the Solution
We need to create a ".github" folder into the root of our project, inside it create a workflow folder. Inside it, we create our workflows which are YAML files.
This is the workflow content:
We are running the workflow on every push or PR to the main branch.
It runs the build on an Ubuntu instance provided by GitHub, here is the specification for Github hosted runners. Of course, there is also an option of creating custom runners. this workflow is pretty simple so I used a hosted runner.
now a series of workflow steps are executed in order:
- Checking out the latest code with the following action:
- Deploying a disposable selenium grid using Selenoid is done in order to simplify the run of the Selenium driver (ChromeDriver) at the runner, the grid terminates when the run is over. this is done with the following action:
- Installing python with the following action:
- Installing the project dependencies using pip using a bash command:
Installing a Pytest plugin that annotates test failures in GitHub actions by the following bash command:
- Running our test suite also setting the allure result directory and that run should happen on the grid and not locally:
- After the run is finished we are generating the allure report with the following action:
- We deploy the report to the project Github pages with the following action:
The result of the run is displayed in the PR status as a check, we can determine if this check.
We can determine in the project settings if the check is mandatory for the push.
The result history of the run can be viewed in the action tab.
Allure reports can be found at the Github pages of the project:
In this article, we reviewed the creation of a CI/CD automation pipeline using GitHub actions python and pytest.
Further reading on GitHub actions features can be found in this link.