Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 179 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# source: https://github.com/actions/starter-workflows/blob/main/ci/node.js.yml

name: ci

permissions:
contents: read
on:
push:
branches:
Expand All @@ -20,8 +21,8 @@ jobs:
- name: Use Node.js 18.12.0
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '18.12.0'
cache: 'yarn'
node-version: "18.12.0"
cache: "yarn"
- run: yarn install --frozen-lockfile
- run: yarn prepublishOnly
- run: node index.node.js
Expand All @@ -31,3 +32,178 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
- run: yarn check-deps

e2e-tests:
runs-on: ubuntu-latest
timeout-minutes: 15

strategy:
matrix:
browser: [chromium, firefox, webkit]
fail-fast: false

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Setup Node.js
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: "18.12.0"
cache: "yarn"
- name: Install dependencies
run: |
yarn install --frozen-lockfile
yarn prepublishOnly
- name: Cache React dependencies
uses: actions/cache@v4
with:
path: react-example/node_modules
key: ${{ runner.os }}-react-deps-${{ hashFiles('react-example/yarn.lock') }}
restore-keys: |
${{ runner.os }}-react-deps-
- name: Install React example dependencies
working-directory: ./react-example
run: |
# Try frozen lockfile first, fallback to regeneration if corrupted
yarn install --frozen-lockfile || {
echo "Lockfile corrupted, regenerating..."
rm yarn.lock
yarn install
}
# Advanced browser caching strategy
- name: Cache Playwright browsers
uses: actions/cache@v4
id: playwright-cache
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-v2-${{ matrix.browser }}-${{ hashFiles('react-example/yarn.lock') }}
restore-keys: |
${{ runner.os }}-playwright-v2-${{ matrix.browser }}-
${{ runner.os }}-playwright-${{ matrix.browser }}-
${{ runner.os }}-playwright-v2-
# Browser-specific installation strategy
- name: Install Playwright browsers
working-directory: ./react-example
run: |
echo "πŸ“₯ Installing ${{ matrix.browser }} browser..."

# Smart installation based on browser type and cache status
cache_hit="${{ steps.playwright-cache.outputs.cache-hit }}"

if [ "$cache_hit" = "true" ]; then
echo "Cache hit: Installing browser only..."
yarn playwright install ${{ matrix.browser }}
elif [ "${{ matrix.browser }}" = "webkit" ]; then
echo "Cache miss + WebKit: Installing with dependencies..."
yarn playwright install ${{ matrix.browser }} --with-deps
elif [ "${{ matrix.browser }}" = "firefox" ]; then
echo "Cache miss + Firefox: Installing with dependencies..."
yarn playwright install ${{ matrix.browser }} --with-deps
else
echo "Cache miss + Chromium: Installing browser only..."
yarn playwright install ${{ matrix.browser }}
fi
# WebKit-specific dependency fix (Ubuntu 22.04 compatibility)
- name: Fix WebKit dependencies
if: matrix.browser == 'webkit'
run: |
echo "πŸ”§ Applying WebKit Ubuntu 22.04 fixes..."
sudo apt-get update -qq
# Install the exact library versions WebKit needs
sudo apt-get install -y libwoff2-1.1.0 libwoff2dec1 fonts-liberation || true
echo "βœ… WebKit dependencies updated"

