Skip to content

Commit 4b3483b

Browse files
committed
chore(ci): improve CI workflows
1 parent 9ea8c43 commit 4b3483b

File tree

2 files changed

+73
-59
lines changed

2 files changed

+73
-59
lines changed

.github/workflows/test-react-firebase-v12.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,36 @@ on:
77
pull_request:
88
branches: [main]
99
paths:
10-
- 'packages/react/**'
11-
- 'dataconnect-sdk/**'
12-
- '.github/workflows/test-react-firebase-v12.yml'
10+
- "packages/react/**"
11+
- "dataconnect-sdk/**"
12+
- ".github/workflows/test-react-firebase-v12.yml"
1313

1414
jobs:
1515
test-react-v12:
1616
name: React Package - Firebase v12
1717
runs-on: ubuntu-latest
18-
18+
1919
steps:
2020
- name: Checkout code
2121
uses: actions/checkout@v4
2222

2323
- name: Setup Node.js
2424
uses: actions/setup-node@v4
2525
with:
26-
node-version: '20'
26+
node-version: "20"
2727

2828
- name: Enable Corepack
2929
run: corepack enable
3030

3131
- name: Install dependencies
3232
run: pnpm install
3333

34-
- name: Install Java
35-
run: |
36-
sudo apt-get update
37-
sudo apt-get install -y openjdk-17-jdk
38-
java -version
34+
# IMPROVED: Use actions/setup-java instead of apt-get
35+
- name: Setup Java
36+
uses: actions/setup-java@v4
37+
with:
38+
distribution: "temurin"
39+
java-version: "17"
3940

4041
- name: Install Firebase CLI
4142
uses: nick-invision/retry@v3
@@ -49,7 +50,7 @@ jobs:
4950
run: |
5051
# Update root devDependencies to Firebase v12
5152
pnpm add -Dw firebase@^12.1.0
52-
53+
5354
- name: Update Data Connect SDK for Firebase v12
5455
run: |
5556
# Manually update the generated SDK to support Firebase v12
@@ -58,7 +59,7 @@ jobs:
5859
# Update the peer dependency to include v12
5960
npm pkg set 'peerDependencies.firebase=^12.1.0'
6061
cd ../../..
61-
62+
6263
- name: Reinstall dependencies with v12
6364
run: |
6465
# Install with no-frozen-lockfile to allow dependency changes
@@ -72,7 +73,7 @@ jobs:
7273
run: |
7374
cd packages/react
7475
pnpm ls firebase | grep -E "firebase.*12\." || (echo "Firebase v12 not found!" && exit 1)
75-
76+
7677
- name: Build React package
7778
run: |
7879
cd packages/react
@@ -84,4 +85,3 @@ jobs:
8485
firebase emulators:exec --project test-project "cd packages/react && pnpm test:ci"
8586
env:
8687
CI: true
87-

.github/workflows/tests.yaml

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ name: Tests
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
pull_request:
8-
branches:
9-
- main
7+
branches: [main]
108

11-
# Cancel in-progress runs when a new run is queued on the same branch
129
concurrency:
1310
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
1411
cancel-in-progress: true
@@ -20,17 +17,23 @@ jobs:
2017
steps:
2118
- name: Checkout
2219
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 1
22+
23+
# Make pnpm available before setup-node uses cache: 'pnpm'
24+
- name: Enable Corepack (pnpm)
25+
run: |
26+
corepack enable
27+
corepack prepare pnpm@9.12.2 --activate
2328
2429
- name: Setup Node.js
2530
uses: actions/setup-node@v4
2631
with:
2732
node-version: "20"
28-
29-
- name: Enable Corepack
30-
run: corepack enable
33+
cache: "pnpm"
3134

3235
- name: Install dependencies
33-
run: pnpm install
36+
run: pnpm install --frozen-lockfile
3437

