A lightweight Cloudflare Workers implementation for triggering GitHub repository dispatch events. This webhook service provides a simple and secure way to trigger GitHub Actions workflows remotely.
- Serverless implementation using Cloudflare Workers
- Minimal configuration required
- Secure GitHub token handling
- Dynamic repository targeting via URL path
- Custom event type support via URL path
- Preserves original request headers and body content
- Easy to deploy and maintain
- Cloudflare account
- GitHub account with repository access
- GitHub Personal Access Token with
reposcope
- Fork this repository by clicking the 'Fork' button in the top-right corner
- Go to your forked repository's settings
- Navigate to 'Secrets and variables' → 'Actions'
- Add the following repository secret:
GITHUB_TOKEN: Your GitHub Personal Access Token
- Log in to your Cloudflare dashboard
- Navigate to Workers & Pages
- Create a new Worker
- Copy the content from
_worker.jsto your new Worker - Add Environment Variable in your Worker settings:
GITHUB_TOKEN: Your GitHub Personal Access Token
- Deploy your Worker using the Cloudflare dashboard
- Test the webhook by sending a POST request to your Worker URL:
curl -X POST https://your-worker.your-subdomain.workers.dev/webhook/owner/repo/deploygit clone https://github.com/yourusername/github-dispatch-webhook.git
cd github-dispatch-webhooknpm install -g wranglerIn your Cloudflare Workers dashboard, set the following environment variable:
GITHUB_TOKEN: Your GitHub Personal Access Token
wrangler publishSend a POST request to your worker's URL with the repository and event type in the path:
curl -X POST https://your-worker.your-subdomain.workers.dev/webhook/{owner}/{repo}/{event_type}For example:
# Trigger a 'deploy' event
curl -X POST https://your-worker.your-subdomain.workers.dev/webhook/ray-workspace/cognideep_server/deploy
# Trigger a 'test' event
curl -X POST https://your-worker.your-subdomain.workers.dev/webhook/ray-workspace/cognideep_server/testYou can also include a JSON body that will be forwarded to the GitHub API:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"client_payload": {"environment": "production"}}' \
https://your-worker.your-subdomain.workers.dev/webhook/ray-workspace/cognideep_server/deployname = "github-dispatch-webhook"
main = "_worker.js"
compatibility_date = "2023-01-01"
[vars]
# Only GITHUB_TOKEN is required as an environment variable
# REPO_PATH and event_type are now specified in the URL path- Never commit your GitHub token to the repository
- Use environment variables for sensitive information
- Consider implementing additional authentication for the webhook endpoint
- Regularly rotate your GitHub token
To run locally:
wrangler dev- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any problems or have suggestions, please open an issue in the GitHub repository.
- Cloudflare Workers
- GitHub API