Cleaner github actions organization #2
Workflow file for this run
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 Preview Environment | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| check: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: ./.github/actions/check | |
| deploy: | |
| needs: check | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: preview | |
| url: https://startkit-preview-pr-${{ github.event.number }}.startkit-dev.workers.dev | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - uses: ./.github/actions/setup | |
| - name: Setup preview database and run migrations | |
| id: setup-db | |
| run: ./scripts/setup-preview-db.sh ${{ github.event.number }} | |
| env: | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| - name: Build application | |
| run: bun run build | |
| env: | |
| BETTER_AUTH_URL: ${{ vars.BETTER_AUTH_URL || format('https://startkit-preview-pr-{0}.startkit-dev.workers.dev', github.event.number) }} | |
| BETTER_AUTH_SECRET: ${{ secrets.BETTER_AUTH_SECRET }} | |
| GITHUB_CLIENT_ID: ${{ secrets.OAUTH_GITHUB_CLIENT_ID }} | |
| GITHUB_CLIENT_SECRET: ${{ secrets.OAUTH_GITHUB_CLIENT_SECRET }} | |
| - name: Create temporary wrangler config for preview | |
| run: | | |
| cat > wrangler.preview.jsonc << EOF | |
| { | |
| "name": "startkit-preview-pr-${{ github.event.number }}", | |
| "main": "@tanstack/react-start/server-entry", | |
| "compatibility_date": "2025-09-24", | |
| "compatibility_flags": ["nodejs_compat"], | |
| "observability": { | |
| "enabled": true | |
| }, | |
| "vars": { | |
| "BETTER_AUTH_URL": "${{ vars.BETTER_AUTH_URL || format('https://startkit-preview-pr-{0}.startkit-dev.workers.dev', github.event.number) }}", | |
| "GITHUB_CLIENT_ID": "${{ secrets.OAUTH_GITHUB_CLIENT_ID }}" | |
| }, | |
| "d1_databases": [ | |
| { | |
| "binding": "DB", | |
| "database_name": "startkit-preview-pr-${{ github.event.number }}", | |
| "database_id": "${{ env.DB_ID }}" | |
| } | |
| ] | |
| } | |
| EOF | |
| - name: Deploy to Cloudflare Workers | |
| id: deploy | |
| uses: cloudflare/wrangler-action@v3 | |
| with: | |
| apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| command: deploy --config wrangler.preview.jsonc | |
| - name: Comment PR with deployment info | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `🚀 **Preview deployment is ready!** | |
| **Preview URL:** ${{ steps.deploy.outputs.deployment-url }} | |
| **Database:** startkit-preview-pr-${{ github.event.number }} | |
| This preview will be automatically deleted when the PR is closed.` | |
| }) |