Run example apps headless tests in CI 2 #57
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run headless tests on root example apps | |
on: | |
workflow_call: | |
workflow_dispatch: | |
push: | |
paths: | |
- "examples/**" | |
branches: | |
- main | |
- release | |
pull_request: | |
# paths: | |
# - "examples/**" | |
env: | |
WASP_TELEMETRY_DISABLE: 1 | |
defaults: | |
run: | |
shell: bash | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
setup-and-cache-playwright: | |
name: Setup and Cache Playwright | |
runs-on: ubuntu-22.04 | |
outputs: | |
playwright-version: ${{ steps.get-playwright-version.outputs.version }} | |
steps: | |
- uses: "actions/checkout@v4" | |
with: | |
# Workaround for a Github Checkout action bug | |
# https://github.com/actions/checkout/issues/1359#issuecomment-1567902034 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Get Playwright Version from Waspello Example App | |
id: get-playwright-version | |
working-directory: examples/waspello | |
run: | | |
PLAYWRIGHT_VERSION=$(jq -r '.devDependencies["@playwright/test"]' package.json) | |
echo "Playwright's Version: $PLAYWRIGHT_VERSION" | |
echo "version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT | |
- name: Cache Playwright Browsers for Playwright's Version | |
id: cache-playwright-browsers | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/ms-playwright | |
key: playwright-browsers-${{ steps.get-playwright-version.outputs.version }} | |
lookup-only: true | |
- uses: actions/setup-node@v4 | |
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' | |
with: | |
node-version: lts/* | |
- name: Setup Playwright | |
if: steps.cache-playwright-browsers.outputs.cache-hit != 'true' | |
run: | | |
npx playwright install --with-deps | |
setup-and-cache-wasp-cli: | |
name: Setup and Cache Wasp CLI | |
runs-on: ubuntu-22.04 | |
outputs: | |
wasp-cli-cache-key: ${{ steps.generate-cache-key.outputs.cache-key }} | |
steps: | |
- uses: "actions/checkout@v4" | |
with: | |
# Workaround for a Github Checkout action bug | |
# https://github.com/actions/checkout/issues/1359#issuecomment-1567902034 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Generate Cache Key | |
id: generate-cache-key | |
run: | | |
CACHE_KEY="wasp-cli-${{ runner.os }}-${{ hashFiles('waspc/**/*.hs', 'waspc/**/*.cabal', 'waspc/cabal.project', 'waspc/data/**') }}" | |
echo "cache-key=$CACHE_KEY" >> $GITHUB_OUTPUT | |
- name: Cache Wasp CLI | |
id: cache-wasp-cli | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cabal | |
key: ${{ steps.generate-cache-key.outputs.cache-key }} | |
lookup-only: true | |
- uses: ./.github/actions/setup-haskell | |
if: steps.cache-wasp-cli.outputs.cache-hit != 'true' | |
with: | |
ghc-version: "8.10.7" | |
cabal-version: "3.6.2.0" | |
cabal-project-dir: waspc | |
- uses: actions/setup-node@v4 | |
if: steps.cache-wasp-cli.outputs.cache-hit != 'true' | |
with: | |
node-version: lts/* | |
- name: Build, package and install Wasp CLI | |
if: steps.cache-wasp-cli.outputs.cache-hit != 'true' | |
working-directory: waspc | |
run: | | |
./run build:all | |
cabal install --installdir=$HOME/.cabal/bin --install-method=copy | |
test-example-apps: | |
name: Test Example Apps | |
runs-on: ubuntu-22.04 | |
needs: [setup-and-cache-playwright, setup-and-cache-wasp-cli] | |
strategy: | |
fail-fast: false | |
matrix: | |
example: | |
- tutorials/TodoApp | |
- tutorials/TodoAppTs | |
- waspello | |
- waspleau | |
- websockets-realtime-voting | |
steps: | |
- uses: "actions/checkout@v4" | |
with: | |
# Workaround for a Github Checkout action bug | |
# https://github.com/actions/checkout/issues/1359#issuecomment-1567902034 | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Restore Wasp CLI Cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: ~/.cabal | |
key: ${{ needs.setup-and-cache-wasp-cli.outputs.wasp-cli-cache-key }} | |
- name: Add Wasp CLI to PATH | |
run: | | |
echo "~/.cabal/bin" >> $GITHUB_PATH | |
- name: Restore Playwright Browsers Cache | |
uses: actions/cache/restore@v4 | |
with: | |
path: ~/.cache/ms-playwright | |
key: playwright-browsers-${{ needs.setup-and-cache-playwright.outputs.playwright-version }} | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: lts/* | |
- name: Install Dependencies for ${{ matrix.example }} | |
working-directory: examples/${{ matrix.example }} | |
run: | | |
npm ci | |
if [ -f ".env.server.headless" ]; then | |
cp .env.server.headless .env.server | |
fi | |
- name: Extract Database Provider | |
id: extract-db-provider | |
working-directory: examples/${{ matrix.example }} | |
run: | | |
DATABASE_PROVIDER=$(wasp-cli info \ | |
| grep "Database system" \ | |
| sed 's/.*: //' \ | |
| sed -e 's/\x1b\[[0-9;]*m//g' \ | |
| tr '[:upper:]' '[:lower:]') | |
if [ -z "$DATABASE_PROVIDER" ]; then | |
echo "ERROR: Could not determine database system from wasp-cli info" | |
exit 1 | |
fi | |
echo "Database provider: $DATABASE_PROVIDER" | |
echo "provider=$DATABASE_PROVIDER" >> $GITHUB_OUTPUT | |
- name: Run Headless DEV Tests for ${{ matrix.example }} | |
working-directory: examples/${{ matrix.example }} | |
env: | |
WASP_CLI_CMD: wasp-cli | |
HEADLESS_TEST_MODE: dev | |
DEBUG: "*" | |
run: | | |
wasp-cli db migrate-dev | |
npm run test | |
- name: Run Headless BUILD Tests for ${{ matrix.example }} | |
if: steps.extract-db-provider.outputs.provider != 'sqlite' | |
working-directory: examples/${{ matrix.example }} | |
env: | |
WASP_CLI_CMD: wasp-cli | |
HEADLESS_TEST_MODE: build | |
DEBUG: "*" | |
run: | | |
npm run test |