From 294f2bfe6b03bdceaa932586f8c2eaa138c69875 Mon Sep 17 00:00:00 2001 From: Karl Power Date: Tue, 2 Jun 2026 12:31:25 +0200 Subject: [PATCH] testing(e2e): backport e2e action split from EE --- .github/actions/e2e-setup/action.yml | 91 +++++++++++++++++++++++ .github/actions/e2e-teardown/action.yml | 35 +++++++++ .github/workflows/e2e-tests.yml | 99 ++----------------------- 3 files changed, 131 insertions(+), 94 deletions(-) create mode 100644 .github/actions/e2e-setup/action.yml create mode 100644 .github/actions/e2e-teardown/action.yml diff --git a/.github/actions/e2e-setup/action.yml b/.github/actions/e2e-setup/action.yml new file mode 100644 index 0000000000..c2d2c80c5b --- /dev/null +++ b/.github/actions/e2e-setup/action.yml @@ -0,0 +1,91 @@ +name: E2E Setup +description: | + Shared setup for E2E test workflows: sets the HDX_E2E_* port env vars and + common Playwright env vars, then runs Node.js setup, dependency install, + build, Playwright browser install, and starts the E2E Docker Compose stack + (MongoDB + ClickHouse) with health checks. The caller is responsible for + `actions/checkout`, running Playwright, uploading artifacts, and tearing + down the Docker stack. +runs: + using: composite + steps: + # E2E port configuration (slot 0 defaults — must match scripts/test-e2e.sh) + - name: Set E2E environment variables + shell: bash + run: | + MONGO_PORT=21100 + echo "HDX_E2E_SLOT=0" >> $GITHUB_ENV + echo "HDX_E2E_OPAMP_PORT=20320" >> $GITHUB_ENV + echo "HDX_E2E_CH_PORT=20500" >> $GITHUB_ENV + echo "HDX_E2E_CH_NATIVE_PORT=20600" >> $GITHUB_ENV + echo "HDX_E2E_API_PORT=21000" >> $GITHUB_ENV + echo "HDX_E2E_MONGO_PORT=$MONGO_PORT" >> $GITHUB_ENV + echo "HDX_E2E_APP_LOCAL_PORT=21200" >> $GITHUB_ENV + echo "HDX_E2E_APP_PORT=21300" >> $GITHUB_ENV + echo "MONGO_URI=mongodb://localhost:$MONGO_PORT/hyperdx-e2e" >> $GITHUB_ENV + echo "E2E_FULLSTACK=true" >> $GITHUB_ENV + echo "E2E_UNIQUE_USER=true" >> $GITHUB_ENV + echo "E2E_API_HEALTH_CHECK_MAX_RETRIES=60" >> $GITHUB_ENV + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + cache-dependency-path: yarn.lock + cache: yarn + + - name: Install dependencies + shell: bash + run: yarn install + + - name: Build dependencies + shell: bash + run: npx nx run-many -t ci:build + + - name: Install Playwright browsers + shell: bash + run: cd packages/app && npx playwright install --with-deps chromium + + - name: Start E2E Docker Compose + shell: bash + run: | + # Pre-pull images with retries to handle transient Docker Hub timeouts + for attempt in 1 2 3; do + if docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml pull; then + echo "Docker images pulled successfully on attempt $attempt" + break + fi + if [ "$attempt" -eq 3 ]; then + echo "Failed to pull Docker images after 3 attempts" + exit 1 + fi + echo "Docker pull failed (attempt $attempt/3), retrying in 10s..." + sleep 10 + done + docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml up -d + echo "Waiting for MongoDB..." + for i in $(seq 1 30); do + if docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml exec -T db mongosh --quiet --eval "db.adminCommand({ping:1})" >/dev/null 2>&1; then + echo "MongoDB is ready" + break + fi + if [ "$i" -eq 30 ]; then + echo "MongoDB failed to become ready after 30 seconds" + exit 1 + fi + echo "Waiting for MongoDB... ($i/30)" + sleep 1 + done + echo "Waiting for ClickHouse..." + for i in $(seq 1 60); do + if curl -sf http://localhost:${HDX_E2E_CH_PORT}/ping >/dev/null 2>&1; then + echo "ClickHouse is ready" + break + fi + if [ "$i" -eq 60 ]; then + echo "ClickHouse failed to become ready after 60 seconds" + exit 1 + fi + echo "Waiting for ClickHouse... ($i/60)" + sleep 1 + done diff --git a/.github/actions/e2e-teardown/action.yml b/.github/actions/e2e-teardown/action.yml new file mode 100644 index 0000000000..b9e78e3140 --- /dev/null +++ b/.github/actions/e2e-teardown/action.yml @@ -0,0 +1,35 @@ +name: E2E Teardown +description: | + Upload Playwright artifacts and stop the E2E Docker Compose stack. + Always runs (even on failure) so containers are cleaned up and reports + are available for failed runs. +inputs: + artifact-suffix: + description: > + Suffix appended to artifact names, e.g. "1" → playwright-report-1. + required: true +runs: + using: composite + steps: + - name: Upload Playwright report + uses: actions/upload-artifact@v7 + if: always() + with: + name: playwright-report-${{ inputs.artifact-suffix }} + path: packages/app/playwright-report/ + retention-days: 30 + + - name: Upload test results + uses: actions/upload-artifact@v7 + if: always() + with: + name: test-results-${{ inputs.artifact-suffix }} + path: packages/app/test-results/ + retention-days: 30 + + - name: Stop E2E containers + if: always() + shell: bash + run: + docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml + down -v diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml index 5eb9f24904..9cd34cb1fd 100644 --- a/.github/workflows/e2e-tests.yml +++ b/.github/workflows/e2e-tests.yml @@ -14,109 +14,20 @@ jobs: matrix: shard: [1, 2, 3, 4] - # E2E port configuration (slot 0 defaults — must match scripts/test-e2e.sh) - env: - HDX_E2E_SLOT: '0' - HDX_E2E_OPAMP_PORT: '20320' - HDX_E2E_CH_PORT: '20500' - HDX_E2E_CH_NATIVE_PORT: '20600' - HDX_E2E_API_PORT: '21000' - HDX_E2E_MONGO_PORT: '21100' - HDX_E2E_APP_LOCAL_PORT: '21200' - HDX_E2E_APP_PORT: '21300' - steps: - name: Checkout uses: actions/checkout@v6 - - name: Setup Node.js - uses: actions/setup-node@v6 - with: - node-version-file: '.nvmrc' - cache-dependency-path: 'yarn.lock' - cache: 'yarn' - - - name: Install dependencies - run: yarn install - - - name: Build dependencies - run: npx nx run-many -t ci:build - - - name: Install Playwright browsers - run: cd packages/app && npx playwright install --with-deps chromium - - - name: Start E2E Docker Compose - run: | - # Pre-pull images with retries to handle transient Docker Hub timeouts - for attempt in 1 2 3; do - if docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml pull; then - echo "Docker images pulled successfully on attempt $attempt" - break - fi - if [ "$attempt" -eq 3 ]; then - echo "Failed to pull Docker images after 3 attempts" - exit 1 - fi - echo "Docker pull failed (attempt $attempt/3), retrying in 10s..." - sleep 10 - done - docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml up -d - echo "Waiting for MongoDB..." - for i in $(seq 1 30); do - if docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml exec -T db mongosh --quiet --eval "db.adminCommand({ping:1})" >/dev/null 2>&1; then - echo "MongoDB is ready" - break - fi - if [ "$i" -eq 30 ]; then - echo "MongoDB failed to become ready after 30 seconds" - exit 1 - fi - echo "Waiting for MongoDB... ($i/30)" - sleep 1 - done - echo "Waiting for ClickHouse..." - for i in $(seq 1 60); do - if curl -sf http://localhost:${HDX_E2E_CH_PORT}/ping >/dev/null 2>&1; then - echo "ClickHouse is ready" - break - fi - if [ "$i" -eq 60 ]; then - echo "ClickHouse failed to become ready after 60 seconds" - exit 1 - fi - echo "Waiting for ClickHouse... ($i/60)" - sleep 1 - done + - name: E2E setup + uses: ./.github/actions/e2e-setup - name: Run Playwright tests (full-stack mode) - env: - E2E_FULLSTACK: 'true' - E2E_UNIQUE_USER: 'true' - E2E_API_HEALTH_CHECK_MAX_RETRIES: '60' - MONGO_URI: - mongodb://localhost:${{ env.HDX_E2E_MONGO_PORT }}/hyperdx-e2e run: | cd packages/app yarn test:e2e --shard=${{ matrix.shard }}/4 - - name: Upload Playwright report - uses: actions/upload-artifact@v7 - if: always() - with: - name: playwright-report-${{ matrix.shard }} - path: packages/app/playwright-report/ - retention-days: 30 - - - name: Upload test results - uses: actions/upload-artifact@v7 + - name: E2E teardown if: always() + uses: ./.github/actions/e2e-teardown with: - name: test-results-${{ matrix.shard }} - path: packages/app/test-results/ - retention-days: 30 - - - name: Stop E2E containers - if: always() - run: - docker compose -p e2e-0 -f packages/app/tests/e2e/docker-compose.yml - down -v + artifact-suffix: ${{ matrix.shard }}