Skip to content

E2E Tests

E2E Tests #618

Workflow file for this run

name: E2E Tests
on:
schedule:
- cron: "0 0 * * *"
push:
paths:
- 'examples/**'
- 'packages/open-next/**'
- 'packages/tests-e2e/**'
branches:
- main
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
PLAYWRIGHT_BROWSERS_PATH: 0
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
# Checks the latest Nextjs Version, if it's not been tested before, it will
# Continue to the next job where it does the actual Playwright tests
check_next_version:
runs-on: ubuntu-latest
# Only run this on the official sst repo
if: github.repository == 'sst/open-next'
steps:
- name: Get Latest Next Version
id: get_latest_version
run: |
latest_version=$(curl -s https://api.github.com/repos/vercel/next.js/releases/latest | jq -r '.tag_name')
echo "Latest version: $latest_version"
echo "LATEST_VERSION=$latest_version" >> $GITHUB_ENV
echo "LATEST_VERSION=$latest_version" >> $GITHUB_OUTPUT
- name: Restore Cache Previous Version
id: cache-previous
uses: actions/cache/restore@v3
with:
path: previous_version.txt
key: ${{ runner.os }}-previous-${{ steps.get_latest_version.outputs.LATEST_VERSION }}
- name: Compare Versions
id: compare_versions
run: |
latest_version=$LATEST_VERSION
if [ -f previous_version.txt ]; then
previous_version=$(cat previous_version.txt)
echo "pv: $previous_version"
else
previous_version=""
fi
if [ "$latest_version" != "$previous_version" ]; then
echo "Versions are different. Continuing the pipeline."
else
echo "Versions are the same. Exiting with success."
echo "SKIP=true" >> $GITHUB_OUTPUT
fi
outputs:
skip: ${{ steps.compare_versions.outputs.SKIP }}
previousNextVersion: ${{ steps.get_latest_version.outputs.LATEST_VERSION }}
cacheKey: ${{ steps.cache-previous.outputs.cache-primary-key }}
# If the event is push (merged and pushed into main) or if
# the latest Nextjs version hasn't been tested, run the Playwright tests
e2e:
needs: check_next_version
if: github.event_name == 'push' || needs.check_next_version.outputs.skip != 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Set up NodeJS v18
uses: actions/setup-node@v3
with:
cache: pnpm # cache pnpm store
node-version: 18.18.2
- name: Install packages
run: pnpm install
# Install latest nextjs version
- name: Install Nextjs in app-router
working-directory: examples/app-router
run: pnpm add next@${{ needs.check_next_version.outputs.previousNextVersion }}
- name: Install Nextjs in pages-router
working-directory: examples/pages-router
run: pnpm add next@${{ needs.check_next_version.outputs.previousNextVersion }}
- name: Install Nextjs in app-pages-router
working-directory: examples/app-pages-router
run: pnpm add next@${{ needs.check_next_version.outputs.previousNextVersion }}
- name: Get Playwright version
id: playwright-version
run: echo "version=$(npm ls @playwright/test | grep @playwright | sed 's/.*@//' | sed 's/ .*//' )"
- name: Cache Playwright
uses: actions/cache@v3
id: playwright-cache
with:
path: "~/.cache/ms-playwright"
key: ${{ runner.os }}-playwright-${{ steps.playwright-version.outputs.version }}
restore-keys: |
${{ runner.os }}-playwright-
- name: Install Playwright
if: steps.playwright-cache.outputs.cache-hit != 'true'
run: pnpm exec playwright install chromium --with-deps
# Cache turbo runs
- name: Cache Turbo
uses: actions/cache@v3
with:
path: .turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
# Build only the open-next package + its monorepo dependencies
- name: Build
run: pnpm --filter open-next... run build
# Deploy e2e stage
- name: Deploy NextjsSite
working-directory: examples/sst
run: npx sst deploy --stage e2e
# Load app urls from .sst/output.json file
- name: Set environments
working-directory: examples/sst
run: |
APP_ROUTER_URL=$(jq -r '.["e2e-example-AppRouter"].url' .sst/outputs.json)
echo "APP_ROUTER_URL=$APP_ROUTER_URL" >> $GITHUB_ENV
PAGES_ROUTER_URL=$(jq -r '.["e2e-example-PagesRouter"].url' .sst/outputs.json)
echo "PAGES_ROUTER_URL=$PAGES_ROUTER_URL" >> $GITHUB_ENV
APP_PAGES_ROUTER_URL=$(jq -r '.["e2e-example-AppPagesRouter"].url' .sst/outputs.json)
echo "APP_PAGES_ROUTER_URL=$APP_PAGES_ROUTER_URL" >> $GITHUB_ENV
- name: Run e2e Test
run: npm run e2e:test
- name: Archive
if: failure()
uses: actions/upload-artifact@v3
with:
name: sst
path: |
.sst/
.next/
- name: Store Latest Version
run: |
echo "${{ needs.check_next_version.outputs.previousNextVersion }}" > previous_version.txt
- name: Cache Previous Version
uses: actions/cache/save@v3
with:
path: previous_version.txt
key: ${{ needs.check_next_version.outputs.cacheKey }}
#############################
# Report status to Discord
#############################
- name: Report success
if: success()
run: |
curl -X POST "$DISCORD_WEBHOOK" \
-H "Content-Type: application/json" \
-d '{
"username": "OpenNext E2E Test",
"avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"embeds": [
{
"description": "Test succeeded [${{ needs.check_next_version.outputs.previousNextVersion }}](https://github.com/vercel/next.js/releases/tag/${{ needs.check_next_version.outputs.previousNextVersion }}) — [view results](https://github.com/${{ github.repository }}/actions/runs/${{github.run_id}})",
"color": 3061373,
"footer": {
"text": "🍌 Ook-ook! Eeek-aak-eek! 🍌",
"icon_url": "https://i.imgur.com/u2ENxCk.png"
}
}
]
}'
- name: Report failure
if: failure()
run: |
curl -X POST "$DISCORD_WEBHOOK" \
-H "Content-Type: application/json" \
-d '{
"username": "OpenNext E2E Test",
"avatar_url": "https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png",
"embeds": [
{
"description": "Test failed [${{ needs.check_next_version.outputs.previousNextVersion }}](https://github.com/vercel/next.js/releases/tag/${{ needs.check_next_version.outputs.previousNextVersion }}) — [view results](https://github.com/${{ github.repository }}/actions/runs/${{github.run_id}})",
"color": 14687834,
"footer": {
"text": "🥓 Oink oink... 🥓",
"icon_url": "https://i.imgur.com/QeXzqIy.png"
}
}
]
}'