0Pricing
DevOps Bootcamp · Lesson

Developing Custom GitHub Actions

Learn to create your own reusable custom actions using JavaScript or Docker to extend GitHub Actions functionality.

Developing Custom GitHub Actions is a free DevOps Bootcamp lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Extend GitHub Actions

What if you need a specific task in your workflow that GitHub Actions doesn't offer out-of-the-box? Or perhaps you have complex logic you want to reuse?

Custom actions let you build your own reusable tools for workflows. They're like mini-programs that perform a specific job, tailored to your needs.

Power of Customization

Custom actions bring several benefits to your CI/CD pipelines:

  • Reusability: Write once, use in many workflows and repositories.
  • Standardization: Ensure consistent processes across your organization.
  • Encapsulation: Hide complex logic behind a simple interface.
  • Integration: Interact with specific internal tools or APIs.

JavaScript or Docker?

GitHub Actions supports two primary ways to create custom actions:

  • JavaScript Actions: Written in JavaScript (or TypeScript), these run directly on the runner machine. Fast and easy for simple tasks.
  • Docker Container Actions: Encapsulate your environment and code within a Docker image. Ideal for actions requiring specific dependencies or languages.

Defining Your Action

Every custom action needs an action.yml file in its root directory. This YAML file is like a manifest, telling GitHub Actions about your action:

  • name and description: What your action does.
  • inputs: Data your action accepts.
  • outputs: Data your action produces.
  • runs: How your action executes (e.g., JavaScript file or Docker image).

Simple JS Action Example

Let's look at a basic JavaScript action. You'll need an action.yml and an index.js file. The action.yml defines the action's metadata and execution environment.

# action.yml
name: 'Hello World Action'
description: 'Greets a person using a custom message'
inputs:
  who-to-greet:
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  greeting-message:
    description: 'The greeting message generated'
runs:
  using: 'node16'
  main: 'index.js'

Writing the JavaScript

The index.js file contains the actual logic. We use the @actions/core toolkit to get inputs and set outputs.

Try running this simple JavaScript snippet to see how inputs and outputs work conceptually, even outside a full workflow:

// index.js (simplified for demonstration)
const core = require('@actions/core');

try {
  const name = core.getInput('who-to-greet');
  const message = `Hello, ${name}!`;
  console.log(message);
  core.setOutput('greeting-message', message);
} catch (error) {
  core.setFailed(error.message);
}

// A standalone runnable example to demonstrate core logic
function runSimpleGreeting(inputName) {
  const name = inputName || 'World';
  const message = `Hello from runnable JS, ${name}!`;
  return message;
}

console.log(runSimpleGreeting('CoddyKit'));
console.log(runSimpleGreeting());

Docker Action Basics

For more complex environments, Docker container actions are powerful. They include a Dockerfile that defines the container image, bundling all necessary dependencies.

Your action.yml will reference this image, telling GitHub Actions to build and run it.

# action.yml for Docker action
name: 'Docker Hello World'
description: 'Greets a name from within a Docker container'
inputs:
  who-to-greet:
    description: 'Who to greet'
    required: true
    default: 'Docker'
outputs:
  greeting-message:
    description: 'The greeting message from Docker'
runs:
  using: 'docker'
  image: 'Dockerfile'

Your Action's Environment

The Dockerfile specifies the base image, installs dependencies, and defines the entry point for your action. This ensures your action runs in a consistent, controlled environment.

# Dockerfile
FROM alpine:3.16

LABEL "com.github.actions.name"="Docker Hello World"
LABEL "com.github.actions.description"="Greets a name from within a Docker container"
LABEL "com.github.actions.icon"="globe"
LABEL "com.github.actions.color"="blue"

# Copy your script into the container
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

Scripting Docker Actions

Inside the Docker container, your entrypoint script (e.g., entrypoint.sh) receives inputs as environment variables (prefixed with INPUT_). It sets outputs by writing to the file specified by the $GITHUB_OUTPUT environment variable.

#!/bin/sh -l

# entrypoint.sh

echo "Hello from Docker, $INPUT_WHO_TO_GREET!"
GREETING="Hello from Docker, $INPUT_WHO_TO_GREET!"
echo "greeting-message=$GREETING" >> "$GITHUB_OUTPUT"

Best Practices for Actions

When developing custom actions, consider these tips for robust and maintainable tools:

  • Versioning: Use semantic versioning (e.g., v1, v2) for stability.
  • Testing: Rigorously test your action locally and in workflows.
  • Error Handling: Implement clear error messages and graceful failures.
  • Security: Sanitize inputs and avoid exposing sensitive data.
  • Documentation: Provide clear usage instructions in your README.

Action Type Check

You need to create a custom GitHub Action that requires a specific Python library that is not pre-installed on standard GitHub Actions runners. Which type of action is generally best suited for this scenario?

Custom Actions Summary

We've explored how to extend GitHub Actions by creating your own custom actions. You learned about the two main types: JavaScript and Docker container actions, and the crucial role of the action.yml file. We also covered how to define inputs, outputs, and the core logic for each type, along with best practices for development.

Custom actions are powerful for reusability and standardization in your CI/CD pipelines!

Frequently asked questions

Is the “Developing Custom GitHub Actions” lesson free?

Yes — the full text of “Developing Custom GitHub Actions” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Developing Custom GitHub Actions”?

Learn to create your own reusable custom actions using JavaScript or Docker to extend GitHub Actions functionality. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Developing Custom GitHub Actions” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Developing Custom GitHub Actions
  2. Self-Hosted Runners for On-Premise
  3. Integrating with Enterprise Systems
  4. Composite Actions and Publishing to the Marketplace
← Back to DevOps Bootcamp