Introduction
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.
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f65a89f191a21b2220f_NTrrpJZa7_ho2cCKnXYSpPDmgUUG3G57ocmHtzofpn6zadP4k6dqUgzNI885o10mIGHWsxd5XzEukeI6syJW5x2qmyzb2Bg4Ybj_FA5MLR_Dla3TsaF3noXMkvOQNSYH2H_6gx8t.png)
This is the workflow content:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f66fda8319547fe69e8_f58fRLou2m2FIgaVeca_Ol80XD3nxjmicpppOPjWxgxnQIyimiKv4TFt-P6yV8xobmdd2BUYWc6VD6pHTa1kPDH1bpimC8nQLoa7mW4ouLdlpdfMWVuBeKlqbCcXlhKh3rP2ZXrt.png)
Walkthrough
We are running the workflow on every push or PR to the main branch.
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f66e4802bcef1a6ab0d_X5THuCPiLck4vevs_sACMcFYWBP7AyPoap15FHt1QnTLDQQGHjaQfToOCtj8gCjTxr-tpp-AdG-yNT-Qpl2pnV6ox1NtZ5M4DZ66jAMO3TT_x4BgIQ9aGLo-_GgbPVOuNUWzoaRG.png)
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.
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f6637bb13ee4a1c05fe_khbl-_AP8Mi6eSJkN2_9z6ZPr8HtubEyb_Bvcqp3IsE4R_kR8p-aQVZEKZSVSucr3o7TUm8KLPvwC7W1Gc0CG2kagZgvsVin8A9WKdiTAm72v20r7ZbtUprxgQdri1f70dY9vcuv.png)
now a series of workflow steps are executed in order:
- Checking out the latest code with the following action:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f66642c9b678e0d16d9_c2_WW6B2cZDdlfovtnDJRtMhq2AZuZTIYBfLDJWdxiA7MYzn77pmg0xtTH-N3L9F1VO_VVLPXV0Yf6ygXrUy5EIKh-SmHZWDht9eIA4F1wWKz18--J3_cObngLN2JDpayk4txegt.png)
- 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:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f6708c9c86eaebb2243_VvuzbOyBDqT7k_wOHDmidFnnaUO36biAHVaA5eLSMkHGovj01CYgt9u4kiPV0tgJXwLqqfJItn_LuVXOcVez8tvz9l4WlbsNf9SkmfGHJa-ZQH4FgULsQnevMvX-Y5uXhdfNgVBk.png)
- Installing python with the following action:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f66ed7ef301bde894c0_zp_vuP36x1apGw0u_PoK-m4HK1SVtjc0PY4uRISFDmjF3ncn1BW5R4M_Ak9-EKFgOjxoDGpR46k4J_dM8__I0y1BSmLmSunLYGKb0auF5JdWpZ_-GAm91i1AJrUx0fN3nvy4OpLF.png)
- Installing the project dependencies using pip using a bash command:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f67257aaa5f25cbb13c_CxeJ8g3FBpT-updJUc9lqe4e5ypvmq_clhhs45UY_n6hZFcGB9Z0fghiNRatTDIXVMOR0ifC9-73XK4iCKkk-FulrEh8OJWi4RBFSh2yOPCeqnFebuQ5EDcGPlINfxbeFIJV6G_t.png)
Installing a Pytest plugin that annotates test failures in GitHub actions by the following bash command:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f6738e7adf7042c5ed9_VfYxLAl6bB0QaYFlKjj5Omv-2wM97vpz59Zq_hMkU8j9RJiXAMOdBb-8QcyTFVuaJDywuH7SSIERchJIfqh_mgUmYdiFqX0VDnaa15NPx2Q2jTcuEvU785824mw2BdxLrYKVJCsV.png)
- Running our test suite also setting the allure result directory and that run should happen on the grid and not locally:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f682d869ba6959fa956__347BKUZkug1_j03qcEyo1nlNEJOYnP_sA3pHKmvHP53MrxBoOyqvQEvrGdxbXT2kXGHSrxUHcKm4oyc5Yt7X10x-55l0GLvbqfn4x2SqalutuDCzXmQTramlP37EdI5jfSdr9Jj.png)
- After the run is finished we are generating the allure report with the following action:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f67caa33154013c6b76_rfwdMAJ5sb7zFcvzHLJlfPlvnFpQI7f0f0mBDI7MdZVwXS2-SWNpYV10QrFnHg-fEF5YnmcRDMi03K82kv8WQEct1lywJLkq4qAKHhG_v6Pi-ExPaj2dBVT1ZGClPnrun9M7uTEp.png)
- We deploy the report to the project Github pages with the following action:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f67fda0ca24078fdce5_2bzK__Rh6Du-_9b36cPd3wNNTk-7Vd75Pl_pkDcUxSlrNSnEcyJu22R97_SXNtA5QexWIy60-uXWsQeUr2EEWf1I-qsOTgHppo_rUiZBDhoDv96NhCLOCEWA149uhSPvVYoKzCMC.png)
The result of the run is displayed in the PR status as a check, we can determine if this check.
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f6771aeb574f11258b9_QECwo-MKl1DXQjz43xWdSTottKapCiW6WNFkRqjuqBpqFH2Vd1gQ_GSJari5_0q6iojU7Mks4UDrINSgHOHB9M94N4YrZGOgp52U3NXi0tWLDCgPempimye_frgtTaLI3sWAZA6J.png)
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.
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f684089712fa02650dc_ntlk6tFNf2-pAQesitnln28uvyJWEuNsKiA4AfG_n3nLlAujOrWrYkYB7EufPYIMOG5guVU_gQtiLYqnpckTkIzFWqTTKtchEWPW54iXvmAf7EXJGWmeKo-Jtnxl_UWSe_ojlkNt.png)
Allure reports can be found at the Github pages of the project:
![No alt text provided for this image](https://cdn.prod.website-files.com/5e5a5c35a623e45f7f701878/608a7f6808c9c851cebb22bd_p-CxUnvjWi9sIIKPdJUpRuHLmoXm4ZmSMDGeqfHp_3EE4bZQjAs1_HxqX2yS6YdwoFLxSeBAUJNSmgtE80bWrZHoWNvzr1FSkKsRyiBC_i7O59_6XN1K2SeGKCo8O68iBMDTZ3Mh.png)
In conclusion
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.
Happy testing!