DEV Community

loading...
Cover image for Working with external actions - GitHub Actions (Part 3)

Working with external actions - GitHub Actions (Part 3)

mihinduranasinghe profile image Mihindu Ranasinghe Updated on ・3 min read

👉 Prerequisites

If you are new to GitHub Actions, I suggest you to read these articles


Here is the cool thing about GitHub actions.

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

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

Alt Text


  • 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.

How to reference a public action ?

There are several ways that we can reference a public action from the marketplace.

  1. Referencing a branch
  2. Referencing a version
  3. 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

Enter fullscreen mode Exit fullscreen mode

We have to provide a reference with the "uses:" tag and we can provide relevant inputs under "with:" tag.

  • Referencing a branch:

uses: publisher-username/repo-name@branch-name

Enter fullscreen mode Exit fullscreen mode
  • Referencing a version:

Find the releases from the marketplace for the particular action


uses: publisher-username/repo-name@v1.1.0

Enter fullscreen mode Exit fullscreen mode
  • Referencing a commit ID :

Explore the commit history of the action and find a specific commit ID


uses: publisher-username/repo-name@commit-ID

Enter fullscreen mode Exit fullscreen mode

Note :

  • 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.


An easier way to find the reference of 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.

Alt Text


For example lets use this Hello world javascript action

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.


name: name-of-the-workflow

on: [push]

jobs:
    sample-job-1:
        runs-on: ubuntu-latest
        steps:
            - name: step-1
              uses: actions/hello-world-javascript-action@v1.1
              with:
                 who-to-greet: Mihindu


Enter fullscreen mode Exit fullscreen mode

Output :

Hello Mihindu!

Enter fullscreen mode Exit fullscreen mode

Another useful action for any workflow.

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: actions/checkout@v2.3.4

            - run: ls


Enter fullscreen mode Exit fullscreen mode

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?

Using Docker Containers In Jobs - GitHub Actions (Part 4)

Thank You

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/

Discussion (0)

Forem Open with the Forem app