fix: Resolve CSS bundling in production and lint errors

- Fix golangci-lint errcheck errors by using t.Setenv() instead of os.Setenv()
- Add CSS bundle build step to deploy workflow for production
- Add graceful fallback to modular CSS if bundle doesn't exist
- Remove unused os import from preferences_test.go
This commit is contained in:
juanatsap
2025-11-30 12:38:31 +00:00
parent 95de841e14
commit 00e28906e6
3 changed files with 25 additions and 14 deletions
+12
View File
@@ -46,6 +46,18 @@ jobs:
git pull origin main 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) # Reapply stashed changes if any (optional - comment out if not needed)
# if git stash list | grep -q "Auto-stash"; then # if git stash list | grep -q "Auto-stash"; then
# echo "♻️ Reapplying stashed changes..." # echo "♻️ Reapplying stashed changes..."
+9 -1
View File
@@ -330,8 +330,16 @@ func (h *CVHandler) prepareTemplateData(lang string) (map[string]interface{}, er
// Get current year // Get current year
currentYear := time.Now().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" 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 // Prepare template data
data := map[string]interface{}{ data := map[string]interface{}{
+4 -13
View File
@@ -3,7 +3,6 @@ package middleware
import ( import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"testing" "testing"
) )
@@ -385,12 +384,8 @@ func TestIsProductionMode(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
// Save original environment // t.Setenv automatically restores the original value after the test
originalEnv := os.Getenv("GO_ENV") t.Setenv("GO_ENV", tt.envValue)
defer os.Setenv("GO_ENV", originalEnv)
// Set test environment
os.Setenv("GO_ENV", tt.envValue)
result := isProductionMode() result := isProductionMode()
@@ -428,12 +423,8 @@ func TestSetPreferenceCookieSecureFlag(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
// Save original environment // t.Setenv automatically restores the original value after the test
originalEnv := os.Getenv("GO_ENV") t.Setenv("GO_ENV", tt.envValue)
defer os.Setenv("GO_ENV", originalEnv)
// Set test environment
os.Setenv("GO_ENV", tt.envValue)
w := httptest.NewRecorder() w := httptest.NewRecorder()
SetPreferenceCookie(w, "test-cookie", "test-value") SetPreferenceCookie(w, "test-cookie", "test-value")