GitHub Actions pipeline integration
Using the GitHub action converter in Codefresh pipelines
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
- Ability to use GitHub Actions with any provider, as Codefresh supports Bitbucket, GitLab, Azure Git etc.
Prerequisites
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
TIP
Since GitHub Actions are created by the community, it is your responsibility to filter and curate any GitHub Action you wish to use in Codefresh pipelines. If for example you use a GitHub Action that is then removed by its owner, 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 find what arguments it requires.
You must then define the values needed by yourself. - When the pipeline runs, it automatically finds the Dockerfile of the GitHub Action, builds it, and makes 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 are 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.
- In the Steps tab on the right-hand side, search for
actions
and select GitHub Actions.
- Scroll down to find the GitHub Action that you want to use or enter a keyword to filter the list.
- Click on the GitHub Action you want to use in your pipeline.
Codefresh displays the YAML for the action on the right. This is the step that you need to insert in your pipeline.
The YAML snippet is a template, and you need to fill the env
block below 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 use 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
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 automatically does the following:
- Finds the Dockerfile of the GitHub Action
- Builds the Dockerfile
- Takes the resulting image and inserts it as Codefresh step
- Passes the environment variables as arguments to the GitHub Action
- Runs 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 the URL of the Codefresh build that fails.