Skip to main content

Github action step

GitHub Actions let you create custom actions that can perform predefined tasks. These predefined tasks range from cloning a codebase to building a Docker image and security scanning images. Previously-created actions are present on the GitHub marketplace, with a rich support of over 10k actions.

Harness CI has added a native Action step type for running GitHub Actions.

note

The Action step is supported in Harness Cloud build infrastructures only.

Examples

This step sets up a go environment for the following steps in the stage to use.

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

spec parameter reference

  1. uses: The GitHub repository of the action along with the branch or tag.
  2. with: A map with a key and value as string. These are action inputs.
  3. env: Environment variables passed to the action.

Action step yaml in Github action vs Harness CI

To create action step in harnessCI, copy the uses, with and env attributes from the GitHub action YAML and paste it in spec section of harness action step yaml

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

Example pipeline

This pipeline installs golang version 1.19.5 using an Action step, compiles the golang application, and runs the tests.

pipeline:
name: Build and test golang application
identifier: Build_test_golang
projectIdentifier: defaul
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 ./...