Skip to content

Commit 13a732d

Browse files
committed
feat: PRSDM-10268 embed themes in binary
1 parent 577d63e commit 13a732d

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

Dockerfile.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
FROM golang:1.25-alpine AS builder
66

77
# Install build dependencies
8-
RUN apk add --no-cache git gcc g++ musl-dev
8+
RUN apk add --no-cache git gcc g++ musl-dev make
99

1010
# Copy source code
1111
WORKDIR /build
1212
COPY . .
1313

14-
# Build presidium binary
15-
RUN go build -tags extended -o presidium .
14+
# Build presidium binary (prepare-themes renames go.mod files so they can be embedded)
15+
RUN make prepare-themes && go build -tags extended -o presidium .
1616

1717
# Stage 2: Test without network access
1818
FROM golang:1.25-alpine AS test

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ DOCSDIR=docs
66
help: ## Display available targets
77
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " %-18s %s\n", $$1, $$2}'
88

9+
update-themes: ## Update theme submodules to their latest versions
10+
@echo "Updating theme submodules to latest..."
11+
@git submodule update --remote themes/presidium-styling-base themes/presidium-layouts-base themes/presidium-layouts-blog
12+
@echo "Theme submodules updated."
13+
914
prepare-themes: ## Prepare themes for embedding (rename go.mod to make embeddable)
1015
@echo "Preparing themes for embedding..."
1116
@for theme in themes/presidium-*; do \
@@ -33,17 +38,17 @@ restore-themes: ## Restore theme go.mod files to original names
3338
done
3439

3540
build: prepare-themes ## Build the presidium binary
36-
go build -tags extended -o $(FILENAME) .
41+
go build -tags extended -o $(FILENAME) . ; status=$$? ; $(MAKE) restore-themes ; exit $$status
3742

3843
test: prepare-themes ## Run tests with coverage
3944
@mkdir -p reports
40-
go test -race -timeout 120s ./... -coverprofile=reports/tests-cov.out
45+
go test -race -timeout 120s ./... -coverprofile=reports/tests-cov.out ; status=$$? ; $(MAKE) restore-themes ; exit $$status
4146

4247
fmt: ## Format Go source files
4348
go fmt ./...
4449

4550
vet: prepare-themes ## Run go vet
46-
go vet ./...
51+
go vet ./... ; status=$$? ; $(MAKE) restore-themes ; exit $$status
4752

4853
tidy: ## Tidy and verify module dependencies
4954
go mod tidy && go mod verify
@@ -55,13 +60,12 @@ coverage_report: ## Open coverage report in browser
5560
@go tool cover -html=reports/tests-cov.out
5661

5762
dist: prepare-themes ## Build distribution binary
58-
mkdir -p "dist"
59-
go build -trimpath -o "dist/presidium" --tags extended
63+
mkdir -p "dist" && go build -trimpath -o "dist/presidium" --tags extended ; status=$$? ; $(MAKE) restore-themes ; exit $$status
6064

6165
checks: clean tidy fmt vet lint test build
6266

6367
serve-docs:
6468
cd $(DOCSDIR) && make serve
6569

6670
lint: prepare-themes ## Run golangci-lint
67-
golangci-lint run --timeout 10m
71+
golangci-lint run --timeout 10m ; status=$$? ; $(MAKE) restore-themes ; exit $$status

pkg/domain/service/hugo/hugo_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,18 @@ func TestExecute_CleansUpEnvironment(t *testing.T) {
5757
// Execute a command that will quickly fail (invalid command)
5858
_ = svc.Execute("nonexistent-command-xyz")
5959

60-
// Check that the environment variable was cleaned up
61-
if value, exists := os.LookupEnv(envVarName); exists {
62-
t.Errorf("HUGO_MODULE_REPLACEMENTS was not cleaned up, value: %s", value)
60+
// Check that the environment variable was cleaned up or restored appropriately
61+
value, exists := os.LookupEnv(envVarName)
62+
if hadOriginal {
63+
if !exists {
64+
t.Errorf("HUGO_MODULE_REPLACEMENTS was not restored; expected it to exist with original value %q", originalValue)
65+
} else if value != originalValue {
66+
t.Errorf("HUGO_MODULE_REPLACEMENTS value was not restored; got %q, want %q", value, originalValue)
67+
}
68+
} else {
69+
if exists {
70+
t.Errorf("HUGO_MODULE_REPLACEMENTS was not cleaned up; expected it to be unset, got value: %q", value)
71+
}
6372
}
6473
}
6574

pkg/domain/service/themes/themes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ func findModuleRoot() (string, error) {
6060
if err != nil {
6161
return "", fmt.Errorf("unable to determine working directory: %w", err)
6262
}
63+
startDir := dir
6364
for {
6465
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
6566
return dir, nil
6667
}
6768
parent := filepath.Dir(dir)
6869
if parent == dir {
69-
return ".", nil
70+
return "", fmt.Errorf("no go.mod found when searching upwards from %s", startDir)
7071
}
7172
dir = parent
7273
}

0 commit comments

Comments
 (0)