diff --git a/cmd/drone-build/run.go b/cmd/drone-build/run.go index dfd2cdb1..6c943040 100644 --- a/cmd/drone-build/run.go +++ b/cmd/drone-build/run.go @@ -32,6 +32,7 @@ func setup(c *Context) error { Network: false, Privileged: false, Volumes: false, + Caching: false, Whitelist: c.Plugins, } @@ -41,6 +42,14 @@ func setup(c *Context) error { opts.Network = true opts.Privileged = true opts.Volumes = true + opts.Caching = true + } + // if repository is public, and a pull request, disable + // the cache. + if c.Repo.Private == false && + c.Build.PullRequest != nil && + c.Build.PullRequest.Number != 0 { + opts.Caching = false } // inject the matrix parameters into the yaml diff --git a/pkg/yaml/parse.go b/pkg/yaml/parse.go index 6b6b7658..c3735406 100644 --- a/pkg/yaml/parse.go +++ b/pkg/yaml/parse.go @@ -15,6 +15,7 @@ type Opts struct { Volumes bool Network bool Privileged bool + Caching bool Whitelist []string } @@ -22,6 +23,7 @@ var DefaultOpts = &Opts{ Volumes: false, Network: false, Privileged: false, + Caching: true, Whitelist: []string{"plugins/*"}, } @@ -86,6 +88,9 @@ func ParseSingle(raw string, opts *Opts, r *common.Repo) (*common.Config, error) transform.RemovePrivileged(conf) } transform.Repo(conf, r) + if !opts.Caching { + transform.RemoveVolumes(conf) + } // lint the yaml file err = Lint(conf)