Learn How to Run GitHub Actions in Your CI/CD Pipeline
Tags: github, tutorial, devops, productivity
Published: 2023-03-15 05:49:00

A GitHub action is a customisable piece of code that developers can use to automate tasks and workflows in their GitHub repositories. Actions are made up of one or more steps, which can perform a variety of tasks, such as building code, running tests, deploying applications, or sending notifications. Actions can be triggered by various events, such as a pull request or a push to a specific branch, and can be configured to run on different operating systems and environments. GitHub provides a library of pre-built actions that developers can use or customise to suit their needs, or they can create their own actions and share them with the GitHub community. With actions, developers can automate repetitive tasks, improve the quality of their code, and accelerate their development workflows.

Harness is considered a leader in the field of continuous delivery, and today I'll show you how you can run GitHub actions as a step in the Harness CI module. 

## Prerequisites
- [GitHub account](https://github.com/join) 
- Free [Harness CI module](https://app.harness.io/auth/#/signup/?module=ci&utm_source=internal&utm_medium=social&utm_campaign=community&utm_content=pavan_actions_tutorial&utm_term=get-started) account
- A sample repo to experiment. Fork our [sample application](https://github.com/pavanbelagatti/Golang-CICD-Tutorial) written in Go.

## Tutorial
Signup for the Harness CI module and create a project and add details.
![create project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c1hio75o0algrddvg5t.png)

Invite collaborators for your project if you want.
![Invite collaborators](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p3j594zky7kr9u8drur8.png)

Select the continuous integration (CI) module.
![CI module](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtopm8eo5mntbry9zivc.png)

Next, it will guide you through creating your first pipeline.
![first pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d8eirv1wd3eizwk5ii61.png)

Connect your repository. Connect the one you forked, the [example repository](https://github.com/pavanbelagatti/Golang-CICD-Tutorial).
![connect repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/83d7ca0z8953z20f4wjf.png)

Since our application code is in GitHub, select 'GitHub'.
![select GitHub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dagsf3r8pjmzim9dg22t.png)

Connect your GitHub with your GitHub personal access token. If you don't know how to create your GitHub personal access token, please refer to [this official document](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token). 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yczgn12d1xmn1xs7vh18.png)

Make sure the connection is successful.

Next, select your repository
![select your repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mm1qqz7ibc67ynxjknjx.png)

Since it is a Go application repository, we will select 'Go' and we can see a default YAML file.
![default yaml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zk6m11rtwg7xcczt9smq.png)

Save and continue, you will land in the pipeline studio which should look like this
![pipeline studio](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g3xwxjz1dg76llwfq6mz.png)

Under the execution tab, you will see the 'Build Go App'. Click on it and it will show the details of the step.
![build go app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylnx2g4787zm2dsm9obc.png)

Let's replace the command field with our own command. We are just adding the `mod init` command to the existing commands list.
![modinit command](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jywa9l5da9d242pxjfie.png)

Apply changes, save and run the pipeline.
![run pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/smibqaeh6oaqz8cnis27.png)

You should see a successful pipeline execution:)
![successful pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yeldo0zezzj0kmxxbo9o.png)

## Add and Run GitHub Actions
Let's customise our pipeline to add GitHub actions now. How?

You should see the 'Pipeline Studio' written at the top with 'VISUAL' & 'YAML' written. click on the 'YAML' 
![click on yaml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qv9m6ks5ik4uc1i5tq51.png)

You will see the YAML file of our pipeline.
![yaml pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ej10096yp993ticvj1w1.png)

Next, we will modify this YAML by adding GitHub actions.
Enable editing the YAML option.
![edit yaml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c1tyijax24rab2wfagwe.png)
![confirm yaml editing](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8c7an727nsc2w3xz4885.png)

Let's add the YAML to setup Golang. The YAML is below.

```
            steps:
              - step:
                  type: Action
                  name: setup golang
                  identifier: setup_go
                  spec:
                    uses: actions/setup-go@v3
                    with:
                      go-version: "1.17"
```
Let's add the above YAML piece to our pipeline YAML.
![adding the go yaml](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/znx7xc732pgkg7u1b0ne.png)

Now, select 'VISUAL' from the top to see how the pipeline looks visually.
![visual](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/889rhq14j5qhcixuyfyp.png)

You should see our added YAML piece 'setup Golang' in the visual pipeline studio.
![setup go](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6ave265cllr1okpb1syc.png)

Similarly, let's modify/edit the pipeline YAML by going to YAML tab. Let's extend our steps by adding Trivy security vulnerability scan to our application repo.

The YAML piece for adding the Trivy scan is shown below,

```
- step:
     identifier: trivy
     name: Run Trivy vulnerability scanner
     type: Plugin
     spec:
         connectorRef: dockerhub
         image: plugins/github-actions
         privileged: true
         settings:
             uses: aquasecurity/trivy-action@master
             with:
                 image-ref: drone/git
                 format: table
                 exit-code: "1"
                 ignore-unfixed: "true"
                 vuln-type: os,library
                 severity: CRITICAL,HIGH,LOW
             env:
                 CI: true
```

![Trivy application repo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4t9lhzpa2fx5lvmqf8sx.png)

When you again switch back to the visual mode, you should see our pipeline and the step 'Trivy security vulnerability scan' added.
![Trivy scan added](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7nj4jqn1vomnx6a01ly4.png)

Save and run the pipeline.
![save and run pipeline](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4oz35drkht4w0jlzb00.png)

You should see the pipeline getting executed and it will fail. Don't panic, it is failing because there are vulnerabilities in the application repo. 
![scan result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nrbog47my73955rm6b39.png)

You can reorder your steps under execution as per your wish just by dragging and dropping them where you want.  
![drag and drop](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erkn0ziokw8tssdyustp.png)

This way, you can easily build your pipeline by adding various capabilities in Harness. You can see the various actions available in the [GitHub actions marketplace](https://github.com/marketplace?type=actions).


### What to Choose: Harness or GitHub Actions?
Both Harness CI and GitHub actions are powerful tools for automating continuous integration and deployment workflows. However, there are a few key differences that set Harness CI apart and may make it a better choice for some development teams.

Firstly, Harness CI offers a more comprehensive set of features than GitHub actions. While GitHub actions is a great tool for automating simple tasks, Harness CI is designed to handle complex workflows that involve multiple stages, environments, and pipelines. It offers a visual pipeline editor that allows developers to create and manage workflows quickly and easily and supports a wide range of integrations with popular tools and platforms.

Another advantage of Harness CI is its focus on security and compliance. Harness CI offers robust security features such as multi-factor authentication, role-based access control, and encryption of sensitive data. It also supports compliance with various regulations, such as [SOC 2](https://www.harness.io/blog/harness-achieves-soc-2-compliance).

Finally, Harness CI offers enterprise-level support and services, including 24/7 customer support, onboarding, and training. This level of support can be invaluable for large development teams or organisations that require a high level of customisation and assistance.

In summary, while both Harness CI and GitHub actions are powerful tools for automating CI/CD workflows, Harness CI offers a more comprehensive set of features, better security and compliance, and enterprise-level support, making it a better choice for some development teams.