Fix ci and added cloudflare deployment #2
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 Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| - name: Install Wrangler CLI | |
| run: npm install -g wrangler | |
| - name: Validate Worker code | |
| run: | | |
| cd worker | |
| if [ -f "src/index.js" ]; then | |
| echo "Validating JavaScript syntax..." | |
| node -c src/index.js | |
| echo "✅ Worker code validation passed" | |
| else | |
| echo "❌ Worker source file 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 |