How to prepare a CI/CD pipeline with GitHub procedures
Let’s be real, technology moves quickly. The new frameworks, tools and best practices appear to appear every week. It is exciting, but also a bit overwhelming. If you are trying to build projects and charge them while keeping up with everything, you may feel a lot.
This is where the CI/CD can help, and it is short for continuous integration and continuous publishing. It cares about frequent things like testing and publishing, so you can focus on writing actual features. I have personally found GitHub to be a strong option to prepare CI/CD workflows inside the Ribo GitHub.
In this article, I will walk for you by setting up a simple CI/CD pipeline using GitHub procedures. The goal is to reduce manual errors, make our code easier to publish, save some time and stress in this process.
Let’s enter!
Before we start, here are some things that you will want to get or know, just so that you do not stumble in the middle of the road.
Basic requirements
- You have a Github account
- The primary understanding of building Yaml and GitHub
Create a first CI/CD pipeline
You can choose to create your yaml file in VS Code or directly on GitHub. In this guide, we will create it directly on GitHub to keep things simple and easy to follow.
Go to your GitHub warehouse (or open the blade editor) and create a new folder called .github
Inside that, create another folder called workflow, then add a new file called pylinter.yml
You can name your yaml file whatever you want.
Next, we need to select our Yaml file, which is the Linter Workingfree that is checking the DockStrings at the base of our code.
Start your yaml file by giving your pipeline a name and preparing GIT – in other words, it is defined when you want to run the pipeline. In this guide, we will prepare it for operation whenever there is a batch to main
Branch or when the request for withdrawal is opened against it.
name: Python Linting
on:
push:
branches: main
pull_request:
branches: main
After that, we need to tell the pipeline what to do when a payment request or withdrawal occurs. In this case, we want it to review our symbol by preparing Python and installing pylint
Package so that Lining can be turned on our warehouse.
jobs:
lint:
name: Run PyLint
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
After preparing Python and installing pylint
The package, the next step is to determine the composition that Pylint will use while running the pipeline.
We will start disrupting everything pylint
Virtual checks using --disable=all
Which gives us a clean menu. After that, we will only enable two specific checks: C0116
(That is, missing signs) and W0311
(Which highlights the bad henger distance). We will also set --max-line-length=100
To allow longer lines of code while maintaining things that can be readable.
You can check the full menu of pylint
Codes and what they do here.
for you pylint
The composition should look like this:
- name: Run PyLint
run: |
pylint --disable=all --enable=C0116,W0311 --max-line-length=100 $(git ls-files '*.py')
And that’s all – I have just created the first workflow for the pipeline! Make sure your project structure matches what we covered in this guide, because any differences may prohibit the operation of the pipeline properly. Once everything is prepared, make your changes and push them to main
branch.
Once your work progress, you should see a yellow point next to your commitment message. This indicates that your pipeline works.
If the pipeline fails, you will see a red point next to the workflow. If it passes, it turns green.
Next, let’s add the Python file to test the workflow and verify whether it is attached to Docstrings. Click “Add a file”, then “Create a new file”, and name it main.py
. Once you add your code, send the file and push it to main
branch.
def some_function():
"""
Description of what this function does.
Returns:
Type: Description of what is returned
"""
pass
Pipeline Test
To test the pipeline we just created, click on GitHub actions. You should see all your workflow tasks. Click on the workflow to learn more details.
Now, let’s disintegrate how the workflow was running and what happened next. Click Pylint to view detailed results.
The pipeline works by preparing a job that first examines your warehouse, and then prepares Python 3.11 (as specified in the YAML file). It installs the necessary dependencies and runs pylint
Training text. Once the text program passes, the pipeline prepares the Python again and is achieved from the warehouse again to make sure that everything works properly before completing the task.
In short, when creating a pipeline, GitHub will automatically run the formed checks (in this case, Pylint) on your code when you adhere to the main branch or submit a withdrawal request. This helps to capture errors early in the development process.
conclusion
Since we conclude this guide to GitHub procedures, it is clear that using this practice can lead to a serious increase in the development process. By automating checks to make sure that your code works smoothly, you will save a lot of time and avoid errors when pushing the code to production.
This is the true power of Gaytap’s actions – its flexibility. It allows you to create workflow tasks specifically designed for your project needs. Whether you fly alone as an independent developer or work inside a team, CI/CD helps you to charge faster features and build a better product.
So, continue and persuade your team leads to the integration of CI/CD into your company’s workflow. Watch your team start charging a better code, faster!