Skip to content

Run tests on preview branches #35

Run tests on preview branches

Run tests on preview branches #35

Workflow file for this run

name: Test & Deploy
on:
push:
paths:
- 'web/**'
- 'packages/**'
jobs:
deploy-preview:
name: 'Deploy to Preview'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
deployments: write
outputs:
preview-url: ${{ steps.vercel-deploy.outputs.PREVIEW_URL }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Deploy preview to Vercel
id: vercel-deploy
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: false
CREATE_COMMENT: false
GITHUB_DEPLOYMENT: false
test:
name: 'Run E2E tests'
needs: [deploy-preview]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies
run: npm -w packages/e2e ci
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@v3
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: ${{ secrets.DATABASE_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 --project smoke-tests
env:
DEPLOYMENT_URL: ${{ needs.deploy-preview.outputs.preview-url }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXTAUTH_SECRET: ${{ secrets.AUTH_SECRET }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
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@v3
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install Vercel CLI
run: npm install --global vercel@latest
- name: Remove preview deployment
run: vercel rm ${{ needs.deploy-preview.outputs.preview-url }} --token=${{ secrets.VERCEL_DEPLOY_TOKEN }} --scope=radical-innovation --yes
- name: Deploy production to Vercel
id: vercel-deploy
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