Skip to content

Commit

Permalink
feat(hugo): add IsTheme property in returned struct to introduce cust…
Browse files Browse the repository at this point in the history
…om behaviors depending on hugo themes and hugo sites

Signed-off-by: kilianpaquier <[email protected]>
  • Loading branch information
kilianpaquier committed Mar 9, 2025
1 parent 0da0c69 commit 7dff8a8
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jobs:
<<- define "hugo" >>
<<- $specifics := get .Languages "hugo" >>

hugo-build:
name: Hugo Build
Expand All @@ -21,7 +22,11 @@ jobs:
with:
hugo-version: latest
extended: true
- run: hugo --gc --minify --destination dist
- run: |
<<- if $specifics.IsTheme >>
if [ -d exampleSite ]; then cd exampleSite; fi
<<- end >>
hugo --gc --enableGitInfo --minify --destination "${GITHUB_WORKSPACE}/dist"
env:
VERSION: ${{ needs.version.outputs.version }}
<<- if .IsStatic "pages" >>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ jobs:
- id: branch_sha
run: |
echo "branch_sha=$(echo "${GITHUB_REF_NAME}" | sha256sum | cut -c -8)" >> $GITHUB_OUTPUT
- id: config
run: |
if [ -f netlify.toml ]; then echo "path=netlify.toml" >> $GITHUB_OUTPUT; fi
- id: netlify
uses: nwtgck/actions-netlify@v3
with:
Expand All @@ -295,7 +298,7 @@ jobs:
enable-commit-status: false
github-deployment-environment: netlify
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-config-path: netlify.toml
netlify-config-path: ${{ steps.config.outputs.path }}
production-branch: ${{ github.event.repository.default_branch }}
publish-dir: dist
env:
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/parser/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Git(destdir string) (VCS, error) {
// - git.ErrRepositoryNotExists
// - git.ErrRemoteNotFound
func gitOriginURL(destdir string) (string, error) {
repository, err := git.PlainOpen(destdir)
repository, err := git.PlainOpenWithOptions(destdir, &git.PlainOpenOptions{DetectDotGit: true})
if err != nil {
return "", fmt.Errorf("open repository: %w", err)
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/engine/parser/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ func ReadGoCmd(destdir string) (Executables, error) {
}

// HugoConfig represents the parse'd hugo.* or theme.* file associated to hugo configuration file.
type HugoConfig struct{}
type HugoConfig struct {
// IsTheme expresses whether a theme.* configuration is present,
// meaning current hugo repository is a theme one.
IsTheme bool
}

// Hugo detects if the project is a Hugo project.
//
Expand All @@ -232,5 +236,8 @@ func Hugo(destdir string) (HugoConfig, bool) {
// detect hugo theme
themes, _ := filepath.Glob(filepath.Join(destdir, "theme.*"))

return HugoConfig{}, len(configs) > 0 || len(themes) > 0
if len(configs) == 0 && len(themes) == 0 {
return HugoConfig{}, false
}
return HugoConfig{IsTheme: len(themes) > 0}, true
}
20 changes: 19 additions & 1 deletion pkg/engine/parser/golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,25 @@ func TestHugo(t *testing.T) {
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, hugo.Close()) })

expected := parser.HugoConfig{}
expected := parser.HugoConfig{IsTheme: false}

// Act
config, ok := parser.Hugo(destdir)

// Assert
assert.True(t, ok)
assert.Equal(t, expected, config)
})

