Skip to main content

GitHub Action plugin step settings

GitHub Actions is a GitHub feature that enables you to automate various event-driven activities in GitHub, such as cloning a repository, generating Docker images, and testing scripts. You can find over 10,000 GitHub Actions on the GitHub Marketplace or create your own Actions.

You can use the GitHub Action plugin step to run GitHub Actions in your Harness CI pipelines.

info

Currently, the GitHub Action plugin step is supported for the Harness Cloud build infrastructure only.

For other build infrastructures, you can use the generic Plugin step with the GitHub Actions Drone Plugin, as explained in Run GitHub Actions in CI pipelines.

Usage examples

In the following YAML examples, GitHub Action plugin steps are used to set up Node.js, Go, Java, and Ruby environments.

This Action step uses the actions/setup-node GitHub Action to set up a Node.js environment that the subsequent steps in the stage can use.

              - step:
type: Action
name: setup nodejs
identifier: setup_nodejs
spec:
uses: actions/setup-[email protected]
with:
node-version: '16'

Settings and specifications

To add a GitHub Action plugin step to your pipeline YAML, add an Action step, for example:

              - step:
type: Action
name: setup golang
identifier: setup_go
spec:
uses: actions/setup-[email protected]
with:
go-version: '1.17'

The spec parameters define which Action to use, the Action settings, and environment variables that you need to pass to the Action. These are configured according to the GitHub Action's usage specifications.

  • uses: Specify the Action's repo, along with a branch or tag, such as actions/[email protected].
  • with: If required by the Action, provide a mapping of key-value pairs representing Action settings, such as go-version: '1.17'.
  • env: If required by the Action, provide a mapping of environment variables to pass to the Action.
tip

If you already configured GitHub Actions elsewhere, you can quickly transfer GitHub Actions into Harness CI by copying the spec details from your existing GitHub Actions YAML.

You can use variable expressions in the with and env settings. For example, credentials: <+stage.variables.[TOKEN_SECRET]> uses a stage variable.

YAML Example: Pipeline with an Action step

This pipeline uses a GitHub Action plugin step to install golang version 1.19.5. It then compiles the golang application and runs tests.

pipeline:
name: Build and test golang application
identifier: Build_test_golang
projectIdentifier: default
orgIdentifier: default
tags: {}
properties:
ci:
codebase:
connectorRef: Github_connector
build: <+input>
stages:
- stage:
name: Build golang application
identifier: Build_golang_application
description: ""
type: CI
spec:
cloneCodebase: true
platform:
os: Linux
arch: Amd64
runtime:
type: Cloud
spec: {}
execution:
steps:
- step:
type: Action
name: setup golang
identifier: setup_go
spec:
uses: actions/setup-[email protected]
with:
go-version: 1.19.5
- step:
type: Run
name: Build and test
identifier: Build_and_test
spec:
shell: Bash
command: |-
go build .
go test -v ./...

Transfer GitHub Actions into Harness CI

If you already configured GitHub Actions elsewhere, you can copy the uses, with and env lines from your GitHub Action YAML into the Action step's spec in your Harness CI pipeline YAML.

If you're using the Visual editor, you can transfer the data into the Uses, Settings, and Environment Variables fields.

The following table compares GitHub Action YAML with Harness CI Action step YAML. Notice the consistency of uses, with, and env.

Github Action YAML Harness CI Action step YAML
- name: hello-world
uses: actions/hello-world-javascript-[email protected]
with:
who-to-greet: 'Mona the Octocat'
env:
hello: world
- step:
type: Action
name: hello world
identifier: hello_world
spec:
uses: actions/hello-world-javascript-[email protected]
with:
who-to-greet: 'Mona the Octocat'
env:
hello: world