Skip to content

[WEB] Use auto format globally and fix profile og image; fixes BAF-388 #257

[WEB] Use auto format globally and fix profile og image; fixes BAF-388

[WEB] Use auto format globally and fix profile og image; fixes BAF-388 #257

Workflow file for this run

name: Test & Deploy
on:
push:
paths:
- './package.json'
- .github/workflows/deploy.yml
- 'web/**'
- 'packages/**'
env:
NEON_API_KEY: ${{ secrets.NEON_API_KEY }}
concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
jobs:
deploy-preview:
name: 'Deploy to Preview'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
outputs:
database-id: ${{ steps.create-db.outputs.branch_id }}
preview-url: ${{ steps.vercel-deploy.outputs.preview_url }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install CLI deps
run: npm install -g neonctl vercel@latest
- name: Destroy previously missed database branches
run: |
neonctl branches list -o json \
| jq '.[].name | select(. | startswith("github-deploy-${{ github.ref_name }}"))' -c \
| xargs -I % neonctl branches delete %
- name: Create database branch
uses: neondatabase/create-branch-action@v4
with:
project_id: wandering-sound-489458
api_key: ${{ secrets.NEON_API_KEY }}
branch_name: github-deploy-${{ github.ref_name }}-${{ github.run_id}}-${{ github.run_attempt }}
database: books-about-food-prod
id: create-db
- name: Deploy preview to Vercel
id: vercel-deploy
env:
VERCEL_ORG_ID: ${{ secrets.BAF_VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.BAF_VERCEL_PROJECT_ID }}
run: |
db_url=$(neonctl cs ${{ steps.create-db.outputs.branch_id }} --database-name books-about-food-prod --prisma --pooled)
direct_db_url=$(neonctl cs ${{ steps.create-db.outputs.branch_id }} --database-name books-about-food-prod --prisma)
preview_url=$(vercel \
--token=${{ secrets.VERCEL_DEPLOY_TOKEN }} \
--scope=radical-innovation \
--meta githubCommitAuthorName=${{ github.actor }} \
--meta githubCommitAuthorLogin=${{ github.actor }} \
--meta githubCommitMessage="${{ github.event.head_commit.message }}" \
--meta githubCommitOrg=${{ github.repository_owner }} \
--meta githubCommitRepo=books-about-food \
--meta githubCommitRef=${{ github.ref_name }} \
--meta githubCommitSha=${{ github.sha }} \
--meta githubOrg=samtgarson \
--meta githubRepo=books-about-food \
--meta githubDeployment=1 \
--build-env DATABASE_URL="$db_url" \
--build-env DATABASE_DIRECT_URL="$direct_db_url" \
--env DATABASE_URL="$db_url" \
--env DATABASE_DIRECT_URL="$direct_db_url" \
)
if [ -z "$preview_url" ]
then
echo "Preview URL not found"
exit 1
else
echo "preview_url=$preview_url" >> $GITHUB_OUTPUT
vercel alias $preview_url \
books-about-food-git-${{ github.ref_name }}.vercel.app \
--scope=radical-innovation \
--token=${{ secrets.VERCEL_DEPLOY_TOKEN }}
fi
test:
name: 'Run E2E tests'
needs: [deploy-preview]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies and get database url
id: install-deps
run: |
npm -w packages/e2e ci
npm i -g neonctl
echo "database-url=$(neonctl cs ${{ needs.deploy-preview.outputs.database-id }} --database-name books-about-food-prod --prisma --pooled)" >> $GITHUB_OUTPUT
echo "database-direct-url=$(neonctl cs ${{ needs.deploy-preview.outputs.database-id }} --database-name books-about-food-prod --prisma)" >> $GITHUB_OUTPUT
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- name: Get installed Playwright version
id: playwright-version
run: echo "PLAYWRIGHT_VERSION=$(npm why @playwright/test --json | jq '.[0].version' -r)" >> $GITHUB_ENV
- name: Cache playwright binaries
uses: actions/cache@v4
id: playwright-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright browsers
run: npx playwright install --with-deps chromium
if: steps.playwright-cache.outputs.cache-hit != 'true'
- name: Generate Prisma client
run: npm run -w packages/database db:build
env:
DATABASE_URL: ${{ steps.install-deps.outputs.database-url }}
DATABASE_DIRECT_URL: ${{ steps.install-deps.outputs.database-direct-url }}
- name: Create Gmail secret files
run: |
echo ${{ secrets.GMAIL_CREDENTIALS_JSON }} | base64 -d > ./packages/e2e/gmail-credentials.json
echo ${{ secrets.GMAIL_TOKEN_JSON }} | base64 -d > ./packages/e2e/gmail-token.json
- name: Run Playwright tests
run: npx -w packages/e2e playwright test
env:
DEPLOYMENT_URL: ${{ needs.deploy-preview.outputs.preview-url }}
DATABASE_URL: ${{ steps.install-deps.outputs.database-url }}
DATABASE_DIRECT_URL: ${{ steps.install-deps.outputs.database-direct-url }}
NEXTAUTH_SECRET: ${{ secrets.AUTH_SECRET }}
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: packages/e2e/test-results
retention-days: 10
deploy-prod:
name: 'Deploy to Production'
needs: [deploy-preview, test]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
env:
VERCEL_ORG_ID: ${{ secrets.BAF_VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.BAF_VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Deploy production to Vercel
id: vercel-deploy
if: always()
uses: BetaHuhn/deploy-to-vercel-action@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERCEL_TOKEN: ${{ secrets.VERCEL_DEPLOY_TOKEN }}
VERCEL_ORG_ID: ${{ secrets.BAF_VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.BAF_VERCEL_PROJECT_ID }}
VERCEL_SCOPE: 'radical-innovation'
PRODUCTION: true
CREATE_COMMENT: false
GITHUB_DEPLOYMENT: true
cleanup:
name: 'Clean Up'
needs: [deploy-preview, test, deploy-prod]
runs-on: ubuntu-latest
if: ${{ always() && github.run_attempt == 1 && github.ref == 'refs/heads/main' }}
env:
VERCEL_ORG_ID: ${{ secrets.BAF_VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.BAF_VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install CLI deps
run: npm install --global vercel@latest neonctl
- name: Remove preview deployment
if: ${{ needs.deploy-preview.outputs.preview-url }}
run: vercel rm ${{ needs.deploy-preview.outputs.preview-url }} --token=${{ secrets.VERCEL_DEPLOY_TOKEN }} --scope=radical-innovation --yes || true
- name: Remove database branch
if: ${{ needs.deploy-preview.outputs.database-id }}
run: neonctl branches delete ${{ needs.deploy-preview.outputs.database-id }} || true