Deploy to Cloudflare Pages #330
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
| # Workflow for deploying to Cloudflare Pages | |
| name: Deploy to Cloudflare Pages | |
| on: | |
| # Runs on pushes targeting the default branch | |
| push: | |
| branches: ["main"] | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| # Runs daily at 03:30AM UTC (09:00AM IST) | |
| schedule: | |
| - cron: "30 3 * * *" | |
| # Sets permissions of the GITHUB_TOKEN to allow commiting to repository and deployment to Cloudflare Pages | |
| permissions: | |
| contents: write | |
| deployments: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| fetch: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| database-changed: ${{ steps.auto-commit-action.outputs.changes_detected }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # Install dependencies | |
| - name: Install Python dependencies | |
| run: python -m pip install --upgrade pip pandas openpyxl | |
| # Fetch database and commit JSON changes to repository | |
| - name: Fetch Google Sheet | |
| run: curl -L 'https://docs.google.com/spreadsheets/d/1lsXt4nXsz9k52bW79KxSLRK3Lg30z8U9AcuPNUHUVNY/export?exportFormat=xlsx' -o ./scripts/officials.xlsx | |
| - name: Save as JSON | |
| run: python ./scripts/xls2json.py | |
| - id: auto-commit-action | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: Fetch database from Google Sheets | |
| deploy: | |
| needs: fetch | |
| if: github.event_name != 'schedule' || needs.fetch.outputs.database-changed == 'true' | |
| environment: | |
| name: cf-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| # Install dependencies | |
| - name: Install pnpm | |
| uses: pnpm/action-setup@v3 | |
| with: | |
| version: 9 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: pnpm | |
| - name: Install dependencies | |
| run: pnpm install | |
| # Build and deploy to Cloudflare Pages | |
| - name: Build site | |
| run: pnpm run build | |
| env: | |
| VITE_GMAPS_API_KEY: ${{ secrets.VITE_GMAPS_API_KEY }} | |
| VITE_GOOGLE_ANALYTICS_ID: ${{ secrets.VITE_GOOGLE_ANALYTICS_ID }} | |
| - name: Deploy to Cloudflare Pages | |
| uses: cloudflare/pages-action@v1 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| projectName: 'boundaries-vonter' | |
| directory: '.svelte-kit/cloudflare' | |
| gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
| branch: 'master' |