Skip to content

Add comment

Add comment #119

name: Playwright Tests and Deploy to Fly.io
on: push
jobs:
playwright-tests:
name: Playwright Tests
runs-on: ubuntu-latest # or macos-latest, windows-latest
env:
PGHOST: localhost
PGDATABASE: next_js_example_spring_2023
PGUSERNAME: next_js_example_spring_2023
PGPASSWORD: next_js_example_spring_2023
steps:
- name: Start preinstalled PostgreSQL on Ubuntu
run: |
sudo systemctl start postgresql.service
pg_isready
- name: Create database user
run: |
sudo -u postgres psql --command="CREATE USER next_js_example_spring_2023 PASSWORD 'next_js_example_spring_2023'" --command="\du"
- name: Create database and allow user
run: |
sudo -u postgres createdb --owner=next_js_example_spring_2023 next_js_example_spring_2023
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 'latest'
# Use the official setup-node action (sets up Node.js):
# https://github.com/actions/setup-node
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Install SafeQL if not yet installed (eg. on Windows dev machines)
run: grep package.json -e '@ts-safeql/eslint-plugin' || pnpm add @ts-safeql/eslint-plugin libpg-query
- run: pnpm migrate up
# Also generates next-env.d.ts, required for tsc
- name: Build Next.js app
run: pnpm build
- name: Run TypeScript Compiler
run: pnpm tsc
- name: Run ESLint
run: pnpm eslint . --max-warnings 0
- name: Run Stylelint
run: pnpm stylelint '**/*.{css,scss,less,js,tsx}'
# Cache and install Playwright browser binaries, modified version of:
# https://github.com/microsoft/playwright/issues/7249#issuecomment-1154603556
# https://github.com/microsoft/playwright/issues/7249#issuecomment-1385567519
# https://playwrightsolutions.com/playwright-github-action-to-cache-the-browser-binaries/
- name: Get installed Playwright version for cache key
run: echo "PLAYWRIGHT_VERSION=$(yq eval '.version' --output-format=yaml ./node_modules/@playwright/test/package.json)" >> $GITHUB_ENV
- name: Cache Playwright browser binaries
uses: actions/cache@v3
id: playwright-browser-cache
with:
path: |
~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ env.PLAYWRIGHT_VERSION }}
- name: Install Playwright browsers only on cache miss
run: pnpm playwright install --with-deps chromium
if: steps.playwright-browser-cache.outputs.cache-hit != 'true'
- name: Run tests
run: pnpm playwright test
- uses: actions/upload-artifact@v3
if: failure()
with:
name: playwright-screenshots-videos
path: playwright/test-results/
deploy:
name: Deploy to Fly.io
runs-on: ubuntu-latest
needs: playwright-tests
if: github.ref == 'refs/heads/main'
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only