@@ -246,23 +246,57 @@ jobs:
246246 echo "Action: run 'npm audit fix --package-lock-only' in config/lighthouse and commit package-lock.json."
247247 exit 1
248248
249- # � Front-load Lighthouse node_modules so the Audit job skips npm install
249+ # 📦 Front-load ALL Lighthouse dependencies so the Audit job is cache-hit only.
250+ # Why: Security scanning runs here (fail-fast before builds/deploy), and the Audit
251+ # job skips npm install + security scan entirely — it just restores and runs Lighthouse.
250252 - name : 📦 Cache Lighthouse node_modules
251253 id : lighthouse-modules
252254 uses : actions/cache@v4
253255 with :
254256 path : config/lighthouse/node_modules
255257 key : ${{ runner.os }}-lh-modules-${{ hashFiles('config/lighthouse/package-lock.json') }}
256258
257- - name : 📦 Seed Lighthouse dependency cache
259+ - name : 📦 Install and scan Lighthouse dependencies
258260 if : steps.lighthouse-modules.outputs.cache-hit != 'true'
259261 run : |
262+ echo "=== 📦 Installing Lighthouse dependencies (first run or lockfile changed) ==="
260263 cd config/lighthouse
261- npm ci --ignore-scripts -- no-fund
262- echo "✅ Lighthouse node_modules cached for Audit job"
264+ npm ci --no-fund
265+ echo "✅ Lighthouse node_modules installed and cached for Audit job"
263266
264- # �🔧 Install Trivy (lightweight, fast install - caching not needed)
265- - name : �️ Install Trivy
267+ - name : 🔒 Lighthouse NPM security scan (fail-fast)
268+ run : |
269+ echo "=== 🔒 Lighthouse Dependency Security Scan ==="
270+ source openshift/scripts/utils/npm.sh
271+ cd config/lighthouse
272+
273+ # Full security audit — catch issues BEFORE builds and deployment
274+ npm_audit_scan "." "high" "LH_SECURITY_RESULT"
275+ scan_exit=$?
276+
277+ if [ $scan_exit -eq 2 ]; then
278+ echo "❌ CRITICAL: Lighthouse dependencies have critical vulnerabilities!"
279+ echo " These must be resolved before deployment proceeds."
280+ echo " Run: cd config/lighthouse && npm audit fix && commit package-lock.json"
281+ # Non-blocking for now — Lighthouse is test tooling, not deployed code.
282+ # Change 'exit 0' to 'exit 2' to make this a hard blocker.
283+ exit 0
284+ elif [ $scan_exit -eq 1 ]; then
285+ echo "⚠️ HIGH: High-severity vulnerabilities detected in Lighthouse deps (non-blocking)"
286+ else
287+ echo "✅ Lighthouse dependency security scan passed"
288+ fi
289+
290+ # 🐧 Seed Lighthouse APT package cache (Chrome headless dependencies)
291+ # Running this in checkEnv means the Audit job gets a cache hit instead of a cold install.
292+ - name : 🐧 Seed Lighthouse APT cache
293+ uses : awalsh128/cache-apt-pkgs-action@latest
294+ with :
295+ packages : gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
296+ version : 1.0
297+
298+ # 🔧 Install Trivy (lightweight, fast install - caching not needed)
299+ - name : 🛡️ Install Trivy
266300 run : |
267301 # Trivy installation is fast (~5-10s), no need to cache
268302 sudo apt-get update
@@ -698,16 +732,17 @@ jobs:
698732
699733 - run : mkdir -p tmp/artifacts
700734
701- # � Restore pre-built Lighthouse node_modules (seeded by checkEnv job)
735+ # All caches below were seeded by the checkEnv job.
736+ # 📦 Restore Lighthouse node_modules (installed + scanned by checkEnv)
702737 - name : 📦 Restore Lighthouse node_modules
703738 id : lighthouse-modules
704739 uses : actions/cache/restore@v4
705740 with :
706741 path : config/lighthouse/node_modules
707742 key : ${{ runner.os }}-lh-modules-${{ hashFiles('config/lighthouse/package-lock.json') }}
708743
709- # �🐧 Cache APT packages for Lighthouse dependencies
710- - name : 🐧 Cache APT packages
744+ # 🐧 Restore Chrome APT dependencies (seeded by checkEnv)
745+ - name : 🐧 Restore APT packages
711746 uses : awalsh128/cache-apt-pkgs-action@latest
712747 with :
713748 packages : gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
@@ -718,22 +753,19 @@ jobs:
718753 with :
719754 install-dependencies : false
720755
721- # 🏗️ Lighthouse Environment Setup
722- # NOTE: Full security scan (Trivy, PHP, containers) already completed in checkEnv job.
723- # node_modules pre-built by checkEnv and restored from cache above.
756+ # 🏗️ Validate cache-restored deps or install on miss (fallback)
724757 - name : 🏗️ Lighthouse Environment Setup
725758 run : |
726- source openshift/scripts/utils/lighthouse.sh
727-
728759 echo "=== 🏗️ Lighthouse Environment Setup ==="
729760
730- # Fast path: validate cache-restored node_modules
731761 if [ -d "config/lighthouse/node_modules/lighthouse" ] && \
732762 cd config/lighthouse && npm list lighthouse puppeteer --depth=0 >/dev/null 2>&1; then
733- echo "✅ Lighthouse dependencies restored from cache (skipping install)"
763+ echo "✅ Cache hit — Lighthouse deps restored (skipping install)"
734764 cd ../..
735765 else
736- echo "⚠️ Cache miss — running full Lighthouse environment setup..."
766+ echo "⚠️ Cache miss — installing Lighthouse dependencies..."
767+ cd config/lighthouse 2>/dev/null && cd ../.. || true
768+ source openshift/scripts/utils/lighthouse.sh
737769 source openshift/scripts/utils/npm.sh
738770 if ! setup_lighthouse_environment "config/lighthouse" "true"; then
739771 echo "❌ Lighthouse environment setup failed"
0 commit comments