GitHub Actions in Codefresh Pipelines
Using the GitHub action converter
GitHub Actions are a set of reusable workflows that can be composed to create automation sequences for GitHub projects. GitHub Actions are supported natively with GitHub, but you can also use them in Codefresh pipelines by automatically converting them to Codefresh pipeline steps.
By using GitHub Actions in your marketplace you have the following benefits:
- access to a vast catalog of reusable pipeline components
- the ability to use GitHub actions with any provider, as Codefresh supports Bitbucket, GitLab, Azure Git etc.
Prerequisites
In order to use a GitHub action in Codefresh you need to make sure that the following apply:
- The GitHub action you have selected is Docker based and has a self-contained and valid Dockerfile
- You have read the documentation of the GitHub action and know what arguments/input it requires
Also notice that since GitHub Actions are created by the community, it is your responsibility to filter and curate any GitHub actions that you wish to use in Codefresh pipelines. If for example you use a GitHub action, and then it is removed by its creator, the Codefresh pipeline that uses it will break as well.
We suggest you first use a GitHub action in a GitHub workflow, in order to understand its requirements, before you use it in a Codefresh pipeline.
How it works
Codefresh offers a github-action-to-codefresh step converter. This converter has two functions
- When you create your pipeline it will analyze the GitHub action and try to find what arguments it requires. You must then fill the values needed by yourself
- When the pipeline runs, it will automatically find the Dockerfile of the GitHub action, build it and make available the docker image in any subsequent step in the same pipeline.
All this process is automatic. You just need to make sure that all arguments/inputs of the GitHub action as provided using pipeline variables, shared configuration or any other standard mechanism you already use in Codefresh.
Inserting a GitHub action in Codefresh pipeline
Create a Codefresh pipeline by visiting the pipeline editor. On the right hand panel in the step tab, search for actions
.
From the result choose the GitHub Actions step with the green check mark. From the dialog that will appear you will see a browser for GitHub actions. Scroll down to find the GitHub action that you want to use or enter a keyword to filter the list
Then click on the GitHub action that you want to use in your pipeline. On the right hand side Codefresh will present that YAML step that you need to insert in your pipeline.
This YAML snippet is a template and you need to fill the env
block under the arguments
block:
The required environment variables are specific to each GitHub action so check the documentation of the action itself.
In the example above we are using the Snyk GitHub action. By visiting the documentation page we find that this action expects a SNYK_TOKEN
as input.
We therefore add the token as a pipeline variable:
Here is the final pipeline:
codefresh.yml
version: '1.0'
steps:
snyk-cli-action:
title: snyk
description: snyk
type: github-action-executor
arguments:
url: 'https://github.com/marketplace/actions/snyk-cli-action'
envs:
- SNYK_TOKEN: '${{SNYK_TOKEN}}'
cmd: test alpine@latest
The cmd
property is specific to each GitHub action and in the case of Snyk we say we want to scan an alpine image for security issues.
Running a Codefresh pipeline with GitHub Actions
You can run the pipeline as any other Codefresh pipeline.
Once the pipeline reaches the GitHub action step, the converter will do automatically the following
- Find the Dockerfile of the GitHub action
- Build the Dockerfile
- Take the resulting image and insert it as Codefresh step
- Pass the environment variables as arguments to the GitHub action
- Run the
cmd
command
If you have issues please contact us (or open a support ticket) and let us know which GitHub action you are trying to use and what is the URL of the Codefresh build that fails.