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.
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
- You have at least one Docker registry connected to your Codefresh account.
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, push it in the Docker registry that you specify and then use it as a standard Codefresh step.
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
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 the following need to be filled under the
env- a list of arguments. They are specific to each Github action so check the documentation of the action itself
registry- the name of a registry connected to Codefresh. You can find the names in your integrations page
registry_repo- the repository/account that you wish to use in the registry for storing the Github action. In the case of Dockerhub it is your Dockerhub username, for the Codefresh registry it is your Codefresh username and so on.
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:
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
- Push the resulting image to the connected Codefresh registry
- Take the resulting image and insert it as Codefresh step
- Pass the environment variables as arguments to the Github action
- Run the
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.