This guide will help you set up automatic deployment of your package tracker from GitHub to Cloudflare Workers.
- A Cloudflare account with Workers enabled
- A GitHub repository with this code
- A Cloudflare D1 database created (already configured in
wrangler.toml)
You'll need two pieces of information from Cloudflare:
Cloudflare API Token:
- Go to Cloudflare Dashboard
- Click "Create Token"
- Use the "Custom token" template
- Configure permissions:
- Zone: Zone.read
- Zone: Zone.zone.edit
- Account: Cloudflare Workers.edit
- Account: D1.edit
- Set Account Resources to "Include - All accounts"
- Click "Continue to summary" and "Create Token"
- Copy the token (you won't see it again!)
Cloudflare Account ID:
- Go to your Cloudflare Dashboard
- Select any domain or go to Workers & Pages
- On the right sidebar, copy your "Account ID"
In your GitHub repository:
- Go to Settings → Secrets and variables → Actions
- Click "New repository secret" and add:
- Name:
CLOUDFLARE_API_TOKEN - Value: Your API token from step 1
- Name:
- Click "New repository secret" and add:
- Name:
CLOUDFLARE_ACCOUNT_ID - Value: Your Account ID from step 1
- Name:
- (Optional) Add your ingest key:
- Name:
INGEST_KEY - Value: A secure random string for API authentication
- Name:
If you need to set environment variables (like INGEST_KEY):
- Go to Cloudflare Workers Dashboard
- Click on your worker (it will be created after first deployment)
- Go to Settings → Variables
- Add environment variables as needed:
- Variable name:
INGEST_KEY - Value: Your secure key
- Variable name:
Your database is already configured in wrangler.toml, but you may need to create it:
# If you need to create the database locally first
wrangler d1 create package-tracker-db
# Run migrations
npm run db:migrateOnce everything is set up:
- Push your code to the
mainormasterbranch - GitHub Actions will automatically:
- Install dependencies
- Run database migrations
- Deploy your worker
You can also deploy manually using:
# Install dependencies
npm install
# Deploy
npm run deploy
# Or run migrations separately
npm run db:migrateAfter deployment, your worker will be available at https://package-tracker.your-subdomain.workers.dev with these endpoints:
GET /event?pkg=PACKAGE_NAME&type=install- Track a package eventGET /ingest?pkg=PACKAGE_NAME&type=install&count=100&key=YOUR_KEY- Bulk ingest dataGET /totals?pkg=PACKAGE_NAME- Get totals for a packageGET /all-totals?key=YOUR_KEY- Get all package totals
- Database errors: Make sure your D1 database exists and migrations have run
- Authentication errors: Check that your API token has the correct permissions
- Deployment fails: Verify your secrets are set correctly in GitHub
- Worker not found: The worker URL will be available after the first successful deployment
You can monitor your deployments:
- GitHub Actions: Check the Actions tab in your repository
- Cloudflare: Monitor logs in the Workers dashboard