Skip to content

Commit

Permalink
Add CI clean cloudflare cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hientominh committed Jan 17, 2024
1 parent f5dca81 commit 95bcd9d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/clean-cloudflare-page-preview-url.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: "Clean old cloudflare pages preview urls and nightly build"
on:
schedule:
- cron: "0 0 * * *" # every day at 00:00
workflow_dispatch:
push:
branches:
- feature/clean-cloudflare-page-and-r2
jobs:
clean-cloudflare-pages-preview-urls:
strategy:
matrix:
project: ["jan", "nitro"]
runs-on: ubuntu-latest
steps:
- name: install requests
run: |
python3 -m pip install requests
- name: Python Inline script
shell: python3
run: |
import requests
from datetime import datetime, timedelta
# Configuration
endpoint = f"https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${{ matrix.project }}/deployments"
expiration_days = 15
headers = {
"Content-Type": "application/json;charset=UTF-8",
"Authorization": f"Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}"
}
# Fetch the list of deployments
response = requests.get(endpoint, headers=headers)
deployments = response.json()
for deployment in deployments['result']:
# Calculate the age of the deployment
created_on = datetime.fromisoformat(deployment['created_on'].rstrip('Z'))
if (datetime.now() - created_on).days > expiration_days:
# Delete the deployment
delete_response = requests.delete(f"{endpoint}/{deployment['id']}", headers=headers)
if delete_response.status_code == 200:
print(f"Deleted deployment: {deployment['id']}")
else:
print(f"Failed to delete deployment: {deployment['id']}")
3 changes: 1 addition & 2 deletions .github/workflows/jan-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
deploy:
name: Deploy to GitHub Pages
env:
CLOUDFLARE_ACCOUNT_ID: 9707100ef42a1a25bd70e3ee2137bd0e
CLOUDFLARE_PROJECT_NAME: jan
runs-on: ubuntu-latest
permissions:
Expand Down Expand Up @@ -66,7 +65,7 @@ jobs:
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ env.CLOUDFLARE_ACCOUNT_ID }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: ${{ env.CLOUDFLARE_PROJECT_NAME }}
directory: ./docs/build
branch: dev
Expand Down

0 comments on commit 95bcd9d

Please sign in to comment.