Migrate to pnpm workspaces with automated npm publishing #280
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: Test Visualizations | |
| on: | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| discover: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| packages: ${{ steps.set-packages.outputs.packages }} | |
| playwright_packages: ${{ steps.set-packages.outputs.playwright_packages }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Discover packages with tests | |
| id: set-packages | |
| run: | | |
| echo "Scanning packages for test scripts..." | |
| regular_packages=() | |
| playwright_packages=() | |
| no_test_script=() | |
| for dir in packages/*/; do | |
| pkg=$(basename "$dir") | |
| if [ -f "$dir/package.json" ]; then | |
| test_script=$(jq -r ".scripts.test // \"\"" "$dir/package.json") | |
| if [ -n "$test_script" ]; then | |
| # Check for Playwright in test script or dependencies | |
| if [[ "$test_script" == *"playwright"* ]] || \ | |
| jq -e '.devDependencies | has("@playwright/test") or has("playwright")' "$dir/package.json" > /dev/null 2>&1; then | |
| playwright_packages+=("$pkg") | |
| else | |
| regular_packages+=("$pkg") | |
| fi | |
| else | |
| no_test_script+=("$pkg") | |
| fi | |
| fi | |
| done | |
| packages=$(printf '%s\n' "${regular_packages[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| echo "packages=$packages" >> $GITHUB_OUTPUT | |
| playwright_packages_json=$(printf '%s\n' "${playwright_packages[@]}" | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| echo "playwright_packages=$playwright_packages_json" >> $GITHUB_OUTPUT | |
| echo "" | |
| echo "✅ Regular packages with test script (${#regular_packages[@]}):" | |
| printf ' - %s\n' "${regular_packages[@]}" | |
| echo "" | |
| echo "✅ Playwright packages with test script (${#playwright_packages[@]}):" | |
| printf ' - %s\n' "${playwright_packages[@]}" | |
| echo "" | |
| echo "❌ Packages without test script (${#no_test_script[@]}):" | |
| printf ' - %s\n' "${no_test_script[@]}" | |
| test: | |
| needs: discover | |
| if: needs.discover.outputs.packages != '[]' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJson(needs.discover.outputs.packages) }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 22 | |
| - name: Cache pnpm store | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.local/share/pnpm/store/v10 | |
| key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Check for requirements.txt | |
| id: check-python | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| if [ -f requirements.txt ]; then | |
| echo "has_requirements=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_requirements=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Python | |
| if: steps.check-python.outputs.has_requirements == 'true' | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| cache: pip | |
| cache-dependency-path: packages/${{ matrix.package }}/requirements.txt | |
| - name: Install Python dependencies | |
| if: steps.check-python.outputs.has_requirements == 'true' | |
| working-directory: packages/${{ matrix.package }} | |
| run: pip install -r requirements.txt | |
| - name: Run tests | |
| working-directory: packages/${{ matrix.package }} | |
| run: pnpm test | |
| test-playwright: | |
| needs: discover | |
| if: needs.discover.outputs.playwright_packages != '[]' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: ${{ fromJson(needs.discover.outputs.playwright_packages) }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v5 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: 22 | |
| - name: Cache pnpm store | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.local/share/pnpm/store/v10 | |
| key: ${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm- | |
| - name: Cache Playwright browsers | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/ms-playwright | |
| key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-playwright- | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Check for requirements.txt | |
| id: check-python | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| if [ -f requirements.txt ]; then | |
| echo "has_requirements=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_requirements=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Setup Python | |
| if: steps.check-python.outputs.has_requirements == 'true' | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: '3.13' | |
| cache: pip | |
| cache-dependency-path: packages/${{ matrix.package }}/requirements.txt | |
| - name: Install Python dependencies | |
| if: steps.check-python.outputs.has_requirements == 'true' | |
| working-directory: packages/${{ matrix.package }} | |
| run: pip install -r requirements.txt | |
| - name: Install Playwright browsers | |
| working-directory: packages/${{ matrix.package }} | |
| run: pnpm exec playwright install --with-deps chromium | |
| - name: Build | |
| working-directory: packages/${{ matrix.package }} | |
| run: pnpm build | |
| - name: Start Server in background | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| nohup pnpm dev > server.log 2>&1 & | |
| echo $! > server.pid | |
| - name: Wait for Server to be ready | |
| run: | | |
| echo "Waiting for server to be ready..." | |
| ports=(5173 8000 8080) | |
| for i in {1..60}; do | |
| for port in "${ports[@]}"; do | |
| if curl -s http://localhost:$port > /dev/null 2>&1; then | |
| echo "✅ Server is ready on port $port!" | |
| exit 0 | |
| fi | |
| done | |
| echo "Attempt $i/60..." | |
| sleep 2 | |
| done | |
| echo "❌ Server failed to start!" | |
| cat packages/${{ matrix.package }}/server.log | |
| exit 1 | |
| - name: Run Playwright Tests | |
| working-directory: packages/${{ matrix.package }} | |
| run: pnpm test | |
| - name: Stop Server | |
| if: always() | |
| working-directory: packages/${{ matrix.package }} | |
| run: | | |
| if [ -f server.pid ]; then | |
| kill $(cat server.pid) 2>/dev/null || true | |
| rm server.pid | |
| fi | |
| - name: Upload Playwright Report | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-report-${{ matrix.package }} | |
| path: packages/${{ matrix.package }}/playwright-report/ | |
| retention-days: 7 | |
| - name: Upload Test Results | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: playwright-test-results-${{ matrix.package }} | |
| path: packages/${{ matrix.package }}/test-results/ | |
| retention-days: 7 |