Skip to content

Commit 6fd5f67

Browse files
fix(lighthouse): use absolute config path in setup validation
Resolve config directory to an absolute path in setup_lighthouse_environment to avoid cwd-dependent failures after npm_install_secure. This prevents false setup failures when warning-mode npm checks return non-critical findings.
1 parent 7f88fd8 commit 6fd5f67

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

openshift/scripts/utils/lighthouse.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,29 @@ setup_lighthouse_environment() {
201201
log_debug "Changed to workspace root: $GITHUB_WORKSPACE"
202202
fi
203203

204+
# Resolve to an absolute path so cwd changes do not break subsequent checks
205+
local full_config_path="$workspace_root/$config_dir"
206+
if [[ "$config_dir" = /* ]]; then
207+
full_config_path="$config_dir"
208+
fi
209+
204210
# Verify the directory exists before attempting to install
205-
if [ ! -d "$config_dir" ]; then
206-
log_error "Lighthouse config directory not found: $config_dir"
211+
if [ ! -d "$full_config_path" ]; then
212+
log_error "Lighthouse config directory not found: $full_config_path"
207213
log_error "Current directory: $(pwd)"
208214
log_error "Directory listing: $(ls -la | head -5)"
209215
return 1
210216
fi
211217

212218
# Verify package.json exists
213-
if [ ! -f "$config_dir/package.json" ]; then
214-
log_error "package.json not found in: $config_dir"
215-
log_error "Expected file: $config_dir/package.json"
216-
log_error "Directory contents: $(ls -la $config_dir/ 2>/dev/null || echo 'directory not accessible')"
219+
if [ ! -f "$full_config_path/package.json" ]; then
220+
log_error "package.json not found in: $full_config_path"
221+
log_error "Expected file: $full_config_path/package.json"
222+
log_error "Directory contents: $(ls -la "$full_config_path"/ 2>/dev/null || echo 'directory not accessible')"
217223
return 1
218224
fi
219225

220-
log_debug "Found package.json in $config_dir"
226+
log_debug "Found package.json in $full_config_path"
221227

222228
# Source npm utilities from workspace root (don't cd first)
223229
source "./openshift/scripts/utils/npm.sh"
@@ -232,7 +238,7 @@ setup_lighthouse_environment() {
232238
elif [ "$npm_install_exit" -eq 1 ]; then
233239
# Exit code 1 can be warning-level NPM findings (high/moderate) in post-install scan.
234240
# For Lighthouse (test tooling), we allow warning-level findings if dependencies are present.
235-
if cd "$config_dir" && npm list lighthouse puppeteer --depth=0 >/dev/null 2>&1; then
241+
if cd "$full_config_path" && npm list lighthouse puppeteer --depth=0 >/dev/null 2>&1; then
236242
log_warn "Lighthouse dependency installation completed with non-critical security warnings"
237243
log_warn "Proceeding in warning mode; review npm audit/Dependabot updates"
238244
else
@@ -251,8 +257,8 @@ setup_lighthouse_environment() {
251257
}
252258

253259
# Verify required packages (now cd from workspace root)
254-
cd "$config_dir" || {
255-
log_error "Failed to change to config directory for verification: $config_dir"
260+
cd "$full_config_path" || {
261+
log_error "Failed to change to config directory for verification: $full_config_path"
256262
return 1
257263
}
258264

0 commit comments

Comments
 (0)