# Browser environment setup (flags now handled by Playwright config)
- name: Setup browser environment
run: |
echo "πŸš€ Browser environment configured via Playwright config"
echo "βœ… CI-optimized browser launch parameters will be applied automatically"
- name: Create environment configuration
working-directory: ./react-example
run: |
cat > .env << 'EOF'
API_KEY=${{ secrets.ITERABLE_API_KEY }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
USE_JWT=true
JWT_GENERATOR=https://jwt-generator.stg-itbl.co/generate
[email protected]
EOF
- name: Build React example app
working-directory: ./react-example
run: yarn build
# Enhanced server startup with better resource management
- name: Start React example server
working-directory: ./react-example
run: |
echo "πŸš€ Starting React server..."

# Set Node.js memory limits for better stability
export NODE_OPTIONS="--max-old-space-size=4096"

# Start server with optimized settings
yarn webpack serve --config webpack.config.js --port 8080 --host 0.0.0.0 &
SERVER_PID=$!
echo "Server started with PID: $SERVER_PID"

# Enhanced health check with better error reporting
for i in {1..20}; do
if curl -f http://localhost:8080 >/dev/null 2>&1; then
echo "βœ… Server ready after ${i} attempts ($(($i*3)) seconds)"
break
fi
if [ $i -eq 20 ]; then
echo "❌ Server startup failed after 60 seconds"
echo "πŸ“‹ Debug information:"
ps aux | grep webpack || true
netstat -tulpn | grep 8080 || true
curl -v http://localhost:8080 || true
exit 1
fi
sleep 3
echo "Server startup attempt $i/20..."
done
# Enhanced test execution with browser-specific optimizations
- name: Run Playwright tests
working-directory: ./react-example
run: |
yarn playwright test --project=${{ matrix.browser }}
env:
CI: true
# Browser-specific environment variables
DISPLAY: :99 # Virtual display for browsers
# WebKit library path configuration
LD_LIBRARY_PATH: $HOME/.cache/ms-playwright/${{ matrix.browser }}-*/minibrowser-wpe/lib:$LD_LIBRARY_PATH
# Enhanced artifact management
- name: Upload Playwright report
uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report-${{ matrix.browser }}-${{ github.run_number }}
path: react-example/playwright-report/
retention-days: 14

- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.browser }}-${{ github.run_number }}
path: react-example/test-results/
retention-days: 7
# Comprehensive cleanup with port management
- name: Cleanup server processes
if: always()
run: |
echo "🧹 Cleaning up server processes..."

# Kill all processes using port 8080
sudo lsof -ti:8080 | xargs -r sudo kill -9 || true

# Kill by process names
pkill -f "webpack serve" || true
pkill -f "node.*webpack" || true

# Kill any remaining browser processes
pkill -f "chrome" || true
pkill -f "firefox" || true
pkill -f "webkit" || true

echo "βœ… Cleanup completed"
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,73 @@ yarn start # In one terminal
yarn playwright # In another terminal
```

## CI/CD with GitHub Actions

The project uses GitHub Actions for continuous integration, including automated Playwright E2E testing across multiple browsers.

### CI Pipeline Overview

The CI pipeline (`/.github/workflows/ci.yml`) runs:

1. **Unit Tests**: SDK build verification and Jest unit tests
2. **E2E Tests**: Playwright tests across Chromium, Firefox, and WebKit browsers

### Playwright CI Configuration

The E2E tests run automatically on every push and pull request:

- **Browsers**: Tests run simultaneously on Chromium, Firefox, and WebKit
- **Environment**: Automatically configured with test API keys
- **Reports**: Test results and screenshots are uploaded as artifacts
- **Retry Strategy**: Failed tests are retried twice on CI

### Required GitHub Secrets

The repository uses these configured secrets for Playwright E2E testing in CI:

- **`ITERABLE_API_KEY`**: Iterable web API key for SDK authentication during testing
- **`JWT_SECRET`**: JWT secret associated with the API key for token generation

These secrets are already configured in the repository's GitHub Actions settings. They enable the CI environment to authenticate with Iterable's API and test SDK functionality with real API endpoints.

**Test Configuration Details:**
- **Default Test User**: `[email protected]` is used as the default test user for CI testing
- **Test Project**: The API_KEY uses Iterable's production test project:
- **Project**: Mobile SDK Test (Do Not Delete) (Project ID: 1226)
- **URL**: https://app.iterable.com/campaigns/manage?projectId=1226

> **Note for developers**: If you need to update these secrets or configure them in a fork, go to Repository Settings β†’ Secrets and variables β†’ Actions and update the values accordingly.

### CI Environment Configuration

During CI execution, the environment is automatically configured with:

```bash
API_KEY=${{ secrets.ITERABLE_API_KEY }}
JWT_SECRET=${{ secrets.JWT_SECRET }}
USE_JWT=true
[email protected]
```

### Features Tested in CI

The automated tests cover:

- **Authentication**: Login form functionality and user management
- **Navigation**: All app sections (Commerce, Events, Users, InApp, Embedded)
- **UUA Testing**: Unknown user activation and consent management
- **Core SDK Integration**: Proper initialization and configuration

### Accessing CI Results

After CI runs, you can:

- View test results in the GitHub Actions tab
- Download test reports and screenshots from artifacts
- Debug failed tests using uploaded traces and videos

For detailed troubleshooting and local development setup, see the [E2E Testing Guide](./react-example/e2e/README.md).

# Contributing

Looking to contribute? Please see the [contributing instructions here](./CONTRIBUTING.md)
Expand Down
Loading
Loading