GitHub Actions
Custom Actions
Using a Docker Action in Workflow
Learn how to import and run a Docker-based GitHub Action from one repository in another. In this guide, we’ll reuse the docker-action-pr-giphy-comment
action in the solar-system project to automatically post a GIF response on pull requests.
1. Switch to the Target Repository
Open the solar-system repository where you want to integrate the custom action.
2. Store Your Giphy API Key
To fetch GIFs, the action requires a Giphy API key stored as a secret.
- Navigate to Settings → Secrets and variables → Actions.
- Click New repository secret.
- Name it
GIPHY_API_KEY
and paste your API key.
Warning
Never expose your API keys in code or logs. Repository secrets are encrypted and only available to workflows.
3. Create a Pull Request Workflow
Under .github/workflows/
, add a new file named pr-thank-you-workflow.yml
:
on:
pull_request:
types:
- opened
jobs:
pr-action:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Post GIF Comment
uses: sidd-harth-7/docker-action-pr-giphy-comment@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
giphy-api-key: ${{ secrets.GIPHY_API_KEY }}
Note
Replace sidd-harth-7/docker-action-pr-giphy-comment@main
with your own owner/repo@branch
reference.
Job Configuration
Setting | Value |
---|---|
runs-on | ubuntu-latest |
permissions | issues: write , pull-requests: write |
Commit to a new branch and open a pull request:
4. Monitor the Workflow Execution
Head to the Actions tab to see your workflow run.
Example Build Logs
Docker container actions build an image at runtime:
# Build container for action use: '/home/runner/work/_actions/sidd-harth-7/docker-action-pr-giphy-comment/main/Dockerfile'.
#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 448B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/alpine:3.10
#3 DONE 0.0s
#6 [1/4] FROM docker.io/library/alpine:3.10@sha256:...
#6 DONE 0.1s
#9 [4/4] RUN chmod +x /entrypoint.sh
#9 DONE 0.3s
Then the container runs:
/usr/bin/docker run --name 2d046f464e14829be2791b519b_32bdb \
--label 461cec \
--workdir /github/workspace \
-e "INPUT_GITHUB_TOKEN=" \
-e "INPUT_GIPHY_API_KEY=" \
--rm \
-v /home/runner/work/... \
...
Note
Continuous Docker builds can introduce latency. Consider using a JavaScript action for faster startup.
5. Confirm the GIF Comment
After success, your pull request will display a “Thank you” comment with a GIF:
Links and References
Watch Video
Watch video content