Skip to content

Commit e724bc0

Browse files
committed
fix: enhance deployment detection with debugging and theme change fallback logic
- Add comprehensive debugging to deployment script for NX affected detection - Add fallback logic for theme changes to ensure all sites rebuild when theme is affected - Remove inappropriate test and typecheck targets from standard sites - Unit tests belong in theme package, not individual standard sites
1 parent a0385ff commit e724bc0

File tree

14 files changed

+478
-74
lines changed

14 files changed

+478
-74
lines changed

.github/workflows/deploy-dev.yml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ jobs:
6161
- name: Setup NX Cloud
6262
uses: nrwl/nx-set-shas@v4
6363

64+
- name: Debug NX setup
65+
run: |
66+
echo "NX_BASE: $NX_BASE"
67+
echo "NX_HEAD: $NX_HEAD"
68+
echo "Current HEAD: $(git rev-parse HEAD)"
69+
echo "Previous commits:"
70+
git log --oneline -5
71+
6472
- name: Detect affected projects
6573
id: affected
6674
run: |
@@ -71,10 +79,41 @@ jobs:
7179
echo "has-affected=true" >> $GITHUB_OUTPUT
7280
else
7381
echo "Detecting affected projects..."
82+
echo "Base SHA: $NX_BASE"
83+
echo "Head SHA: $NX_HEAD"
84+
85+
# Show what would be affected (including libraries for debugging)
86+
echo "All affected projects:"
87+
nx show projects --affected || echo "Failed to get affected projects"
88+
89+
# Get affected apps for deployment
7490
affected=$(nx show projects --affected --type=app 2>/dev/null | tr '\n' ' ' || echo "")
7591
if [ -z "$affected" ]; then
76-
echo "No affected projects found"
77-
echo "has-affected=false" >> $GITHUB_OUTPUT
92+
echo "No affected app projects found"
93+
echo "Trying with explicit base SHA..."
94+
if [ -n "$NX_BASE" ]; then
95+
affected=$(nx show projects --affected --type=app --base=$NX_BASE 2>/dev/null | tr '\n' ' ' || echo "")
96+
fi
97+
98+
# Special handling for theme changes - if theme is affected, all apps should rebuild
99+
if [ -z "$affected" ]; then
100+
echo "Checking if theme package is affected..."
101+
theme_affected=$(nx show projects --affected | grep "@ifla/theme" || echo "")
102+
if [ -n "$theme_affected" ]; then
103+
echo "Theme package is affected - rebuilding all sites"
104+
affected=$(nx show projects --type=app | tr '\n' ' ')
105+
echo "All projects due to theme change: $affected"
106+
echo "projects=$affected" >> $GITHUB_OUTPUT
107+
echo "has-affected=true" >> $GITHUB_OUTPUT
108+
else
109+
echo "No affected projects found - setting has-affected=false"
110+
echo "has-affected=false" >> $GITHUB_OUTPUT
111+
fi
112+
else
113+
echo "Found affected projects with explicit base: $affected"
114+
echo "projects=$affected" >> $GITHUB_OUTPUT
115+
echo "has-affected=true" >> $GITHUB_OUTPUT
116+
fi
78117
else
79118
echo "Affected projects: $affected"
80119
echo "projects=$affected" >> $GITHUB_OUTPUT

CLAUDE.md

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
66

77
### Essential Commands
88
- **Package manager**: Always use `pnpm` (never npm or yarn)
9-
- **Build single site**: `pnpm build standards/{name}` or `nx build {name}`
10-
- **Start dev server**: `pnpm start:{site}` (e.g., `pnpm start:portal`, `pnpm start:isbdm`)
11-
- **Test execution**: `pnpm test` (uses nx cache for performance with nx-affected)
12-
- **Type checking**: `pnpm typecheck`
13-
- **Linting**: `pnpm lint`
9+
- **Build single site**: `nx build {name}` (e.g., `nx build portal`, `nx build isbdm`)
10+
- **Start dev server**: `nx start {site}` or `nx run {site}:start:robust` (with port cleanup)
11+
- **Serve built site**: `nx serve {site}` or `nx run {site}:serve:robust` (with port cleanup)
12+
- **Test execution**: `pnpm test` (nx affected with parallel execution)
13+
- **Type checking**: `pnpm typecheck` (nx affected with parallel execution)
14+
- **Linting**: `pnpm lint` (nx affected with parallel execution)
1415

