Skip to content

Cleaner github actions organization #19

Cleaner github actions organization

Cleaner github actions organization #19

Workflow file for this run

name: Preview Deploy
# Requires repository secrets:
# - CLOUDFLARE_ACCOUNT_ID: Cloudflare account ID for the worker.
# - CLOUDFLARE_API_TOKEN: Token with Workers Scripts Edit permissions.
#
# Requires preview environment variables:
# - OAUTH_GITHUB_CLIENT_ID: GitHub OAuth app client ID
#
# Requires preview environment secrets:
# - BETTER_AUTH_SECRET: Better Auth secret key
# - OAUTH_GITHUB_CLIENT_SECRET: GitHub OAuth app client secret
on:
pull_request:
types: [opened, reopened, synchronize]
permissions:
contents: read
pull-requests: write
jobs:
upload-preview:
name: Upload Worker Preview
runs-on: ubuntu-latest
environment: preview
env:
PR_ALIAS: pr-${{ github.event.number }}
WORKER_NAME: startkit-preview
WORKER_SUBDOMAIN: blendist
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Install dependencies
uses: ./.github/actions/setup
- name: Run code quality checks
run: bun run check
- name: Build project
run: bun run build
env:
CLOUDFLARE_ENV: preview
BETTER_AUTH_URL: ${{ format('https://{0}-{1}.{2}.workers.dev', env.PR_ALIAS, env.WORKER_NAME, env.WORKER_SUBDOMAIN) }}
OAUTH_GITHUB_CLIENT_ID: ${{ vars.OAUTH_GITHUB_CLIENT_ID }}
- name: Run database migrations
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: d1 migrations apply DB --remote --env preview
packageManager: bun
- name: Upload preview Worker
id: wrangler
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: versions upload --preview-alias ${{ env.PR_ALIAS }}
packageManager: bun
env:
CLOUDFLARE_ENV: preview
BETTER_AUTH_SECRET: ${{ secrets.BETTER_AUTH_SECRET }}
BETTER_AUTH_URL: ${{ format('https://{0}-{1}.{2}.workers.dev', env.PR_ALIAS, env.WORKER_NAME, env.WORKER_SUBDOMAIN) }}
OAUTH_GITHUB_CLIENT_ID: ${{ vars.OAUTH_GITHUB_CLIENT_ID }}
OAUTH_GITHUB_CLIENT_SECRET: ${{ secrets.OAUTH_GITHUB_CLIENT_SECRET }}
- name: Find existing comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.number }}
comment-author: "github-actions[bot]"
body-includes: "<!-- ${{ env.WORKER_NAME }} -->"
- name: Comment preview link
if: success()
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: |
<!-- ${{ env.WORKER_NAME }} -->
**Preview Deployment**
- Version Preview URL: ${{ steps.wrangler.outputs.deployment-url }}
- Version Preview Alias URL: ${{ format('[https://{0}-{1}.{2}.workers.dev](https://{0}-{1}.{2}.workers.dev)', env.PR_ALIAS, env.WORKER_NAME, env.WORKER_SUBDOMAIN) }}
edit-mode: replace