Update README to reflect current architecture #51
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 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Deployment environment' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - staging | |
| - production | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| backend: ${{ steps.filter.outputs.backend }} | |
| frontend: ${{ steps.filter.outputs.frontend }} | |
| environment: ${{ steps.env.outputs.environment }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dorny/paths-filter@v3 | |
| id: filter | |
| with: | |
| filters: | | |
| backend: | |
| - 'backend/**' | |
| frontend: | |
| - 'frontend/**' | |
| - name: Determine environment | |
| id: env | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| echo "environment=staging" >> $GITHUB_OUTPUT | |
| echo "Deploying to STAGING (pull_request event)" | |
| elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
| echo "environment=${{ inputs.environment }}" >> $GITHUB_OUTPUT | |
| echo "Deploying to ${{ inputs.environment }} (workflow_dispatch event)" | |
| else | |
| echo "environment=production" >> $GITHUB_OUTPUT | |
| echo "Deploying to PRODUCTION (push to main)" | |
| fi | |
| deploy-backend: | |
| needs: changes | |
| if: needs.changes.outputs.backend == 'true' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: backend/package-lock.json | |
| - name: Install dependencies | |
| working-directory: backend | |
| run: npm ci | |
| - name: Bootstrap D1 migrations table (staging) | |
| if: needs.changes.outputs.environment == 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: d1 execute skyreader-staging --env=staging --remote --file=migrations/0000_bootstrap.sql | |
| - name: Run D1 migrations (staging) | |
| if: needs.changes.outputs.environment == 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: d1 migrations apply skyreader-staging --env=staging --remote | |
| - name: Deploy Worker (staging) | |
| if: needs.changes.outputs.environment == 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: deploy --env=staging | |
| - name: Bootstrap D1 migrations table (production) | |
| if: needs.changes.outputs.environment != 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: d1 execute skyreader --remote --file=migrations/0000_bootstrap.sql | |
| - name: Run D1 migrations (production) | |
| if: needs.changes.outputs.environment != 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: d1 migrations apply skyreader --remote | |
| - name: Deploy Worker (production) | |
| if: needs.changes.outputs.environment != 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: backend | |
| command: deploy --env="" | |
| deploy-frontend: | |
| needs: changes | |
| if: needs.changes.outputs.frontend == 'true' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Install dependencies | |
| working-directory: frontend | |
| run: npm ci | |
| - name: Build (staging) | |
| if: needs.changes.outputs.environment == 'staging' | |
| working-directory: frontend | |
| env: | |
| VITE_API_URL: https://api-staging.skyreader.app | |
| run: npm run build | |
| - name: Build (production) | |
| if: needs.changes.outputs.environment != 'staging' | |
| working-directory: frontend | |
| env: | |
| VITE_API_URL: https://api.skyreader.app | |
| run: npm run build | |
| - name: Deploy to Cloudflare Pages (staging) | |
| if: needs.changes.outputs.environment == 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: frontend | |
| command: pages deploy build --project-name=skyreader --branch=staging | |
| - name: Deploy to Cloudflare Pages (production) | |
| if: needs.changes.outputs.environment != 'staging' | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| workingDirectory: frontend | |
| command: pages deploy build --project-name=skyreader --branch=main |