Fix ci and added cloudflare deployment #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Cloudflare Worker | |
| on: | |
| push: | |
| branches: [main, master] | |
| paths: | |
| - 'worker/**' | |
| - '.github/workflows/deploy-worker.yml' | |
| pull_request: | |
| branches: [main, master] | |
| paths: | |
| - 'worker/**' | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Deployment environment' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| - staging | |
| permissions: | |
| contents: read | |
| env: | |
| NODE_VERSION: '20' | |
| jobs: | |
| deploy-worker: | |
| name: Deploy Worker to Cloudflare | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: latest | |
| - name: Cache Bun global packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.bun/install/global | |
| key: ${{ runner.os }}-bun-global-wrangler | |
| restore-keys: | | |
| ${{ runner.os }}-bun-global- | |
| - name: Install Wrangler CLI | |
| run: bun install -g wrangler | |
| - name: Verify Worker configuration | |
| run: | | |
| cd worker | |
| if [ -f "wrangler.toml" ]; then | |
| echo "Worker configuration found" | |
| wrangler whoami | |
| echo "✅ Worker setup validation passed" | |
| else | |
| echo "❌ Worker configuration not found" | |
| exit 1 | |
| fi | |
| - name: Deploy Worker (Production) | |
| if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'production') | |
| run: | | |
| cd worker | |
| wrangler deploy --env production | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Deploy Worker (Staging) | |
| if: github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.environment == 'staging') | |
| run: | | |
| cd worker | |
| wrangler deploy --env staging | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Worker Deployment Summary | |
| run: | | |
| ENVIRONMENT="production" | |
| if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event.inputs.environment }}" = "staging" ]; then | |
| ENVIRONMENT="staging" | |
| fi | |
| echo "## 🎉 Worker Deployment Successful!" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "Your Cloudflare Worker has been deployed successfully." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### Deployment Information" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Environment**: $ENVIRONMENT" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit**: ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Deploy Time**: $(date -u)" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "### API Endpoints" >> $GITHUB_STEP_SUMMARY | |
| echo "- Health Check: \`/api/health\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- Search Suggestions: \`/api/search/suggestions?q=query\`" >> $GITHUB_STEP_SUMMARY | |
| echo "- Analytics: \`/api/analytics/event\` (POST)" >> $GITHUB_STEP_SUMMARY | |
| echo "- Feedback: \`/api/feedback\` (POST)" >> $GITHUB_STEP_SUMMARY |