diff --git a/.github/workflows/clean-cloudflare-page-preview-url.yml b/.github/workflows/clean-cloudflare-page-preview-url.yml new file mode 100644 index 0000000000..7aef5e6cbe --- /dev/null +++ b/.github/workflows/clean-cloudflare-page-preview-url.yml @@ -0,0 +1,55 @@ +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 tqdm + - name: Python Inline script + uses: jannekem/run-python-script-action@v1 + with: + script: | + import requests + from datetime import datetime, UTC + from pytz import timezone + from tqdm import tqdm + + # 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 tqdm(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.now(UTC) - 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']}") + + \ No newline at end of file diff --git a/.github/workflows/jan-docs.yml b/.github/workflows/jan-docs.yml index 12d5992dd0..9c34fafc3b 100644 --- a/.github/workflows/jan-docs.yml +++ b/.github/workflows/jan-docs.yml @@ -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: @@ -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