GitHub Actions CI/CD - A Basic Demo

GitHub Actions CI/CD - A Basic Demo

Getting Started with GitHub Actions

GitHub Actions

GitHub Actions is a CI/CD platform that allows developers to automate software development workflows, such as building, testing, and deploying code. It integrates with GitHub and provides a range of tools and features for automating software development processes, including pre-made actions, a powerful API, and the ability to run workflows in parallel on multiple platforms.

GitHub Actions is used to automate a wide range of tasks, including continuous integration, continuous delivery, and deployment to production.

It does this by allowing them to set up specific tasks, like testing and building code, that runs automatically every time changes are made to the code. This saves time and helps ensure that the code is always up-to-date and working correctly.

Lint

Lint is a type of tool used in software development to check code for potential errors, bugs, and style issues. Linting refers to the process of running a lint tool against code to identify and highlight issues.

A lint tool analyzes the code and provides feedback, such as warnings or error messages, about potential problems.

This helps developers identify and fix problems before they become bigger issues, leading to improved code quality and reduced development time.

Why you should use it?

  1. Integration with GitHub: Integrates seamlessly with the GitHub platform, making it easy to use and access.

  2. Multi-platform Support: Allows workflows to run on multiple platforms, making it suitable for a wide range of projects.

  3. Increased Collaboration: Facilitates collaboration among team members by allowing them to easily share and automate workflows.

  4. Improved Code Quality: Helps improve the quality of code by automatically testing and building code with each change.

  5. Continuous Deployment: Supports continuous deployment to various environments, making it easy to continuously deliver updates to production.

Hands-On Demo

1.Make a Repo

Make a new Repository on GitHub named "gitactions-demo" with a ReadMe file

2.Create the SuperLinter file

  1. Click on Addfile > Create a new file

  2. Create the file in .github/workflows as shown in the image below.

  3. Name this file superlinter.yml

name: Super-Linter

on: push

jobs:
  super-lint:
    name: Lint code base
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run Super-Linter
        uses: github/super-linter@v4
        env:
          DEFAULT_BRANCH: main
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

After saving the changes your repository should look like this

3.Testing

Now, let's test the superlinter file that we just made.

For that, we will intentionally create a python file with incorrect code named main.py

def hello():
    print("hi")

def bye():
  print("bye")


print(hello())

As the code is incorrect, the lint check will fail and will tell us what is wrong with the code.

It also shows what we need to do to improve the code

The '+' represents the addition of a line and the '-' represents the deletion of the line. So, let's do what GitHub Action suggests and do again.

def hello():
    print("hi")


def bye():
    print("bye")


print(hello())

After this, we can create this file without any problems.

What's Next?

After all this basic stuff, we have something known as the 'GitHub Actions Marketplace' that has prebuilt templates for various platforms such as AWS, GCP, Azure, DigitalOcean, etc.

You can access it by clicking on Actions > New Workflow .

Final Words

In conclusion, GitHub Actions is a useful tool for automating software development workflows. It integrates with GitHub and supports multiple platforms, making it versatile and accessible.

My next blog will be on Dockerizing an image and publishing it on GCP using GitHub Actions.

If you liked this blog post, consider liking and commenting on it and Sharing it with your friends.

Did you find this article valuable?

Support Varchasv Hoon by becoming a sponsor. Any amount is appreciated!