From cbca9613c69174501f583dc6899015f9bdb4c0fa Mon Sep 17 00:00:00 2001 From: mrrfv Date: Thu, 7 Sep 2023 20:57:08 +0200 Subject: [PATCH] Dry run support --- README.md | 6 ++++++ cf_list_create.js | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 8a69724..479c01e 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,12 @@ Please note that the GitHub Action downloads the recommended blocklists and whit Alternatively, you can install the Cloudflare WARP client and log in to Zero Trust. This method proxies your traffic over Cloudflare servers, meaning it works similarly to a commercial VPN. +### Dry runs + +To see if e.g. your filter lists are valid without actually changing anything in your Cloudflare account, you can set the `DRY_RUN` environment variable to "true", either in `.env` or the regular way. This will only print info such as the lists that would be created or the amount of duplicate domains to the console. + +**Warning:** This currently only works for `cf_list_create.js`. + ## Why not... ### Pi-hole or Adguard Home? diff --git a/cf_list_create.js b/cf_list_create.js index ee6dad4..6eeb9b2 100644 --- a/cf_list_create.js +++ b/cf_list_create.js @@ -109,6 +109,10 @@ fs.readFile('input.csv', 'utf8', async (err, data) => { if (!process.env.CI) console.log(`Found ${domains.length} valid domains in input.csv after cleanup - ${listsToCreate} list(s) will be created`); + // If we are dry-running, stop here because we don't want to create lists + // TODO: we should probably continue, just without making any real requests to Cloudflare + if (process.env.DRY_RUN) return console.log('Dry run complete - no lists were created. If this was not intended, please remove the DRY_RUN environment variable and try again.'); + // Separate domains into chunks of 1000 (Cloudflare list cap) const chunks = chunkArray(domains, 1000);