diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 53b4474..d06eb2d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,6 +46,18 @@ jobs: git pull origin main + # Build CSS bundle for production + echo "🎨 Building CSS bundle..." + if command -v lightningcss &> /dev/null; then + mkdir -p static/dist + lightningcss --bundle --minify static/css/main.css -o static/dist/bundle.min.css + echo "✅ CSS bundle created ($(du -h static/dist/bundle.min.css | cut -f1))" + else + echo "⚠️ lightningcss not found, falling back to modular CSS" + # Ensure dist directory doesn't exist so template falls back to main.css + rm -rf static/dist + fi + # Reapply stashed changes if any (optional - comment out if not needed) # if git stash list | grep -q "Auto-stash"; then # echo "♻️ Reapplying stashed changes..." diff --git a/internal/handlers/cv_helpers.go b/internal/handlers/cv_helpers.go index 1ad7890..f2dfc0a 100644 --- a/internal/handlers/cv_helpers.go +++ b/internal/handlers/cv_helpers.go @@ -330,8 +330,16 @@ func (h *CVHandler) prepareTemplateData(lang string) (map[string]interface{}, er // Get current year currentYear := time.Now().Year() - // Check if production mode + // Check if production mode AND CSS bundle exists + // This ensures graceful fallback to modular CSS if bundle not built isProduction := os.Getenv("GO_ENV") == "production" + if isProduction { + bundlePath := filepath.Join("static", "dist", "bundle.min.css") + if _, err := os.Stat(bundlePath); os.IsNotExist(err) { + // Bundle doesn't exist, fall back to modular CSS + isProduction = false + } + } // Prepare template data data := map[string]interface{}{ diff --git a/internal/middleware/preferences_test.go b/internal/middleware/preferences_test.go index b1e0a76..9acaa5e 100644 --- a/internal/middleware/preferences_test.go +++ b/internal/middleware/preferences_test.go @@ -3,7 +3,6 @@ package middleware import ( "net/http" "net/http/httptest" - "os" "testing" ) @@ -385,12 +384,8 @@ func TestIsProductionMode(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Save original environment - originalEnv := os.Getenv("GO_ENV") - defer os.Setenv("GO_ENV", originalEnv) - - // Set test environment - os.Setenv("GO_ENV", tt.envValue) + // t.Setenv automatically restores the original value after the test + t.Setenv("GO_ENV", tt.envValue) result := isProductionMode() @@ -428,12 +423,8 @@ func TestSetPreferenceCookieSecureFlag(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - // Save original environment - originalEnv := os.Getenv("GO_ENV") - defer os.Setenv("GO_ENV", originalEnv) - - // Set test environment - os.Setenv("GO_ENV", tt.envValue) + // t.Setenv automatically restores the original value after the test + t.Setenv("GO_ENV", tt.envValue) w := httptest.NewRecorder() SetPreferenceCookie(w, "test-cookie", "test-value")