From 3b88aae53ac293cc0973f0a2680eb8b2deb92dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 28 Jun 2021 16:50:01 +0200 Subject: [PATCH] Getting it running on Netlify --- README.md | 12 ++++++++++++ .../hugothemesitebuilder/build/site/build.sh | 6 ++---- cmd/hugothemesitebuilder/build/site/go.mod | 2 +- cmd/hugothemesitebuilder/build/site/go.sum | 2 ++ netlify.toml | 12 ++++-------- pkg/client/client.go | 9 ++++++++- 6 files changed, 29 insertions(+), 14 deletions(-) rename build.sh => cmd/hugothemesitebuilder/build/site/build.sh (89%) diff --git a/README.md b/README.md index e4f6fe5..35bf319 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ # hugoThemeSiteBuilder + +[![Netlify Status](https://api.netlify.com/api/v1/badges/faa207e4-92c4-4fd4-8f5d-b8305205fb84/deploy-status)](https://app.netlify.com/sites/inspiring-noether-f6fa3f/deploys) + Work in progress. + + +* Preview https://inspiring-noether-f6fa3f.netlify.app/ +* Add new themes in cmd/hugothemesitebuilder/build/themes.txt +* The new script fetches star info etc. from GitHub and uses that as part of the weight (combined with date) +* The script currently does not build any demo site, but we may consider a build as part of the "theme evaluation" (as in: block themes with lots of errors, or maybe pull them down with weight). +* Similar I have added some notes about checking if `hugo_version` is set and valid. + + diff --git a/build.sh b/cmd/hugothemesitebuilder/build/site/build.sh similarity index 89% rename from build.sh rename to cmd/hugothemesitebuilder/build/site/build.sh index 87ee520..ee16711 100755 --- a/build.sh +++ b/cmd/hugothemesitebuilder/build/site/build.sh @@ -19,14 +19,12 @@ popd() { command popd "$@" >/dev/null } -pushd cmd/hugothemesitebuilder +pushd "../.." try go run main.go build -pushd build/site +popd if [ -z "$CONTEXT" ] || [ "$CONTEXT" == "production" ] then try hugo --gc --minify else try hugo --gc --minify -b $DEPLOY_PRIME_URL fi -popd -popd \ No newline at end of file diff --git a/cmd/hugothemesitebuilder/build/site/go.mod b/cmd/hugothemesitebuilder/build/site/go.mod index bfa11c9..5fc9ecd 100644 --- a/cmd/hugothemesitebuilder/build/site/go.mod +++ b/cmd/hugothemesitebuilder/build/site/go.mod @@ -2,4 +2,4 @@ module github.com/gohugoio/hugoThemeSiteBuilder/cmd/hugothemesitebuilder/build/s go 1.16 -require github.com/gohugoio/hugoThemesSite v0.0.0-20210628104547-7a5b595fb9f9 +require github.com/gohugoio/hugoThemesSite v0.0.0-20210628144450-4b0d4917433c diff --git a/cmd/hugothemesitebuilder/build/site/go.sum b/cmd/hugothemesitebuilder/build/site/go.sum index 63e7501..a8f7011 100644 --- a/cmd/hugothemesitebuilder/build/site/go.sum +++ b/cmd/hugothemesitebuilder/build/site/go.sum @@ -2,3 +2,5 @@ github.com/gohugoio/gohugoioTheme v0.0.0-20210301124928-2c15837dfec3/go.mod h1:k github.com/gohugoio/hugoThemesSite v0.0.0-20210519162828-756792be83fa h1:s8I3nhH+5bXJEnTGCwYxVT2JfhgxME8SAb7iSIzlN5I= github.com/gohugoio/hugoThemesSite v0.0.0-20210519162828-756792be83fa/go.mod h1:Gx6nWFkR+m0eRiTbtiFb1luhSp6IJ22akCXOvYdcbN4= github.com/gohugoio/hugoThemesSite v0.0.0-20210628104547-7a5b595fb9f9/go.mod h1:Gx6nWFkR+m0eRiTbtiFb1luhSp6IJ22akCXOvYdcbN4= +github.com/gohugoio/hugoThemesSite v0.0.0-20210628144450-4b0d4917433c h1:IA0osqEnyMe7mMHmnzIuDioqXnQ+YTAVm+qf8F0ScFg= +github.com/gohugoio/hugoThemesSite v0.0.0-20210628144450-4b0d4917433c/go.mod h1:Gx6nWFkR+m0eRiTbtiFb1luhSp6IJ22akCXOvYdcbN4= diff --git a/netlify.toml b/netlify.toml index f9eebb9..fe74c23 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,19 +1,15 @@ [build] -publish = "cmd/hugothemesitebuilder/build/site/public" -command = "build.sh" +base = "cmd/hugothemesitebuilder/build/site" +publish = "public" +command = "./build.sh" +ignore = "/bin/false" [context.production.environment] HUGO_VERSION = "0.84.2" -[context.deploy-preview] -command = "build.sh" - [context.deploy-preview.environment] HUGO_VERSION = "0.84.2" -[context.branch-deploy] -command = "build.sh" - [context.branch-deploy.environment] HUGO_VERSION = "0.84.2" diff --git a/pkg/client/client.go b/pkg/client/client.go index a66ed12..0e4ddb3 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -37,6 +37,8 @@ type Client struct { } func (c *Client) GetHugoModulesMap(config string) (ModulesMap, error) { + c.Logf("Get Hugo Modules, config %q", config) + defer c.TimeTrack(time.Now(), "Got Hugo Modules") b := &bytes.Buffer{} if err := c.runHugo(b, "--config", config, "config", "mounts", "-v"); err != nil { return nil, err @@ -48,7 +50,8 @@ func (c *Client) GetHugoModulesMap(config string) (ModulesMap, error) { for dec.More() { var m Module if derr := dec.Decode(&m); derr != nil { - return nil, derr + b, _ := io.ReadAll(dec.Buffered()) + return nil, fmt.Errorf("failed to decode config: %s (buf: %q)", derr, b) } if m.Owner == modPath { @@ -141,6 +144,8 @@ const cacheFileSuffix = "githubrepos.json" // // If you start with an empty cache, you will need to set a GITHUB_TOKEN environment variable. func (c *Client) GetGitHubRepos(mods ModulesMap) (map[string]GitHubRepo, error) { + c.Logf("Get GitHub repos") + defer c.TimeTrack(time.Now(), "Got GitHub repos") cacheFiles := c.getGithubReposCacheFilesSorted() m := make(map[string]GitHubRepo) for _, cacheFile := range cacheFiles { @@ -264,6 +269,8 @@ func (c *Client) runHugo(w io.Writer, arg ...string) error { env := os.Environ() setEnvVars(&env, "PWD", c.outDir) // Use the output dir as the Hugo root. + arg = append(arg, "--quiet") + cmd := exec.Command("hugo", arg...) cmd.Env = env cmd.Stdout = w