mirror of
https://github.com/BillyOutlast/posthog.git
synced 2026-02-04 03:01:23 +01:00
253 lines
11 KiB
YAML
253 lines
11 KiB
YAML
#
|
|
# This workflow runs CI E2E tests with Playwright.
|
|
#
|
|
# It relies on the container image built by 'container-images-ci.yml'.
|
|
#
|
|
name: E2E CI Playwright
|
|
|
|
on:
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
changes:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
if: github.repository == 'PostHog/posthog'
|
|
name: Determine need to run E2E checks
|
|
# Set job outputs to values from filter step
|
|
outputs:
|
|
shouldRun: ${{ steps.changes.outputs.shouldRun }}
|
|
steps:
|
|
# For pull requests it's not necessary to check out the code
|
|
- uses: dorny/paths-filter@v2
|
|
id: changes
|
|
with:
|
|
filters: |
|
|
shouldRun:
|
|
# Avoid running E2E tests for irrelevant changes
|
|
# NOTE: we are at risk of missing a dependency here. We could make
|
|
# the dependencies more clear if we separated the backend/frontend
|
|
# code completely
|
|
- 'ee/**'
|
|
- 'posthog/!(temporal/**)/**'
|
|
- 'bin/*'
|
|
- frontend/**/*
|
|
- requirements.txt
|
|
- requirements-dev.txt
|
|
- package.json
|
|
- pnpm-lock.yaml
|
|
# Make sure we run if someone is explicitly changes the workflow
|
|
- .github/workflows/ci-e2e-playwright.yml
|
|
- .github/actions/build-n-cache-image/action.yml
|
|
# We use docker compose for tests, make sure we rerun on
|
|
# changes to docker-compose.dev.yml e.g. dependency
|
|
# version changes
|
|
- docker-compose.dev.yml
|
|
- Dockerfile
|
|
- playwright/**
|
|
|
|
container:
|
|
name: Build and cache container image
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 60
|
|
needs: [changes]
|
|
permissions:
|
|
contents: read
|
|
id-token: write # allow issuing OIDC tokens for this workflow run
|
|
outputs:
|
|
tag: ${{ steps.build.outputs.tag }}
|
|
build-id: ${{ steps.build.outputs.build-id }}
|
|
steps:
|
|
- name: Checkout
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: actions/checkout@v3
|
|
- name: Build the Docker image with Depot
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
# Build the container image in preparation for the E2E tests
|
|
uses: ./.github/actions/build-n-cache-image
|
|
id: build
|
|
with:
|
|
save: true
|
|
actions-id-token-request-url: ${{ env.ACTIONS_ID_TOKEN_REQUEST_URL }}
|
|
|
|
playwright:
|
|
name: Playwright E2E tests
|
|
runs-on: depot-ubuntu-latest-4
|
|
timeout-minutes: 60
|
|
needs: [changes, container]
|
|
permissions:
|
|
id-token: write # allow issuing OIDC tokens for this workflow run
|
|
|
|
steps:
|
|
- name: Checkout
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Install pnpm
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: pnpm/action-setup@v4
|
|
|
|
- name: Set up Node.js
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 18.12.1
|
|
cache: 'pnpm'
|
|
|
|
- name: Get pnpm cache directory path
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
id: pnpm-cache-dir
|
|
run: echo "PNPM_STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
|
|
|
|
- uses: actions/cache@v4
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
id: pnpm-cache
|
|
with:
|
|
path: |
|
|
${{ steps.pnpm-cache-dir.outputs.PNPM_STORE_PATH }}
|
|
key: ${{ runner.os }}-pnpm-playwright-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-playwright-
|
|
|
|
- name: Install package.json dependencies with pnpm
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: pnpm --filter=@posthog/playwright... install --frozen-lockfile
|
|
|
|
- name: Install playwright and dependencies
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: pnpm --filter=@posthog/playwright exec playwright install --with-deps
|
|
|
|
- name: Stop/Start stack with Docker Compose
|
|
# these are required checks so, we can't skip entire sections
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: |
|
|
docker compose -f docker-compose.dev.yml down
|
|
docker compose -f docker-compose.dev.yml up -d
|
|
|
|
- name: Wait for ClickHouse
|
|
# these are required checks so, we can't skip entire sections
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: ./bin/check_kafka_clickhouse_up
|
|
|
|
- name: Install Depot CLI
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: depot/setup-action@v1
|
|
|
|
- name: Get Docker image cached in Depot
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
uses: depot/pull-action@v1
|
|
with:
|
|
build-id: ${{ needs.container.outputs.build-id }}
|
|
tags: ${{ needs.container.outputs.tag }}
|
|
|
|
- name: Write .env # This step intentionally has no if, so that GH always considers the action as having run
|
|
run: |
|
|
cat <<EOT >> .env
|
|
SECRET_KEY=6b01eee4f945ca25045b5aab440b953461faf08693a9abbf1166dc7c6b9772da
|
|
REDIS_URL=redis://localhost
|
|
DATABASE_URL=postgres://posthog:posthog@localhost:5432/posthog
|
|
KAFKA_HOSTS=kafka:9092
|
|
DISABLE_SECURE_SSL_REDIRECT=1
|
|
SECURE_COOKIES=0
|
|
OPT_OUT_CAPTURE=0
|
|
E2E_TESTING=1
|
|
SKIP_SERVICE_VERSION_REQUIREMENTS=1
|
|
EMAIL_HOST=email.test.posthog.net
|
|
SITE_URL=http://localhost:8000
|
|
NO_RESTART_LOOP=1
|
|
CLICKHOUSE_SECURE=0
|
|
OBJECT_STORAGE_ENABLED=1
|
|
OBJECT_STORAGE_ENDPOINT=http://localhost:19000
|
|
OBJECT_STORAGE_ACCESS_KEY_ID=object_storage_root_user
|
|
OBJECT_STORAGE_SECRET_ACCESS_KEY=object_storage_root_password
|
|
GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
|
CELERY_METRICS_PORT=8999
|
|
CLOUD_DEPLOYMENT=1
|
|
EOT
|
|
|
|
- name: Start PostHog
|
|
# these are required checks so, we can't skip entire sections
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: |
|
|
mkdir -p /tmp/logs
|
|
|
|
echo "Starting PostHog using the container image ${{ needs.container.outputs.tag }}"
|
|
DOCKER_RUN="docker run --rm --network host --add-host kafka:127.0.0.1 --add-host clickhouse:127.0.0.1 --env-file .env ${{ needs.container.outputs.tag }}"
|
|
|
|
$DOCKER_RUN ./bin/migrate
|
|
$DOCKER_RUN python manage.py setup_dev
|
|
|
|
# only starts the plugin server so that the "wait for PostHog" step passes
|
|
$DOCKER_RUN ./bin/docker-worker &> /tmp/logs/worker.txt &
|
|
$DOCKER_RUN ./bin/docker-server &> /tmp/logs/server.txt &
|
|
|
|
- name: Wait for PostHog
|
|
# these are required checks so, we can't skip entire sections
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
# this action might be abandoned - but v1 doesn't point to latest of v1 (which it should)
|
|
# so pointing to v1.1.0 to remove warnings about node version with v1
|
|
# todo check https://github.com/iFaxity/wait-on-action/releases for new releases
|
|
uses: iFaxity/wait-on-action@v1.2.1
|
|
timeout-minutes: 3
|
|
with:
|
|
verbose: true
|
|
log: true
|
|
resource: http://localhost:8000
|
|
|
|
- name: Playwright run
|
|
# these are required checks so, we can't skip entire sections
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
run: pnpm --filter=@posthog/playwright exec playwright test
|
|
env:
|
|
E2E_TESTING: 1
|
|
OPT_OUT_CAPTURE: 0
|
|
GITHUB_ACTION_RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
|
|
|
|
- name: Archive report
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: playwright-report
|
|
path: playwright/playwright-report/
|
|
retention-days: 30
|
|
if: ${{ failure() }}
|
|
|
|
capture-run-time:
|
|
name: Capture run time
|
|
runs-on: ubuntu-latest
|
|
needs: [playwright]
|
|
if: needs.changes.outputs.shouldRun == 'true'
|
|
steps:
|
|
- name: Calculate run time and send to PostHog
|
|
run: |
|
|
gh auth login --with-token < <(echo ${{ secrets.GITHUB_TOKEN }})
|
|
run_id=${GITHUB_RUN_ID}
|
|
repo=${GITHUB_REPOSITORY}
|
|
run_info=$(gh api repos/${repo}/actions/runs/${run_id})
|
|
echo run_info: ${run_info}
|
|
# name is the name of the workflow file
|
|
# run_started_at is the start time of the workflow
|
|
# we want to get the number of seconds between the start time and now
|
|
name=$(echo ${run_info} | jq -r '.name')
|
|
run_url=$(echo ${run_info} | jq -r '.url')
|
|
run_started_at=$(echo ${run_info} | jq -r '.run_started_at')
|
|
run_attempt=$(echo ${run_info} | jq -r '.run_attempt')
|
|
start_seconds=$(date -d "${run_started_at}" +%s)
|
|
now_seconds=$(date +%s)
|
|
duration=$((now_seconds-start_seconds))
|
|
echo running_time_duration_seconds=${duration} >> $GITHUB_ENV
|
|
echo running_time_run_url=${run_url} >> $GITHUB_ENV
|
|
echo running_time_run_attempt=${run_attempt} >> $GITHUB_ENV
|
|
echo running_time_run_id=${run_id} >> $GITHUB_ENV
|
|
echo running_time_run_started_at=${run_started_at} >> $GITHUB_ENV
|
|
- name: Capture running time to PostHog
|
|
if: github.repository == 'PostHog/posthog'
|
|
uses: PostHog/posthog-github-action@v0.1
|
|
with:
|
|
posthog-token: ${{secrets.POSTHOG_API_TOKEN}}
|
|
event: 'posthog-ci-running-time'
|
|
properties: '{"runner": "depot", "duration_seconds": ${{ env.running_time_duration_seconds }}, "run_url": "${{ env.running_time_run_url }}", "run_attempt": "${{ env.running_time_run_attempt }}", "run_id": "${{ env.running_time_run_id }}", "run_started_at": "${{ env.running_time_run_started_at }}"}'
|