Skip to content

Commit 361decb

Browse files
committed
feat: PRSDM-10368 incl themes in binary PR feedback
1 parent b70604c commit 361decb

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ jobs:
1414
uses: actions/checkout@v4
1515
with:
1616
fetch-depth: 0
17+
submodules: true
1718
- name: Set up Go
1819
uses: actions/setup-go@v5
1920
with:
2021
go-version: 1.25.x
22+
- name: Prepare themes for embedding
23+
run: make prepare-themes
2124
- name: Run GoReleaser
2225
uses: goreleaser/goreleaser-action@v6
2326
with:

pkg/domain/service/hugo/hugo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66

77
"github.com/SPANDigital/presidium-hugo/pkg/domain/service/themes"
8+
"github.com/SPANDigital/presidium-hugo/pkg/filesystem"
89
"github.com/SPANDigital/presidium-hugo/pkg/log"
910
"github.com/gohugoio/hugo/commands"
1011
)
@@ -36,7 +37,7 @@ func (s Service) Execute(args ...string) error {
3637

3738
// Ensure cleanup happens regardless of how Hugo execution ends
3839
defer func() {
39-
os.RemoveAll(tmpDir)
40+
_ = filesystem.AFS.RemoveAll(tmpDir)
4041
if hadPrevReplacements {
4142
os.Setenv("HUGO_MODULE_REPLACEMENTS", prevReplacements)
4243
} else {

pkg/domain/service/themes/themes.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ func findModuleRoot() (string, error) {
7575
}
7676

7777
// Extract extracts all embedded themes to a temporary directory and returns:
78-
// - tmpDir: the temporary directory path (caller must clean up with os.RemoveAll)
78+
// - tmpDir: the temporary directory path (caller must clean up)
7979
// - replacements: comma-separated string for HUGO_MODULE_REPLACEMENTS env var
8080
// - err: any error encountered during extraction
8181
func (s Service) Extract() (tmpDir string, replacements string, err error) {
8282
// Create a temporary directory for themes
83-
tmpDir, err = os.MkdirTemp("", "presidium-themes-*")
83+
tmpDir, err = filesystem.AFS.TempDir("", "presidium-themes-*")
8484
if err != nil {
8585
return "", "", fmt.Errorf("creating temp directory: %w", err)
8686
}
@@ -97,8 +97,8 @@ func (s Service) Extract() (tmpDir string, replacements string, err error) {
9797
themeName := moduleMap[modulePath]
9898
// Create the theme directory in temp
9999
themeDir := filepath.Join(tmpDir, themeName)
100-
if err := os.MkdirAll(themeDir, 0755); err != nil {
101-
os.RemoveAll(tmpDir)
100+
if err := filesystem.AFS.MkdirAll(themeDir, 0755); err != nil {
101+
_ = filesystem.AFS.RemoveAll(tmpDir)
102102
return "", "", fmt.Errorf("creating theme directory %s: %w", themeName, err)
103103
}
104104

@@ -146,7 +146,7 @@ func (s Service) Extract() (tmpDir string, replacements string, err error) {
146146
})
147147

148148
if err != nil {
149-
os.RemoveAll(tmpDir)
149+
_ = filesystem.AFS.RemoveAll(tmpDir)
150150
return "", "", fmt.Errorf("extracting theme %s: %w", themeName, err)
151151
}
152152

pkg/domain/service/themes/themes_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"strings"
77
"testing"
88
"testing/fstest"
9+
10+
"github.com/SPANDigital/presidium-hugo/pkg/filesystem"
911
)
1012

1113
func TestNew_WithEmbeddedFS(t *testing.T) {
@@ -70,23 +72,23 @@ func TestExtract_WritesFilesAndProducesReplacements(t *testing.T) {
7072
if err != nil {
7173
t.Fatalf("Extract() returned unexpected error: %v", err)
7274
}
73-
defer os.RemoveAll(tmpDir)
75+
defer func() { _ = filesystem.AFS.RemoveAll(tmpDir) }()
7476

7577
// Verify go.mod.tmpl was renamed to go.mod on disk
7678
goModPath := filepath.Join(tmpDir, "presidium-styling-base", "go.mod")
77-
if _, err := os.Stat(goModPath); os.IsNotExist(err) {
79+
if exists, _ := filesystem.AFS.Exists(goModPath); !exists {
7880
t.Error("Expected go.mod.tmpl to be extracted as go.mod, but file does not exist")
7981
}
8082

8183
// Verify go.sum.tmpl was renamed to go.sum on disk
8284
goSumPath := filepath.Join(tmpDir, "presidium-styling-base", "go.sum")
83-
if _, err := os.Stat(goSumPath); os.IsNotExist(err) {
85+
if exists, _ := filesystem.AFS.Exists(goSumPath); !exists {
8486
t.Error("Expected go.sum.tmpl to be extracted as go.sum, but file does not exist")
8587
}
8688

8789
// Verify config.yml was extracted
8890
configPath := filepath.Join(tmpDir, "presidium-styling-base", "config.yml")
89-
if _, err := os.Stat(configPath); os.IsNotExist(err) {
91+
if exists, _ := filesystem.AFS.Exists(configPath); !exists {
9092
t.Error("Expected config.yml to be extracted, but file does not exist")
9193
}
9294

@@ -127,7 +129,7 @@ func TestExtract_EmptyTheme(t *testing.T) {
127129
if err != nil {
128130
t.Fatalf("Extract() returned unexpected error: %v", err)
129131
}
130-
defer os.RemoveAll(tmpDir)
132+
defer func() { _ = filesystem.AFS.RemoveAll(tmpDir) }()
131133

132134
if replacements == "" {
133135
t.Error("Expected non-empty replacements string")

0 commit comments

Comments
 (0)