|
| 1 | +# Cloudflare Workers - Deployment Setup |
| 2 | + |
| 3 | +This directory contains Cloudflare Workers that are automatically deployed via GitHub Actions. |
| 4 | + |
| 5 | +## Structure |
| 6 | + |
| 7 | +Each worker lives in its own subdirectory with: |
| 8 | +- `worker.js` - The worker code |
| 9 | +- `wrangler.toml` - Configuration file |
| 10 | + |
| 11 | +## Current Workers |
| 12 | + |
| 13 | +### gumroad-products |
| 14 | +- **Location**: `cloudflare-workers/gumroad-products/` |
| 15 | +- **Purpose**: Fetch products from a Gumroad user profile page |
| 16 | + |
| 17 | +## Setup Instructions |
| 18 | + |
| 19 | +### 1. Install Wrangler CLI (Optional - for local development) |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install -g wrangler |
| 23 | +``` |
| 24 | + |
| 25 | +### 2. Configure GitHub Secrets |
| 26 | + |
| 27 | +Add these secrets to your GitHub repository at Settings → Secrets and variables → Actions: |
| 28 | + |
| 29 | +- `CLOUDFLARE_API_TOKEN` - Create at https://dash.cloudflare.com/profile/api-tokens |
| 30 | + - Use the "Edit Cloudflare Workers" template |
| 31 | + - Or create custom token with these permissions: |
| 32 | + - Account > Workers Scripts > Edit |
| 33 | + - Account > Account Settings > Read |
| 34 | + |
| 35 | +- `CLOUDFLARE_ACCOUNT_ID` - Your account ID |
| 36 | + |
| 37 | +### 3. Configure Worker Environment Variables |
| 38 | + |
| 39 | +The github-auth worker requires these environment variables (secrets): |
| 40 | + |
| 41 | +```bash |
| 42 | +# Set these in Cloudflare Dashboard or via Wrangler CLI |
| 43 | +wrangler secret put GITHUB_CLIENT_ID --env production |
| 44 | +wrangler secret put GITHUB_CLIENT_SECRET --env production |
| 45 | +wrangler secret put GITHUB_REDIRECT_URI --env production |
| 46 | +``` |
| 47 | + |
| 48 | +Or set them in the Cloudflare Dashboard. |
| 49 | + |
| 50 | +## Automatic Deployment |
| 51 | + |
| 52 | +The GitHub Actions workflow (`.github/workflows/deploy-cloudflare-workers.yml`) will automatically deploy workers when: |
| 53 | + |
| 54 | +1. Changes are pushed to the `main` branch |
| 55 | +2. Files in `cloudflare-workers/**` are modified |
| 56 | +3. The workflow is manually triggered |
| 57 | + |
| 58 | +Each worker is deployed independently - only workers with changed files are deployed. |
| 59 | + |
| 60 | +## Manual Deployment |
| 61 | + |
| 62 | +To deploy manually from your local machine: |
| 63 | + |
| 64 | +```bash |
| 65 | +cd cloudflare-workers/github-auth |
| 66 | +wrangler deploy --env production |
| 67 | +``` |
| 68 | + |
| 69 | +You'll need to authenticate with Wrangler first: |
| 70 | +```bash |
| 71 | +wrangler login |
| 72 | +``` |
| 73 | + |
| 74 | +## Adding New Workers |
| 75 | + |
| 76 | +To add a new worker to this monorepo: |
| 77 | + |
| 78 | +1. Create a new directory: `cloudflare-workers/your-worker-name/` |
| 79 | +2. Add your worker code as `worker.js` |
| 80 | +3. Create a `wrangler.toml` configuration (copy from github-auth as template) |
| 81 | +4. Add a new job to `.github/workflows/deploy-cloudflare-workers.yml` (see commented example) |
| 82 | +5. Push to main branch |
| 83 | + |
| 84 | +## Local Development |
| 85 | + |
| 86 | +To test a worker locally: |
| 87 | + |
| 88 | +```bash |
| 89 | +cd cloudflare-workers/your-worker-name |
| 90 | +wrangler dev |
| 91 | +``` |
| 92 | + |
| 93 | +This starts a local server at http://localhost:8787 |
| 94 | + |
| 95 | +## Troubleshooting |
| 96 | + |
| 97 | +### Deployment fails in GitHub Actions |
| 98 | +- Check that secrets are properly configured |
| 99 | +- Verify the worker name in `wrangler.toml` matches your Cloudflare worker |
| 100 | +- Check the Actions logs for specific error messages |
| 101 | + |
| 102 | +### "Unauthorized" errors |
| 103 | +- Regenerate your CLOUDFLARE_API_TOKEN with correct permissions |
| 104 | +- Ensure the token hasn't expired |
| 105 | + |
| 106 | +### Worker not updating |
| 107 | +- Check the GitHub Actions logs to see if deployment ran |
| 108 | +- Verify the file path filter in the workflow matches your changed files |
| 109 | +- Try manually triggering the workflow |
0 commit comments