Fix Cloudflare vs Netlify cache dir issue
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 30 Jun 2021 10:55:29 +0000 (12:55 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 30 Jun 2021 10:58:43 +0000 (12:58 +0200)
Re-add the additional environment checks to determine if its Netlify. Seems that Cloudflare also sets `NETLIFY=true`.

This makes it look, basically, like a variant of the conditional we had before we started fixing this, but I have checked this logic on Netlify now and it should work.

Fixes #8714

helpers/path.go

index 6d4827bd2bb6bcb5449ec4a39d999d7e5dc4e616..b504f5251dc1b31b8cd3a1c84035b86f6a72bf29 100644 (file)
@@ -412,8 +412,10 @@ func getCacheDir(cfg config.Provider) string {
                return addTrailingFileSeparator(cacheDir)
        }
 
-       // This is always set to true when running on Netlify.
-       if os.Getenv("NETLIFY") == "true" {
+       // See Issue #8714.
+       // Turns out that Cloudflare also sets NETLIFY=true in its build environment,
+       // but all of these 3 should not give any false positives.
+       if os.Getenv("NETLIFY") == "true" && os.Getenv("PULL_REQUEST") != "" && os.Getenv("DEPLOY_PRIME_URL") != "" {
                // Netlify's cache behaviour is not documented, the currently best example
                // is this project:
                // https://github.com/philhawksworth/content-shards/blob/master/gulpfile.js