-
Notifications
You must be signed in to change notification settings - Fork 10
Add relay crawler worker and GitHub Actions workflows #318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
c1b646e
1173e62
cb5771c
6440dc2
32637e0
a21b40f
72123d9
dbbc57b
1cc5092
adaba25
666a810
d94e8fc
385842d
73c672f
4a39c23
06febef
819d395
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
|
|
||
| # Push Notification Configuration | ||
| VITE_WORKER_URL=https://your-worker-url.workers.dev | ||
| VITE_VAPID_PUBLIC_KEY=your-vapid-public-key-here | ||
| EOF 2>&1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,228 @@ | ||
| name: Deploy Relay Crawler | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - 'worker/cloudflare-worker/src/relay-crawler-worker.ts' | ||
| - 'worker/cloudflare-worker/wrangler-crawler.toml' | ||
| - '.github/workflows/deploy-relay-crawler.yml' | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| paths: | ||
| - 'worker/cloudflare-worker/src/relay-crawler-worker.ts' | ||
| - 'worker/cloudflare-worker/wrangler-crawler.toml' | ||
| workflow_dispatch: | ||
| inputs: | ||
| environment: | ||
| description: 'Deployment environment' | ||
| required: true | ||
| default: 'production' | ||
| type: choice | ||
| options: | ||
| - development | ||
| - staging | ||
| - production | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Test Relay Crawler | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: worker/cloudflare-worker/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm ci | ||
|
|
||
| - name: Type check | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm run typecheck | ||
|
|
||
| - name: Lint | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm run lint || true | ||
|
|
||
| deploy-staging: | ||
| name: Deploy to Staging | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.event_name == 'pull_request' | ||
| environment: | ||
| name: staging | ||
| url: https://relay-crawler-staging.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev | ||
| steps: | ||
|
Comment on lines
+60
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
-environment:
- name: staging
- url: https://relay-crawler-staging.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev
+environment: staging # URL configured in repo Settings → Environments🧰 Tools🪛 actionlint (1.7.7)62-62: context "secrets" is not allowed here. available contexts are "env", "github", "inputs", "job", "matrix", "needs", "runner", "steps", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details (expression) 🤖 Prompt for AI Agents |
||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: worker/cloudflare-worker/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm ci | ||
|
|
||
| - name: Deploy to Cloudflare Workers (Staging) | ||
| uses: cloudflare/wrangler-action@v3 | ||
| with: | ||
| apiToken: ${{ secrets.CF_API_TOKEN }} | ||
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
| workingDirectory: worker/cloudflare-worker | ||
| command: deploy --env staging -c wrangler-crawler.toml | ||
| secrets: | | ||
| WORKER_AUTH_TOKEN | ||
| env: | ||
| WORKER_AUTH_TOKEN: ${{ secrets.WORKER_AUTH_TOKEN_STAGING }} | ||
|
|
||
| - name: Test deployment | ||
| run: | | ||
| sleep 10 | ||
| response=$(curl -s -w "\n%{http_code}" https://relay-crawler-staging.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev/health) | ||
| status_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | head -n-1) | ||
|
|
||
| echo "Response: $body" | ||
| echo "Status code: $status_code" | ||
|
|
||
| if [ "$status_code" != "200" ]; then | ||
| echo "Health check failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if response is valid JSON | ||
| echo "$body" | jq . | ||
|
|
||
| deploy-production: | ||
| name: Deploy to Production | ||
| runs-on: ubuntu-latest | ||
| needs: test | ||
| if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') | ||
| environment: | ||
| name: production | ||
| url: https://relay-crawler-prod.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev | ||
| steps: | ||
|
Comment on lines
+112
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Same invalid 🧰 Tools🪛 actionlint (1.7.7)115-115: context "secrets" is not allowed here. available contexts are "env", "github", "inputs", "job", "matrix", "needs", "runner", "steps", "strategy", "vars". see https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability for more details (expression) 🤖 Prompt for AI Agents |
||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: worker/cloudflare-worker/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm ci | ||
|
|
||
| - name: Deploy to Cloudflare Workers (Production) | ||
| uses: cloudflare/wrangler-action@v3 | ||
| with: | ||
| apiToken: ${{ secrets.CF_API_TOKEN }} | ||
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
| workingDirectory: worker/cloudflare-worker | ||
| command: deploy --env production -c wrangler-crawler.toml | ||
| secrets: | | ||
| WORKER_AUTH_TOKEN | ||
| env: | ||
| WORKER_AUTH_TOKEN: ${{ secrets.WORKER_AUTH_TOKEN_PRODUCTION }} | ||
|
|
||
| - name: Test deployment | ||
| run: | | ||
| sleep 10 | ||
| response=$(curl -s -w "\n%{http_code}" https://relay-crawler-prod.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev/health) | ||
| status_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | head -n-1) | ||
|
|
||
| echo "Response: $body" | ||
| echo "Status code: $status_code" | ||
|
|
||
| if [ "$status_code" != "200" ]; then | ||
| echo "Health check failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Check if response is valid JSON and service is 'relay-crawler' | ||
| echo "$body" | jq . | ||
| service=$(echo "$body" | jq -r .service) | ||
| if [ "$service" != "relay-crawler" ]; then | ||
| echo "Unexpected service: $service" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Send deployment notification | ||
| if: success() | ||
| run: | | ||
| echo "✅ Relay Crawler deployed successfully to production!" | ||
| # Add Slack/Discord notification here if needed | ||
|
|
||
| deploy-manual: | ||
| name: Manual Deploy | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'workflow_dispatch' | ||
| environment: | ||
| name: ${{ github.event.inputs.environment }} | ||
| url: https://relay-crawler-${{ github.event.inputs.environment == 'production' && 'prod' || github.event.inputs.environment }}.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: worker/cloudflare-worker/package-lock.json | ||
|
|
||
| - name: Install dependencies | ||
| working-directory: worker/cloudflare-worker | ||
| run: npm ci | ||
|
|
||
| - name: Deploy to Cloudflare Workers | ||
| uses: cloudflare/wrangler-action@v3 | ||
| with: | ||
| apiToken: ${{ secrets.CF_API_TOKEN }} | ||
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | ||
| workingDirectory: worker/cloudflare-worker | ||
| command: deploy ${{ github.event.inputs.environment != 'development' && format('--env {0}', github.event.inputs.environment) || '' }} -c wrangler-crawler.toml | ||
| secrets: | | ||
| WORKER_AUTH_TOKEN | ||
| env: | ||
| WORKER_AUTH_TOKEN: ${{ github.event.inputs.environment == 'production' && secrets.WORKER_AUTH_TOKEN_PRODUCTION || secrets.WORKER_AUTH_TOKEN_STAGING }} | ||
|
|
||
| - name: Test deployment | ||
| run: | | ||
| sleep 10 | ||
| if [ "${{ github.event.inputs.environment }}" = "production" ]; then | ||
| url="https://relay-crawler-prod.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev/health" | ||
| elif [ "${{ github.event.inputs.environment }}" = "staging" ]; then | ||
| url="https://relay-crawler-staging.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev/health" | ||
| else | ||
| url="https://relay-crawler.${{ secrets.CF_ACCOUNT_SUBDOMAIN }}.workers.dev/health" | ||
| fi | ||
|
|
||
| echo "Testing: $url" | ||
| response=$(curl -s -w "\n%{http_code}" "$url") | ||
| status_code=$(echo "$response" | tail -n1) | ||
| body=$(echo "$response" | head -n-1) | ||
|
|
||
| echo "Response: $body" | ||
| echo "Status code: $status_code" | ||
|
|
||
| if [ "$status_code" != "200" ]; then | ||
| echo "Health check failed" | ||
| exit 1 | ||
| fi | ||
Uh oh!
There was an error while loading. Please reload this page.