t.Run("detected_hugo_theme", func(t *testing.T) {
// Arrange
destdir := t.TempDir()

hugo, err := os.Create(filepath.Join(destdir, "theme.toml"))
require.NoError(t, err)
t.Cleanup(func() { assert.NoError(t, hugo.Close()) })

expected := parser.HugoConfig{IsTheme: true}

// Act
config, ok := parser.Hugo(destdir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ jobs:
with:
hugo-version: latest
extended: true
- run: hugo --gc --minify --destination dist
- run: |
hugo --gc --enableGitInfo --minify --destination "${GITHUB_WORKSPACE}/dist"
env:
VERSION: ${{ needs.version.outputs.version }}
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -128,6 +129,9 @@ jobs:
- id: branch_sha
run: |
echo "branch_sha=$(echo "${GITHUB_REF_NAME}" | sha256sum | cut -c -8)" >> $GITHUB_OUTPUT
- id: config
run: |
if [ -f netlify.toml ]; then echo "path=netlify.toml" >> $GITHUB_OUTPUT; fi
- id: netlify
uses: nwtgck/actions-netlify@v3
with:
Expand All @@ -137,7 +141,7 @@ jobs:
enable-commit-status: false
github-deployment-environment: netlify
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-config-path: netlify.toml
netlify-config-path: ${{ steps.config.outputs.path }}
production-branch: ${{ github.event.repository.default_branch }}
publish-dir: dist
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ jobs:
with:
hugo-version: latest
extended: true
- run: hugo --gc --minify --destination dist
- run: |
hugo --gc --enableGitInfo --minify --destination "${GITHUB_WORKSPACE}/dist"
env:
VERSION: ${{ needs.version.outputs.version }}
- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -128,6 +129,9 @@ jobs:
- id: branch_sha
run: |
echo "branch_sha=$(echo "${GITHUB_REF_NAME}" | sha256sum | cut -c -8)" >> $GITHUB_OUTPUT
- id: config
run: |
if [ -f netlify.toml ]; then echo "path=netlify.toml" >> $GITHUB_OUTPUT; fi
- id: netlify
uses: nwtgck/actions-netlify@v3
with:
Expand All @@ -137,7 +141,7 @@ jobs:
enable-commit-status: false
github-deployment-environment: netlify
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-config-path: netlify.toml
netlify-config-path: ${{ steps.config.outputs.path }}
production-branch: ${{ github.event.repository.default_branch }}
publish-dir: dist
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ jobs:
with:
hugo-version: latest
extended: true
- run: hugo --gc --minify --destination dist
- run: |
hugo --gc --enableGitInfo --minify --destination "${GITHUB_WORKSPACE}/dist"
env:
VERSION: ${{ needs.version.outputs.version }}
- uses: actions/upload-pages-artifact@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ jobs:
with:
hugo-version: latest
extended: true
- run: hugo --gc --minify --destination dist
- run: |
hugo --gc --enableGitInfo --minify --destination "${GITHUB_WORKSPACE}/dist"
env:
VERSION: ${{ needs.version.outputs.version }}
- uses: actions/upload-pages-artifact@v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ jobs:
- id: branch_sha
run: |
echo "branch_sha=$(echo "${GITHUB_REF_NAME}" | sha256sum | cut -c -8)" >> $GITHUB_OUTPUT
- id: config
run: |
if [ -f netlify.toml ]; then echo "path=netlify.toml" >> $GITHUB_OUTPUT; fi
- id: netlify
uses: nwtgck/actions-netlify@v3
with:
Expand All @@ -163,7 +166,7 @@ jobs:
enable-commit-status: false
github-deployment-environment: netlify
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-config-path: netlify.toml
netlify-config-path: ${{ steps.config.outputs.path }}
production-branch: ${{ github.event.repository.default_branch }}
publish-dir: dist
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ jobs:
- id: branch_sha
run: |
echo "branch_sha=$(echo "${GITHUB_REF_NAME}" | sha256sum | cut -c -8)" >> $GITHUB_OUTPUT
- id: config
run: |
if [ -f netlify.toml ]; then echo "path=netlify.toml" >> $GITHUB_OUTPUT; fi
- id: netlify
uses: nwtgck/actions-netlify@v3
with:
Expand All @@ -163,7 +166,7 @@ jobs:
enable-commit-status: false
github-deployment-environment: netlify
github-token: ${{ secrets.GITHUB_TOKEN }}
netlify-config-path: netlify.toml
netlify-config-path: ${{ steps.config.outputs.path }}
production-branch: ${{ github.event.repository.default_branch }}
publish-dir: dist
env:
Expand Down

0 comments on commit 7dff8a8

Please sign in to comment.