From 9aee76b2138f8381cf48b5fc98488ecc5902db8d Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 29 Oct 2018 03:45:36 -0400 Subject: [PATCH] add cacheDir flag (#11) golang version of #7 ----- This enables setting a custom cache directory for Hugo. Some caching plugins (e.g. http://plugins.drone.io/drillster/drone-volume-cache/) require the directories to be cached to be located inside the workspace. --- README.md | 1 + cmd/drone-hugo/main.go | 6 ++++++ plugin.go | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/README.md b/README.md index 87bbdb5..f4e7a1f 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ docker run --rm \ -e PLUGIN_BUILDDRAFTS=false \ -e PLUGIN_BUILDEXPIRED=false \ -e PLUGIN_BUILDFUTURE=false \ + -e PLUGIN_CACHEDIR=false \ -e PLUGIN_CONFIG=false \ -e PLUGIN_CONTENT=false \ -e PLUGIN_LAYOUT=false \ diff --git a/cmd/drone-hugo/main.go b/cmd/drone-hugo/main.go index dedc498..78e0134 100644 --- a/cmd/drone-hugo/main.go +++ b/cmd/drone-hugo/main.go @@ -36,6 +36,12 @@ func main() { Usage: "include content with publishdate in the future", EnvVar: "PLUGIN_BUILDFUTURE", }, + cli.StringFlag{ + Name: "cacheDir", + Usage: "change cache directory (useful when using caching plugins)", + EnvVar: "PLUGIN_CACHEDIR", + Value: "", + }, cli.StringFlag{ Name: "config", Usage: "config file (default is path/config.yaml|json|toml)", diff --git a/plugin.go b/plugin.go index 6803240..51c25e7 100644 --- a/plugin.go +++ b/plugin.go @@ -18,6 +18,7 @@ type ( BuildDrafts bool BuildExpired bool BuildFuture bool + CacheDir string Config string Content string Layout string @@ -75,6 +76,9 @@ func commandBuild(config Config) *exec.Cmd { args = append(args, "-F") } // add string args + if config.CacheDir != "" { + args = append(args, "--cacheDir", config.CacheDir) + } if config.Config != "" { args = append(args, "--config", config.Config) }