Skip to main content
In this tutorial, you’ll build a JavaScript GitHub Action that posts a random “thank you” GIF from Giphy whenever a new pull request is opened. We’ll cover project setup, metadata definition, coding, bundling dependencies, and publishing to your GitHub repository.
The image shows a GitHub documentation page titled "Creating a JavaScript action," which provides a guide on building a JavaScript action using the actions toolkit. The page includes an introduction and a sidebar with related topics.

Prerequisites

Before you begin, verify that you have the following:
The image shows a GitHub documentation page about creating a JavaScript action, including prerequisites like downloading Node.js and creating a GitHub repository.

1. Project Setup

Create a fresh directory and initialize npm. This scaffolds your package and creates essential files:

2. Define Action Metadata

The action.yml file tells GitHub how to run your action. Specify inputs and the entrypoint:
The github-token input is usually provided via ${{ secrets.GITHUB_TOKEN }}.
Be sure to store your giphy-api-key in GitHub Secrets to keep it secure.

3. Install Dependencies

Install the GitHub Actions Toolkit and Giphy client:
Here’s a quick reference of what each package does: Check your package.json to confirm these are listed under dependencies.

4. Write the Action Code

In index.js, import the necessary modules, fetch a random “thank you” GIF, and post it as a comment on the pull request:
The image shows a GitHub repository page for "docker-action-pr-giphy-comment," displaying files like Dockerfile, README.md, and action.yml, along with recent commit activity.

5. Bundle with ncc

To avoid committing node_modules, bundle your code and dependencies into a single file using Vercel ncc:
ncc produces dist/index.js with your action logic and all dependencies. This simplifies deployment.

6. Ignore Unnecessary Files

Add a .gitignore to keep your repository clean:

7. Publish to GitHub

Initialize and push your project:
The image shows a GitHub interface for creating a new repository, with fields for the repository name, description, visibility options, and initialization settings.
After pushing, your repository will look like this:
The image shows a GitHub repository page titled "js-action-pr-giphy-comment," displaying files like .gitignore, README.md, and index.js. The repository is public with no stars or forks.

You’ve now successfully created, bundled, and published a JavaScript GitHub Action. Next, tag a release and submit it to the GitHub Marketplace so others can use it!

Watch Video