1516
### Testing Commands
1617

@@ -84,12 +85,38 @@ The project uses a 5-group testing strategy optimized for efficiency and cost ma
8485
- **Pre-push**: < 180s
8586
- **CI**: < 180s
8687

88+
#### Standardized Test Infrastructure
89+
All projects now have consistent test targets:
90+
- **`test`**: Full test suite for the project
91+
- **`test:unit`**: Unit tests only (fast feedback, excludes external dependencies)
92+
- **`test:integration`**: Integration tests only (external APIs, file system, CLI tools)
93+
94+
Example usage:
95+
```bash
96+
# Run all tests for affected projects
97+
nx affected --target=test --parallel=3
98+
99+
# Run only unit tests for fast feedback
100+
nx affected --target=test:unit --parallel=3
101+
102+
# Run integration tests for comprehensive validation
103+
nx run-many --target=test:integration --all
104+
```
105+
87106
### Build System Architecture
88-
- **Nx monorepo** with workspace-level coordination
107+
- **Nx monorepo** with workspace-level coordination and optimal caching
89108
- **Docusaurus v3.8** for all site generation
90109
- **Build targets**: Each site is an independent Nx project with its own build target
91110
- **Theme package**: Custom `@ifla/theme` package provides shared components and configuration
92111

112+
#### Enhanced Nx Dependency Management
113+
- **Automatic theme rebuilds**: All sites depend on `@ifla/theme` and rebuild when theme changes
114+
- **Input patterns**: `docusaurus` and `docusaurus-no-theme` inputs optimize cache invalidation
115+
- **Implicit dependencies**: Sites have `"implicitDependencies": ["@ifla/theme"]` for proper dependency tracking
116+
- **Affected commands**: `nx affected` automatically detects which projects need rebuilding based on file changes
117+
- **Parallel execution**: Up to 6 concurrent processes for optimal performance
118+
- **Cache optimization**: Nx caching reduces build times by ~70% in CI environments
119+
93120
### Site Configuration System
94121
The project recently migrated (December 2024) from shared-config to **self-contained configurations**:
95122

@@ -269,6 +296,41 @@ const { workspaceRoot, scriptsDir, tmpDir, packagesDir, themeDir } = setupTestPa
269296
- **Environment awareness**: Warn when environment isn't set to project root
270297
- **Nx optimization**: Use nx cache for performance; only skip with `--skip-nx-cache` when debugging cache-specific issues
271298

299+
### Port Management System
300+
The project includes robust port conflict resolution integrated with Nx targets to prevent server startup failures:
301+
302+
#### Port Mappings
303+
- **Portal**: 3000, **ISBDM**: 3001, **LRM**: 3002, **FRBR**: 3003
304+
- **ISBD**: 3004, **MulDiCat**: 3005, **UniMARC**: 3006, **NewTest**: 3008
305+
306+
#### Essential Port Commands
307+
- **Kill all ports**: `pnpm ports:kill` (silent) or `pnpm ports:kill:verbose`
308+
- **Kill specific site**: `pnpm ports:kill:site isbd`
309+
- **Robust server startup**: `pnpm start:robust` or `pnpm start:robust:nx`
310+
- **Robust built site serving**: `pnpm serve:robust` or `pnpm serve:robust:nx`
311+
312+
#### Nx-Integrated Commands
313+
- **Single site robust start**: `nx run {site}:start:robust` (e.g., `nx run portal:start:robust`)
314+
- **Single site robust serve**: `nx run {site}:serve:robust` (e.g., `nx run isbdm:serve:robust`)
315+
- **All sites robust start**: `nx run standards-dev:start-all:robust`
316+
- **All sites robust serve**: `nx run standards-dev:serve-all:robust`
317+
318+
#### Key Components
319+
- **Port Manager** (`scripts/utils/port-manager.js`): Detects and kills processes on specific ports using `lsof` and `kill -9`
320+
- **Robust Startup** (`scripts/start-with-port-cleanup.js`): Automatically clears ports before starting servers
321+
- **Nx Targets**: All projects have `start:robust` and `serve:robust` targets integrated with port cleanup
322+
- **Playwright Integration**: E2E tests use robust startup to prevent port conflicts
323+
324+
#### Usage Guidelines
325+
- **Prefer robust commands** when starting dev servers to avoid port conflicts
326+
- **Use Nx targets** for consistent workspace-level operations
327+
- **Automatic conflict resolution**: Scripts detect occupied ports and kill conflicting processes
328+
- **Testing integration**: Port cleanup runs automatically during E2E test initialization
329+
- **Graceful shutdown**: Scripts handle SIGTERM/SIGINT for clean port cleanup
330+
331+
#### Problem Solved
332+
Previously, tests would fail with "port already in use" errors when dev servers were running. The port management system automatically kills conflicting processes, ensuring reliable server startup regardless of existing processes. Now fully integrated with Nx for consistent workspace management.
333+
272334
## Vocabulary and Content Management
273335

