diff --git a/.github/workflows/test-react-firebase-v12.yml b/.github/workflows/test-react-firebase-v12.yml index c9d3d9df..610e74dc 100644 --- a/.github/workflows/test-react-firebase-v12.yml +++ b/.github/workflows/test-react-firebase-v12.yml @@ -7,15 +7,15 @@ on: pull_request: branches: [main] paths: - - 'packages/react/**' - - 'dataconnect-sdk/**' - - '.github/workflows/test-react-firebase-v12.yml' + - "packages/react/**" + - "dataconnect-sdk/**" + - ".github/workflows/test-react-firebase-v12.yml" jobs: test-react-v12: name: React Package - Firebase v12 runs-on: ubuntu-latest - + steps: - name: Checkout code uses: actions/checkout@v4 @@ -23,7 +23,7 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: '20' + node-version: "20" - name: Enable Corepack run: corepack enable @@ -31,11 +31,12 @@ jobs: - name: Install dependencies run: pnpm install - - name: Install Java - run: | - sudo apt-get update - sudo apt-get install -y openjdk-17-jdk - java -version + # IMPROVED: Use actions/setup-java instead of apt-get + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" - name: Install Firebase CLI uses: nick-invision/retry@v3 @@ -49,7 +50,7 @@ jobs: run: | # Update root devDependencies to Firebase v12 pnpm add -Dw firebase@^12.1.0 - + - name: Update Data Connect SDK for Firebase v12 run: | # Manually update the generated SDK to support Firebase v12 @@ -58,7 +59,7 @@ jobs: # Update the peer dependency to include v12 npm pkg set 'peerDependencies.firebase=^12.1.0' cd ../../.. - + - name: Reinstall dependencies with v12 run: | # Install with no-frozen-lockfile to allow dependency changes @@ -72,7 +73,7 @@ jobs: run: | cd packages/react pnpm ls firebase | grep -E "firebase.*12\." || (echo "Firebase v12 not found!" && exit 1) - + - name: Build React package run: | cd packages/react @@ -84,4 +85,3 @@ jobs: firebase emulators:exec --project test-project "cd packages/react && pnpm test:ci" env: CI: true - diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dda94f71..a6948908 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -2,13 +2,10 @@ name: Tests on: push: - branches: - - main + branches: [main] pull_request: - branches: - - main + branches: [main] -# Cancel in-progress runs when a new run is queued on the same branch concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true @@ -20,17 +17,23 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 1 + + # Make pnpm available before setup-node uses cache: 'pnpm' + - name: Enable Corepack (pnpm) + run: | + corepack enable + corepack prepare pnpm@9.12.2 --activate - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "20" - - - name: Enable Corepack - run: corepack enable + cache: "pnpm" - name: Install dependencies - run: pnpm install + run: pnpm install --frozen-lockfile - name: Run format check run: pnpm format @@ -42,63 +45,74 @@ jobs: strategy: matrix: node-version: [20, 22] + steps: - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 1 + + # Make pnpm available before setup-node uses cache: 'pnpm' + - name: Enable Corepack (pnpm) + run: | + corepack enable + corepack prepare pnpm@9.12.2 --activate - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - registry-url: "https://registry.npmjs.org" - - - name: Enable Corepack - run: corepack enable - - - name: Install dependencies - run: pnpm install + cache: "pnpm" - - name: Install Java - run: | - sudo apt-get update - sudo apt-get install -y openjdk-17-jdk - java -version + # Fast Java (no apt-get) + - name: Setup Java (JDK 17) + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: "17" + # Cache Firebase emulators (JARs) once - name: Cache Firebase emulators + if: matrix.node-version == '20' uses: actions/cache@v4 with: - path: ~/.cache/firebase/emulators - key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('.github/workflows/tests.yaml') }} + path: | + ~/.cache/firebase/emulators + ~/.cache/firebase/runtime + key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('firebase.json', '.firebaserc', 'package.json', 'pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-firebase-emulators- - - name: Install Firebase CLI - uses: nick-invision/retry@v3 - with: - timeout_minutes: 10 - retry_wait_seconds: 60 - max_attempts: 3 - command: npm i -g firebase-tools@latest - - # Determine which packages have changed - - name: Determine changed packages - id: changes - uses: dorny/paths-filter@v2 + # Ensure pnpm has a global bin dir on Linux runners (fixes ERR_PNPM_NO_GLOBAL_BIN_DIR) + - name: Configure PNPM global bin + if: matrix.node-version == '20' + run: | + echo "PNPM_HOME=$HOME/.local/share/pnpm" >> $GITHUB_ENV + mkdir -p "$HOME/.local/share/pnpm" + echo "$HOME/.local/share/pnpm" >> $GITHUB_PATH + + # Install Firebase CLI globally so pnpm test:emulator works + - name: Install Firebase CLI (global, fast) + if: matrix.node-version == '20' + run: pnpm add -g firebase-tools@14 + + # Optional turbo cache + - name: Cache turbo build metadata + uses: actions/cache@v4 with: - filters: | - react: - - 'packages/react/**' - angular: - - 'packages/angular/**' + path: .turbo + key: ${{ runner.os }}-turbo-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-turbo- + + - name: Install dependencies + run: pnpm install --frozen-lockfile - # Build packages before testing - name: Build packages run: pnpm turbo build - # Verify build outputs - name: Verify build outputs run: | - # Check all packages for dist directories MISSING_BUILDS="" for PKG_DIR in packages/*; do if [ -d "$PKG_DIR" ] && [ -f "$PKG_DIR/package.json" ]; then @@ -108,13 +122,13 @@ jobs: fi fi done - if [ -n "$MISSING_BUILDS" ]; then echo "❌ Build outputs not found for: $MISSING_BUILDS" exit 1 fi echo "✅ All build outputs verified" - # Run tests with all emulators (auth, firestore, and data-connect) + # Run emulator tests only once (Node 20) - name: Run tests with emulator + if: matrix.node-version == '20' run: pnpm test:emulator