From 172b49148a7e440b99c9f0fec0f6e17159794f5d Mon Sep 17 00:00:00 2001
From: Chris Coley <chris@codingallnight.com>
Date: Sun, 30 Apr 2023 04:42:42 -0700
Subject: [PATCH] Purge all site URLs from Cloudflare cache

---
 .gitlab-ci.yml | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 5a206ce..537482f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -70,4 +70,26 @@ pages:
   rules:
     - if: $CI_COMMIT_BRANCH == 'custom-domain'
 
+# Purge all of this site's URLs from the Cloudflare cache
+purge-cache:
+  stage: .post
+  tags:
+    - docker
+  rules:
+    - if: $CF_PURGE_CACHE_ZONE && $CF_PURGE_CACHE_TOKEN
+  script:
+    - >-
+      FILES="{ \"files\": [\"$CI_PAGES_URL/\"";
+      for d in $(find public/* -type d); do FILES="$FILES,\"$CI_PAGES_URL/${d#public/}/\""; done;
+      for f in $(find public -type f); do FILES="$FILES,\"$CI_PAGES_URL/${f#public/}\""; done;
+      FILES="$FILES] }"
+    - echo $FILES
+    - >-
+      wget -qO- "https://api.cloudflare.com/client/v4/zones/$CF_PURGE_CACHE_ZONE/purge_cache"
+      --header "Content-Type: application/json"
+      --header "Authorization: Bearer $CF_PURGE_CACHE_TOKEN"
+      --post-data "$FILES"
+
+
+
 # vi: set ts=2 sw=2 et ft=yaml:
-- 
GitLab