chore(ci): improve CI workflows #445
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: Tests | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
quality: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
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 | |
# Optional but recommended: pin pnpm for reproducibility | |
corepack prepare pnpm@9.12.2 --activate | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "pnpm" | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Run format check | |
run: pnpm format | |
test: | |
runs-on: ubuntu-latest | |
timeout-minutes: 30 | |
needs: quality | |
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" | |
cache: "pnpm" | |
# 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 | |
~/.cache/firebase/runtime | |
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('firebase.json', '.firebaserc', 'package.json', 'pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-firebase-emulators- | |
# Pre-download emulator JARs (uses pnpm cache) | |
- name: Pre-download Firebase emulators (cached) | |
if: matrix.node-version == '20' | |
run: pnpm dlx firebase-tools@14 setup:emulators:download | |
# Ensure firebase CLI is available for the test step (Node 20) | |
- name: Install Firebase CLI (global, fast) | |
if: matrix.node-version == '20' | |
run: | | |
pnpm add -g firebase-tools@14 | |
echo "$(pnpm bin -g)" >> $GITHUB_PATH | |
- name: Cache turbo build metadata | |
uses: actions/cache@v4 | |
with: | |
path: .turbo | |
key: ${{ runner.os }}-turbo-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-turbo- | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Build packages | |
run: pnpm turbo build | |
- name: Verify build outputs | |
run: | | |
MISSING_BUILDS="" | |
for PKG_DIR in packages/*; do | |
if [ -d "$PKG_DIR" ] && [ -f "$PKG_DIR/package.json" ]; then | |
PKG_NAME=$(basename "$PKG_DIR") | |
if [ ! -d "$PKG_DIR/dist" ]; then | |
MISSING_BUILDS="$MISSING_BUILDS $PKG_NAME" | |
fi | |
fi | |
done | |
if [ -n "$MISSING_BUILDS" ]; then | |
echo "❌ Build outputs not found for: $MISSING_BUILDS" | |
exit 1 | |
fi | |
echo "✅ All build outputs verified" | |
# ✅ Only run emulator tests once on Node 20 | |
- name: Run tests with emulator | |
if: matrix.node-version == '20' | |
run: pnpm test:emulator |