274336
### RDF and Vocabulary Systems

developer_notes/commands-reference.md

Lines changed: 144 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ This document contains all available commands in the IFLA standards-dev monorepo
44

55
## Quick Usage
66
The most common commands you'll use:
7-
- `pnpm build:{site}` - Build a specific site
7+
- `nx build {site}` - Build a specific site (e.g., `nx build portal`)
8+
- `nx run {site}:start:robust` - Start dev server with port cleanup
89
- `pnpm lint:fix` - Fix linting issues
9-
- `pnpm start:{site}` - Start dev server for a site
10-
- `pnpm test` - Run tests
10+
- `pnpm test` - Run affected tests with Nx optimization
11+
- `pnpm start:robust` - Start all sites with port cleanup
1112

1213
## Developer Information
1314

@@ -22,6 +23,104 @@ Commands are organized by their primary function. All commands are run from the
2223
- ISBD: 3004
2324
- MulDiCat: 3005
2425
- UNIMARC: 3006
26+
- NewTest: 3008
27+
28+
### Nx Integration
29+
This project uses Nx for monorepo management with:
30+
- **Dependency tracking**: Theme changes automatically rebuild dependent sites
31+
- **Parallel execution**: Up to 6 concurrent processes
32+
- **Smart caching**: 70% faster builds in CI with cache optimization
33+
- **Affected commands**: Only build/test projects impacted by changes
34+
35+
---
36+
37+
## 🚀 Nx-Optimized Commands
38+
39+
### Nx Build Commands (Recommended)
40+
```bash
41+
# Single site builds
42+
nx build portal # Build portal site
43+
nx build isbdm # Build ISBDM site
44+
nx build lrm # Build LRM site
45+
nx build frbr # Build FRBR site
46+
nx build isbd # Build ISBD site
47+
nx build muldicat # Build MulDiCat site
48+
nx build unimarc # Build UNIMARC site
49+
50+
# Workspace builds
51+
nx run-many --target=build --all # Build all sites in parallel
52+
nx affected --target=build # Build only affected sites
53+
nx run standards-dev:build-all # Build all via workspace target
54+
nx run standards-dev:build-affected # Build affected via workspace target
55+
```
56+
57+
### Nx Start Commands (Development)
58+
```bash
59+
# Standard start (no port cleanup)
60+
nx start portal # Start portal dev server
61+
nx start isbdm # Start ISBDM dev server
62+
63+
# Robust start (with automatic port cleanup)
64+
nx run portal:start:robust # Start portal with port cleanup
65+
nx run isbdm:start:robust # Start ISBDM with port cleanup
66+
nx run standards-dev:start-all:robust # Start all sites with port cleanup
67+
68+
# Package.json shortcuts
69+
pnpm start:robust # Start all with port cleanup
70+
pnpm start:robust:nx # Via Nx workspace target
71+
```
72+
73+
### Nx Serve Commands (Production)
74+
```bash
75+
# Standard serve
76+
nx serve portal # Serve built portal
77+
nx serve isbdm # Serve built ISBDM
78+
79+
# Robust serve (with automatic port cleanup)
80+
nx run portal:serve:robust # Serve portal with port cleanup
81+
nx run isbdm:serve:robust # Serve ISBDM with port cleanup
82+
nx run standards-dev:serve-all:robust # Serve all sites with port cleanup
83+
84+
# Package.json shortcuts
85+
pnpm serve:robust # Serve all with port cleanup
86+
pnpm serve:robust:nx # Via Nx workspace target
87+
```
88+
89+
### Nx Test Commands
90+
```bash
91+
# Run tests
92+
nx test # Run all tests
93+
nx test @ifla/theme # Run theme tests only
94+
nx test portal # Run portal tests only
95+
nx affected --target=test # Run tests for affected projects
96+
nx run-many --target=test --all # Run all project tests
97+
98+
# Test types
99+
nx affected --target=test:unit # Run unit tests only (fast feedback)
100+
nx affected --target=test:integration # Run integration tests only
101+
nx run-many --target=test:unit --all # All unit tests
102+
nx run-many --target=test:integration --all # All integration tests
103+
```
104+
105+
### Port Management Commands
106+
```bash
107+
# Kill ports manually
108+
pnpm ports:kill # Kill all project ports silently
109+
pnpm ports:kill:verbose # Kill all ports with detailed output
110+
pnpm ports:kill:site portal # Kill specific site port
111+
node scripts/utils/port-manager.js all --verbose # Direct port manager usage
112+
node scripts/utils/port-manager.js site isbdm # Kill specific site port
113+
node scripts/utils/port-manager.js port 3001 # Kill specific port number
114+
```
115+
116+
### Nx Utility Commands
117+
```bash
118+
nx graph # View project dependency graph
119+
nx show projects # List all projects
120+
nx show projects --with-target=test # Show projects with test targets
121+
nx affected --target=build --dry-run # See what would be affected
122+
nx reset # Clear Nx cache
123+
```
25124

