-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5dca81
commit e353df7
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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: | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.x' | ||
- name: install requests | ||
run: | | ||
python3 -m pip install requests pytz | ||
- name: Python Inline script | ||
uses: jannekem/run-python-script-action@v1 | ||
with: | ||
script: | | ||
import requests | ||
from datetime import datetime | ||
from pytz import timezone | ||
# Configuration | ||
endpoint = "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${{ matrix.project }}/deployments" | ||
expiration_days = 3 | ||
headers = { | ||
"Content-Type": "application/json;charset=UTF-8", | ||
"Authorization": "Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" | ||
} | ||
utc_tz = timezone('UTC') | ||
# 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.strptime(deployment['created_on'], "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=utc_tz) | ||
if (datetime.utcnow().replace(tzinfo=utc_tz) - 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']}") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters