This document explains how to set up automatic deployment to Cloudflare Workers via GitHub Actions.
The project is configured to automatically deploy to Cloudflare Workers whenever code is pushed to the main branch.
Workflow file: .github/workflows/deploy.yml
You need to add two secrets to your GitHub repository:
What it is: API token that allows GitHub Actions to deploy to your Cloudflare account
How to get it:
- Go to https://dash.cloudflare.com/profile/api-tokens
- Click "Create Token"
- Use the "Edit Cloudflare Workers" template (or create custom token with these permissions):
- Account: Workers Scripts (Edit)
- Account: Workers KV Storage (Edit)
- Account: D1 (Edit)
- Account: Vectorize (Edit)
- Account: Analytics Engine (Edit)
- Select your account under "Account Resources"
- Click "Continue to summary" → "Create Token"
- Copy the token (you won't be able to see it again!)
Add to GitHub:
- Go to your GitHub repo → Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
CLOUDFLARE_API_TOKEN - Value: paste the token you copied
- Click "Add secret"
What it is: Your Cloudflare account ID
How to get it:
- Go to https://dash.cloudflare.com/
- Select any website (or Workers & Pages)
- Look for "Account ID" in the right sidebar (or scroll down)
- Copy the account ID (format:
1234567890abcdef1234567890abcdef)
Add to GitHub:
- Go to your GitHub repo → Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
CLOUDFLARE_ACCOUNT_ID - Value: paste your account ID
- Click "Add secret"
Every time you push to main:
git add .
git commit -m "Your commit message"
git push origin mainGitHub Actions will automatically:
- Check out the code
- Install dependencies
- Build the frontend (
npm run build) - Deploy to Cloudflare Workers using wrangler
You can also trigger deployment manually:
- Go to your GitHub repo → Actions tab
- Click "Deploy to Cloudflare Workers" workflow
- Click "Run workflow" → select branch → "Run workflow"
- Go to your GitHub repo → Actions tab
- Click on the latest workflow run
- View logs for each step
- Go to https://dash.cloudflare.com/
- Navigate to Workers & Pages
- Click on
threat-intel-dashboard - View deployment history, logs, and metrics
Problem: Invalid or expired API token
Solution:
- Create a new API token (see steps above)
- Update
CLOUDFLARE_API_TOKENsecret in GitHub
Problem: Incorrect account ID
Solution:
- Double-check your account ID from Cloudflare dashboard
- Update
CLOUDFLARE_ACCOUNT_IDsecret in GitHub
Problem: Browser caching
Solution:
- Hard refresh (Ctrl+Shift+R or Cmd+Shift+R)
- Check Cloudflare Workers dashboard to verify deployment time
Problem: package-lock.json out of sync with package.json
Solution:
rm package-lock.json
npm install
git add package-lock.json
git commit -m "Fix package-lock.json"
git pushThe workflow runs on:
- Push to main: Automatic deployment
- Manual trigger: Via GitHub Actions UI
File: .github/workflows/deploy.yml
name: Deploy to Cloudflare Workers
on:
push:
branches:
- main
workflow_dispatch: # Allow manual trigger
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build frontend
run: npm run build
- name: Deploy to Cloudflare Workers
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}If you prefer manual deployment:
npm run deployThis builds and deploys directly from your local machine.
- Never commit API tokens to the repository
- Use GitHub Secrets for all sensitive values
- Rotate API tokens periodically (every 90 days recommended)
- Use scoped tokens with minimum required permissions
- Enable 2FA on your Cloudflare account
- ✅ Add
CLOUDFLARE_API_TOKENto GitHub Secrets - ✅ Add
CLOUDFLARE_ACCOUNT_IDto GitHub Secrets - ✅ Push code to main branch
- ✅ Verify deployment in GitHub Actions
- ✅ Test the deployed application
Status: Ready to deploy automatically on push to main! 🚀