Skip to main content
In this tutorial, you’ll build a custom Docker Action that:
  1. Triggers when a pull request is opened.
  2. Fetches a random “thank you” GIF from Giphy.
  3. Posts a comment with the GIF on the PR using the GitHub REST API.
This pattern can be adapted to any third-party API integration.

External APIs

We rely on two REST APIs:

Giphy API: Random GIF Endpoint

Request URL:
Sample response:
The image shows the GIPHY Developers API Explorer interface, where users can input sample queries to test the API. It includes options to choose an app/API key, resource, endpoint, and parameters like tag and rating.

GitHub REST API: Post a Comment

Use the Issues API to add a comment:
The image shows a GitHub documentation page for the REST API, specifically focusing on managing issues, with links to various related actions like creating, updating, and locking issues.

1. Create the Repository

  1. On GitHub, create a new public repo named docker-action-pr-giphy-comment.
  2. Initialize with a README.md.
The image shows a GitHub page for creating a new repository, with fields for the repository name, description, and visibility options.
After creation, you’ll see the default commit:
The image shows a GitHub repository page titled "docker-action-pr-giphy-comment" with an initial commit and a README file. The repository has no stars, forks, or releases.

Add Giphy API Key as a Secret

  1. Go to Settings → Secrets and variables → Actions.
  2. Add a new secret GIPHY_API_KEY with your Giphy API key.
Keep your secrets safe. Never hard-code API keys in your code or Docker image.
The image shows a GitHub repository settings page where a new secret is being added under "Actions secrets." The secret is named "GIPHY_API_KEY."
Once saved, the secret appears in the list:
The image shows a GitHub repository settings page, specifically the "Secrets and variables" section, with a repository secret named "GIPHY_API_KEY" listed.

2. Define the Action Structure

In your repo root, create:
  • Dockerfile
  • entrypoint.sh
  • action.yml

Dockerfile

Entrypoint Script (entrypoint.sh)

This script retrieves a GIF and posts a comment on the PR:
Make it executable:

Action Metadata (action.yml)


3. Test Your Action

Create a test workflow at .github/workflows/test.yml:
Create the workflow folder:
The image shows a Visual Studio Code interface with a project open, displaying a file explorer on the left and a README.md file in the main editor area. The project appears to involve Docker and GitHub workflows.

4. Commit, Push, and Trigger

  1. Commit all changes and push to GitHub.
  2. Edit README.md on a new branch and open a pull request.
The image shows a GitHub repository interface where a user is editing the README.md file in a project named "docker-action-pr-giphy-comment."
The image shows a GitHub interface where a user is proposing changes to a README.md file, with options to commit directly or create a new branch.
When the PR opens, your action runs automatically:
The image shows a GitHub Actions interface for a project named "Solar System Workflow," displaying a list of workflow runs with details such as event triggers, status, and branch information.
The image shows a GitHub Actions interface with a successful workflow run named "testing-action," detailing steps like setting up a job, checking out a repository, and posting a PR comment.
You’ll see a comment from the github-actions bot on your pull request:
The image shows a GitHub Actions interface with a successful workflow run, displaying logs and details of a "testing-action" job, including environment variables and a Giphy API response.

Next Steps

You’ve built and tested a Docker-based GitHub Action that posts Giphy comments on PRs. To take it further:
  • Publish your action to the GitHub Marketplace.
  • Consume the published action in other repositories.

Watch Video