Product
|
Cloud costs
|
released
April 26, 2024
|
3
min read
|

GitHub Actions Plugin for Reusable CI/CD Pipelines

Updated

In this blog post, we'll explore how you can utilize the GitHub Actions Plugin step in your Harness Continuous Integration pipeline to create a versatile and robust continuous integration workflow. Crafting quality code within tight deadlines is a constant challenge for developers. Ensuring adherence to coding standards and best practices is crucial in this process. Harness Continuous Integration provides a solution by offering a variety of community plugins to help with code quality and beyond.

Reusable CI/CD Pipelines

Let’s ask a question:

Why do we need reusable CI/CD pipelines?

The answer lies in efficiency and consistency. Reusable CI/CD pipelines streamline the development process by providing a standardized workflow for building, testing, and deploying applications. Rather than reinventing the wheel with each project, developers can leverage pre-defined pipelines tailored to their organization's needs. This not only saves time but also ensures consistency across projects, reducing the risk of errors and promoting collaboration among team members.

Furthermore, reusable pipelines promote scalability and maintainability. As projects evolve and new features are added, having a modular, reusable pipeline allows for easy updates and modifications without the need to overhaul the entire process. This flexibility enables teams to adapt quickly to changing requirements and iterate on their workflows efficiently.

In the next section, we'll explain the technology behind GitHub Actions and then how we can leverage GitHub Actions within the Harness CI pipeline. By utilizing these plugins, we'll demonstrate how they enable the creation of numerous pipelines while maintaining reusability. We'll explore how these tools contribute to ensuring code quality and adherence to best practices throughout the development lifecycle.

The Anatomy of “Actions”

Do you know how actions run under the hood?

Actions encapsulate common tasks to reduce duplication of configuration in your pipelines. Behavior of an action is determined by the inputs passed. The code in the action runs, which can modify the pipeline environment, and potentially pass outputs to following steps in your pipeline.

Additionally, developers can use open source tools like act. to run actions locally for fast feedback and as a local task runner. act reads the actions from a directory, determines the set of actions to be run, and uses the Docker API to pull or build the necessary images defined in the action files. It then determines the execution path based on dependencies and runs containers for each action. The environment variables and filesystem are configured to match the environment provided by the platform.

This capability allows developers to test changes to their action files without needing to commit/push every time, providing fast feedback. Furthermore, developers can leverage the actions defined in their workflows to replace traditional task runners, reducing repetition and streamlining the development process.

GitHub Actions in Harness CI

Harness CI is based on Drone. Drone supports plugins, which can perform predefined tasks in your pipelines. Drone provides a GitHub Actions plugin, which is used by Action steps in Harness CI. The Drone GitHub Actions plugin is a wrapper around act. Harness CI also allows you to run actions from a private GitHub repository

Let’s use hello-world-javascript-action in a Harness CI pipeline. If this is the first time you’re creating a Harness pipeline, you can follow this getting started guide.

              - step:
                  type: Action
                  name: Hello world
                  identifier: Hello_world
                  spec:
                    uses: actions/hello-world-javascript-action@v1
                    with:
                      who-to-greet: Captain Canary

In this Harness CI configuration, a step is defined to execute a custom action named "Hello world." The step is identified by the name "Hello_world" for reference within the Harness CI environment.

The step configuration specifies the action to be used with the uses directive. The action is sourced from an external location, and its specific implementation is not provided in this context.

Additionally, input parameters are provided to the action using the with directive. In this example, the input parameter who-to-greet is provided with the value "Captain Canary."

In the pipeline log output, you will see the message printed.

Pipeline execution log output from the above pipeline

Run other actions from the vast GitHub Actions marketplace, such as linters. Here is an example of using the golangci-lint action.

             - step:
                  type: Action
                  name: Lint
                  identifier: lint
                  spec:
                    uses: golangci/golangci-lint-action@v3
                    with:
                      version: v1.54
                      skip-cache: true
                      working-directory: /harness

Harness CI Cloud (hosted build infrastructure)  offers isolated build environments on Harness-managed VMs with preconfigured tools and settings, simplifying CI pipeline setup and maintenance. With build credits for usage on preconfigured machines, starter pipelines for various languages, and rapid builds across Linux, macOS, and Windows, developers can leverage Harness Cloud to streamline software development while accessing the latest features ahead of other infrastructure options.

For other build infrastructures, you can run the Drone GitHub Actions plugin in a Plugin step.

              - step:
                  type: Plugin
                  name: Hello world
                  identifier: Hello_world
                  spec:
                    image: plugins/github-actions
                    settings:
                      uses: actions/hello-world-javascript-action@v1
                      with:
                        who-to-greet: Captain Canary

Next Steps

Having explored the capabilities of Harness CI alongside examples like GitHub Actions and the super-linter plugin, it's clear that the key to efficient and effective CI/CD lies in the ability to leverage automation and maintainable workflows. By understanding how Harness CI operates under the hood and how to extend its functionality beyond its native environment, you've gained valuable insights into creating reusable pipelines that promote consistency and scalability in your development process.

If you’re using GitHub Actions, it’s time to transfer GitHub Actions into Harness CI.

Sign up now

Sign up for our free plan, start building and deploying with Harness, take your software delivery to the next level.

Get a demo

Sign up for a free 14 day trial and take your software development to the next level

Documentation

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

Case studies

Learn intelligent software delivery at your own pace. Step-by-step tutorials, videos, and reference docs to help you deliver customer happiness.

We want to hear from you

Enjoyed reading this blog post or have questions or feedback?
Share your thoughts by creating a new topic in the Harness community forum.

Sign up for our monthly newsletter

Subscribe to our newsletter to receive the latest Harness content in your inbox every month.

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Continuous Integration