Simple steps to create your own actions in GitHub Action Marketplace

Aditya Bhangle
KPMG UK Engineering
4 min readJan 17, 2024

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that lets you automate your build, test, and deployment pipelines. GitHub also offers the GitHub Actions Marketplace, where you can find many actions ready to use and created by the community.

You too can create your own GitHub Action workflows that does a particular task like — getting all changed files in a PR, logging into a container registry and pushing an image to it and much more. Once these actions are ready, you can also push them to the GitHub Action Marketplace, so that other users can make use of the actions you have built.

Create your own Action and publish to GitHub Action Marketplace

There are 3 types of actions you can create — Docker Container Action, JavaScript Actions, and the Composite Actions

Docker Action
Docker containers package the environment with the GitHub Actions code. Since the user who uses the action does not need to worry about the dependencies, this option creates a more consistent and reliable unit of work

JavaScript Action
JavaScript actions can run directly on a runner machine and separate the action code from the environment used to run the code. Using a JavaScript action simplifies the action code and executes faster than a Docker container action.

Composite Action
A composite action allows you to combine multiple workflow steps within one action. For example, you can use this feature to bundle together multiple run commands into an action, and then have a workflow that executes the bundled commands as a single step using that action.

Contents

So, in this example, we are going to see how to create a composite action. As stated earlier, a composite action allows you to combine multiple workflow steps within one action.

For this you need to create 3 basic files

  • License — A generic file used by several applications to store license related information.
  • Readme.md — This contains information about your action, what it does and how the users can make use of it. It would be great to showcase a few examples with screenshots. The file usually contains:
    - Complete description of what the action really does
    - Required input and output if any
    - Env variables and Secrets the action uses if any
    - An example of how to use your action in a workflow
  • action.yml — This contains the actual action steps that performs some activity

You can refer to the following GitHub repository to see an example to create your own composite action
https://github.com/adityabhangle658/ruff-python-lint-format-check-pr

Publishing your Action to GitHub Action Marketplace

Before you can publish an action, you’ll need to create an action in your repository. For more information, see “Creating actions

If you plan to publish an action to GitHub Marketplace, you must ensure that the repository contains only the metadata files, code, and files required for the action. Creating a single repository for operations allows you to tag, share, and package code in a single unit.

Some of the key requirements to publish your action to GitHub marketplace are

  • The action must be part of a public repository.
  • Each repository must not contain any workflow files.
  • The action’s metadata file (action.yml or action.yaml) must be in the root directory of the repository.
  • You can create only one action in each repository
  • The name in the action must be unique. As in the name cannot match an existing action name published on GitHub Marketplace.
  • The name cannot match a user or organization on GitHub, unless the user or organization owner is publishing the action.
  • The name cannot match an existing GitHub Marketplace category.
  • GitHub reserves the names of GitHub features.

Example

action.yml

---
name: <Name of the Action>
description: <Description of the Action>
author: <Author>
branding:
icon: 'check-square’ (You could choose from number of options available)
color: 'green'
runs:
using: composite
steps:
- name: <step name1>
<lines_of_code>
- name: <step name2>
<lines_of_code>
- name: <step nameN>
<lines_of_code>

How to Publish to Marketplace

  • Once your code is ready, push the code to your public repository. You can use following git commands
git add –all
git commit –m <some message>
git push
  • Then you need to create a tag and push the tag to origin. You can use following git commands
git tag –a <tag_name> -m "<some message>
git push origin <tag_name>
  • Post the above step, you will see the tag appears in your Git repo
  • Then click on “Release” on the right sidebar and create a release by choosing the tag name and providing other details. Make sure you check the “Publish this Action to the GitHub Marketplace” box. Once done, you will be able to find your action in the GitHub marketplace. You can search by providing the action name.
Release Action to GitHub Marketplace

This is what your action will look like in GitHub Action Marketplace

You can refer to the following GitHub repository to see an example to create your own composite action
https://github.com/adityabhangle658/ruff-python-lint-format-check-pr

#github #githubactions

--

--