Skip to content

Add deploy preview db #4

Add deploy preview db

Add deploy preview db #4

Workflow file for this run

name: Deploy Preview
on: [pull_request]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
NEON_DATABASE_NAME: ${{ secrets.NEON_DATABASE_NAME }}
NEON_DATABASE_USERNAME: ${{ secrets.NEON_DATABASE_USERNAME }}
NEON_PROJECT_ID: ${{ secrets.NEON_PROJECT_ID }}
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
jobs:
deploy-preview:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ">=18.0.0"
cache: "npm"
- run: |
npm install
npm install --global vercel@latest
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Create Neon Branch
id: create-branch
uses: neondatabase/create-branch-action@v5
with:
project_id: ${{ env.NEON_PROJECT_ID }}
parent: main
branch_name: preview/pr-${{ github.event.number }}-${{ steps.branch-name.outputs.current_branch }}
database: ${{ env.NEON_DATABASE_NAME }}
username: ${{ env.NEON_DATABASE_USERNAME }}
api_key: ${{ env.NEON_API_KEY }}
- name: Run Migrations
run: |
touch .env
echo PG_HOST=${{ steps.create-branch.outputs.host }} >> .env
echo PG_DATABASE=${{ env.NEON_DATABASE_NAME }} >> .env
echo PG_USER=${{ env.NEON_DATABASE_USERNAME }} >> .env
echo PG_PASSWORD=${{ steps.create-branch.outputs.password }} >> .env
npm run db:generate
npm run db:push
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ env.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ env.VERCEL_TOKEN }}
- name: Deploy Preview to Vercel
id: deploy
run: echo preview_url=$(vercel deploy --prebuilt --token=${{ env.VERCEL_TOKEN }}) >> $GITHUB_OUTPUT
- name: Comment on Pull Request
uses: thollander/actions-comment-pull-request@v2
with:
GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
message: |
Vercel Preview URL :rocket: : ${{ steps.deploy.outputs.preview_url }}
Neon branch :elephant: : https://console.neon.tech/app/projects/${{ env.NEON_PROJECT_ID }}/branches/${{ steps.create-branch.outputs.branch_id }}