chore(ci): improve CI workflows #444
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] | |
# 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 | |
jobs: | |
quality: | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "pnpm" # built-in pnpm cache | |
- name: Enable Corepack | |
run: corepack enable | |
- 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 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
registry-url: "https://registry.npmjs.org" | |
cache: "pnpm" # built-in pnpm cache | |
- name: Enable Corepack | |
run: corepack enable | |
# 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) | |
- name: Cache Firebase emulators | |
if: matrix.node-version == '20' # only download once per run | |
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- | |
# Ensure CLI available; pnpm dlx will use the pnpm cache and avoids global installs | |
- name: Pre-download Firebase emulators (cached) | |
if: matrix.node-version == '20' | |
run: pnpm dlx firebase-tools@14 setup:emulators:download | |
# Determine which packages have changed (you can wire this into conditional builds/tests later) | |
- name: Determine changed packages | |
id: changes | |
uses: dorny/paths-filter@v2 | |
with: | |
filters: | | |
react: | |
- 'packages/react/**' | |
angular: | |
- 'packages/angular/**' | |
# Optional turbo cache; helpful if you run incremental builds locally or use remote cache | |
- 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" | |
# Run emulator tests only once (Node 20). If you DO need both versions, remove the "if". | |
- name: Run tests with emulator | |
run: pnpm test:emulator |