CI/CD using GitHub Actions

Knoldus Blog Audio
Reading Time: 3 minutes

GitHub Actions: How to create a pipeline using GitHub Actions? There are many other tools present for CI/CD like Jenkins, Circle CI, Teamcity, and many more. Here we are going to know about GitHub Actions, how to create a pipeline and what are the features of using GitHub Actions.

So, Let’s start with the little bit of introduction on GitHub Actions.

Introduction

GitHub Actions help you automate tasks within your software development life cycle. GitHub Actions are event-driven, meaning that you can run a series of commands after a specified event has occurred, like a commit, a PR or on a schedule.

You can find an “Action” available in the Actions “marketplace” – it is like a plugin so you can do more complex tasks in your workflow without writing the code yourself. If you want more detail about actions you can refer this.

Steps need to create CI/CD using GitHub Actions

How to create a Hello World workflow on GitHub Actions

Step 1: Choose a repo

Create a new GitHub repo or choose an existing one. It doesn’t matter what code is in the repo.

Step 2: Create a workflow

Click the “Actions” tab on your repo. Note that you can view this tab on any repo but you can only edit workflows if you have edit access to the repo.

If you have no workflows (config files used for pipelines) yet, you’ll be prompted to create one.

Then you will see the different options to create a workflow as there are inbuilt templates for many languages or you can create your own workflow using “manual workflow option”

You’ll be taken to an editor view for editing a new file called .github/workflows/main.yml. You can leave the path as it is.

The comments in the sample will be very verbose and you don’t need to know everything yet, so you can delete the file contents.

Paste in the simple content below:

name: Scala CI

on:
  push:

jobs:
  job1:
    name: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 1.8
        uses: actions/setup-java@v1
        with:
          java-version: 1.8
      - name: Run tests
        run: sbt test

The key parts to note are the triggers on a push event and the steps . The name for the job can be anything (no spaces). You only need one job in most cases.

You can add as many steps you want in workflow and can define multiple job also.

Note: every job runs parallelly on different GitHub servers.

Step 3: Commit the changes

Now whatever changes you made in the workflow just push the commit so that the workflow get started once it occurs the push event.

Step 4: View logs

After pushing the code it will run against the current code immediately. View the Actions tab and find the logs for a run for this workflow

The workflow should log that it is successfully checked out your repo and then ran one step to print a greeting. Then it will finish with a green checkmark.

So this way you can create a workflow in GitHub Actions. One more thing to be noted about GitHub Actions is you can have the inbuilt actions for different operation like docker build, docker push , upload , download artifact and many more. You will get an example for docker in my reference pipeline here

If you are using ‘Teamcity’ you can have a look here

References:

https://docs.github.com/en/actions

https://gabrieltanner.org/blog/an-introduction-to-github-actions

Knoldus-blog-footer-image

1 thought on “CI/CD using GitHub Actions3 min read

Comments are closed.