If you are new to GitHub Actions, I suggest you to read these articles
Instead of automating each and every step by your own from the scratch , you can use reusable codes in Github Actions.
Mainly there are two types of reusable actions.
We can create private reusable actions and use them inside our local workflows.
We can use public reusable actions from the marketplace
In this article, let's have a look at how we can use publicly available external actions from the marketplace and how we can use them inside our workflow.
GitHub Actions Marketplace is where you can find out reusable codes/workflows also known as "actions" implemented by someone in the GitHub Actions community.
Most of the reputed cloud companies like AWS, Google, Azure have published their own public actions for their clients.
Not only companies, also the individuals in the Github Actions Community have build up and published some useful actions in the Marketplace
Link : Marketplace
You can search for actions in the search bar of the Marketplace.
Once you click on an action, you will be redirected to a readme(documentation) page and there you can find a brief about the action and how we can use it in our workflow and what is the reference(signature) of the particular workflow and what are the inputs we have to give when we use the action in our workflow.
There are several ways that we can reference a public action from the marketplace.
- Referencing a branch
- Referencing a version
- Referencing a commit
Here is the basic structure of a step to use a public action :
steps: - name: Any-relevant-name-for-the-step id: step-1-id(Optional) uses: #reference with: #inputs
We have to provide a reference with the "uses:" tag and we can provide relevant inputs under "with:" tag.
- Referencing a branch:
- Referencing a version:
Find the releases from the marketplace for the particular action
- Referencing a commit ID :
Explore the commit history of the action and find a specific commit ID
If you reference a branch, actually it is not really preferred. Some breaking changes might occur when the publisher changes the code in the particular branch you referred. Then your workflow might fail.
If you reference a specific Version, It will help to mitigate this problem.
The safest way is to have a stable workflow is to use specific commit ID to reference an action.
- Go to the action page in the marketplace.
- Click on this green color box or drop down and find the specific version.
- copy paste the reference.
If you have read the documentation, there are few inputs you can provide.
I provide here the "who-to-greet" input with a sample name.
Before working with the repo files from the workflow steps, we need to clone our repo files into the virtual machine that we created in the job.
So this is something we do at very first of many workflows. So that you can use this checkout public action and clone repo files into VM very easily.
name: name-of-the-workflow on: [push] jobs: sample-job-1: runs-on: ubuntu-latest steps: - name: Clone-repo-files-into-vm uses: firstname.lastname@example.org - run: ls
There are many more useful actions in the marketplace. Take your time and refer them and use them in your workflows according to the purpose.
👉 What's Next?
Hope you all enjoyed and learned something from this. Let me know your comments and suggestions in the discussion section.
👉 Visit me - https://mihinduranasinghe.com/