3538
- name: Run format check
3639
run: pnpm format
@@ -42,63 +45,74 @@ jobs:
4245
strategy:
4346
matrix:
4447
node-version: [20, 22]
48+
4549
steps:
4650
- name: Checkout code
4751
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 1
54+
55+
# Make pnpm available before setup-node uses cache: 'pnpm'
56+
- name: Enable Corepack (pnpm)
57+
run: |
58+
corepack enable
59+
corepack prepare pnpm@9.12.2 --activate
4860
4961
- name: Setup Node.js
5062
uses: actions/setup-node@v4
5163
with:
5264
node-version: ${{ matrix.node-version }}
53-
registry-url: "https://registry.npmjs.org"
54-
55-
- name: Enable Corepack
56-
run: corepack enable
57-
58-
- name: Install dependencies
59-
run: pnpm install
65+
cache: "pnpm"
6066

61-
- name: Install Java
62-
run: |
63-
sudo apt-get update
64-
sudo apt-get install -y openjdk-17-jdk
65-
java -version
67+
# Fast Java (no apt-get)
68+
- name: Setup Java (JDK 17)
69+
uses: actions/setup-java@v4
70+
with:
71+
distribution: "temurin"
72+
java-version: "17"
6673

74+
# Cache Firebase emulators (JARs) once
6775
- name: Cache Firebase emulators
76+
if: matrix.node-version == '20'
6877
uses: actions/cache@v4
6978
with:
70-
path: ~/.cache/firebase/emulators
71-
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('.github/workflows/tests.yaml') }}
79+
path: |
80+
~/.cache/firebase/emulators
81+
~/.cache/firebase/runtime
82+
key: ${{ runner.os }}-firebase-emulators-${{ hashFiles('firebase.json', '.firebaserc', 'package.json', 'pnpm-lock.yaml') }}
7283
restore-keys: |
7384
${{ runner.os }}-firebase-emulators-
7485
75-
- name: Install Firebase CLI
76-
uses: nick-invision/retry@v3
77-
with:
78-
timeout_minutes: 10
79-
retry_wait_seconds: 60
80-
max_attempts: 3
81-
command: npm i -g firebase-tools@latest
82-
83-
# Determine which packages have changed
84-
- name: Determine changed packages
85-
id: changes
86-
uses: dorny/paths-filter@v2
86+
# Ensure pnpm has a global bin dir on Linux runners (fixes ERR_PNPM_NO_GLOBAL_BIN_DIR)
87+
- name: Configure PNPM global bin
88+
if: matrix.node-version == '20'
89+
run: |
90+
echo "PNPM_HOME=$HOME/.local/share/pnpm" >> $GITHUB_ENV
91+
mkdir -p "$HOME/.local/share/pnpm"
92+
echo "$HOME/.local/share/pnpm" >> $GITHUB_PATH
93+
94+
# Install Firebase CLI globally so pnpm test:emulator works
95+
- name: Install Firebase CLI (global, fast)
96+
if: matrix.node-version == '20'
97+
run: pnpm add -g firebase-tools@14
98+
99+
# Optional turbo cache
100+
- name: Cache turbo build metadata
101+
uses: actions/cache@v4
87102
with:
88-
filters: |
89-
react:
90-
- 'packages/react/**'
91-
angular:
92-
- 'packages/angular/**'
103+
path: .turbo
104+
key: ${{ runner.os }}-turbo-${{ github.sha }}
105+
restore-keys: |
106+
${{ runner.os }}-turbo-
107+
108+
- name: Install dependencies
109+
run: pnpm install --frozen-lockfile
93110

94-
# Build packages before testing
95111
- name: Build packages
96112
run: pnpm turbo build
97113

98-
# Verify build outputs
99114
- name: Verify build outputs
100115
run: |
101-
# Check all packages for dist directories
102116
MISSING_BUILDS=""
103117
for PKG_DIR in packages/*; do
104118
if [ -d "$PKG_DIR" ] && [ -f "$PKG_DIR/package.json" ]; then
@@ -108,13 +122,13 @@ jobs:
108122
fi
109123
fi
110124
done
111-
112125
if [ -n "$MISSING_BUILDS" ]; then
113126
echo "❌ Build outputs not found for: $MISSING_BUILDS"
114127
exit 1
115128
fi
116129
echo "✅ All build outputs verified"
117130
118-
# Run tests with all emulators (auth, firestore, and data-connect)
131+
# Run emulator tests only once (Node 20)
119132
- name: Run tests with emulator
133+
if: matrix.node-version == '20'
120134
run: pnpm test:emulator

0 commit comments

Comments
 (0)