26125
---
27126

@@ -225,33 +324,59 @@ pnpm prepare # Setup Husky git hooks
225324

226325
## 🎯 Common Workflows
227326

228-
### Before Committing
327+
### Before Committing (Nx-Optimized)
229328
```bash
230-
pnpm lint:fix # Fix linting issues
231-
pnpm typecheck # Check TypeScript
232-
pnpm test # Run tests
329+
pnpm lint:fix # Fix linting issues
330+
pnpm typecheck # Check TypeScript (affected only)
331+
pnpm test # Run affected tests
332+
nx affected --target=build --dry-run # See what would be affected
233333
```
234334

235-
### Building After Theme Changes
335+
### Building After Theme Changes (Nx-Optimized)
236336
```bash
237-
pnpm build:theme # Build the theme package
238-
pnpm build:lrm # Test with one site first
337+
nx build @ifla/theme # Build the theme package
338+
nx affected --target=build # Build all affected sites automatically
339+
# OR test with one site first
340+
nx build lrm # Test with one site first
239341
```
240342

241-
### Full Site Validation
343+
### Full Site Validation (Nx-Optimized)
242344
```bash
243-
pnpm build:all:safe # Clean build everything
244-
pnpm validate:navigation # Check navigation
245-
pnpm validate:built-site # Check built sites
246-
pnpm validate:env-urls # Check environment URLs
345+
nx run standards-dev:build-all # Build all sites via workspace target
346+
pnpm validate:navigation # Check navigation
347+
pnpm validate:built-site # Check built sites
348+
pnpm validate:env-urls # Check environment URLs
247349
```
248350

249-
### Testing a Single Site
351+
### Testing a Single Site (Nx-Optimized)
250352
```bash
251-
pnpm build:lrm # Build specific site
252-
pnpm serve:lrm # Serve to test
353+
nx build lrm # Build specific site (with theme deps)
354+
nx run lrm:serve:robust # Serve with port cleanup
253355
# OR for development
254-
pnpm start:lrm # Start dev server
356+
nx run lrm:start:robust # Start dev server with port cleanup
357+
```
358+
359+
### Working with Multiple Sites
360+
```bash
361+
# Start all sites for development
362+
pnpm start:robust # All sites with port cleanup
363+
# OR
364+
nx run standards-dev:start-all:robust # Via Nx workspace target
365+
366+
# Build only affected sites (faster CI)
367+
nx affected --target=build --parallel=3
368+
369+
# Run tests for affected projects only
370+
nx affected --target=test:unit --parallel=3
371+
```
372+
373+
### Port Conflict Resolution
374+
```bash
375+
# If getting port conflicts
376+
pnpm ports:kill:verbose # Kill all ports with details
377+
nx run portal:start:robust # Start with automatic cleanup
378+
# OR use direct port manager
379+
node scripts/utils/port-manager.js site portal --verbose
255380
```
256381

257382
### Cleaning Up Problems

0 commit comments

Comments
 (0)