-
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 fff0787
Showing
2 changed files
with
50 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,49 @@ | ||
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: Execute JavaScript inline | ||
uses: satackey/[email protected] | ||
with: | ||
required-packages: node-fetch | ||
script: | | ||
const endpoint = "https://api.cloudflare.com/client/v4/accounts/${{ secrets.CLOUDFLARE_ACCOUNT_ID }}/pages/projects/${{ matrix.project }}/deployments"; | ||
const expirationDays = 15; | ||
import fetch from 'node-fetch'; | ||
const init = { | ||
headers: { | ||
"Content-Type": "application/json;charset=UTF-8", | ||
// We recommend you store the API token as a secret using the Workers dashboard or using Wrangler as documented here: https://developers.cloudflare.com/workers/wrangler/commands/#secret | ||
"Authorization": "Bearer ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}", | ||
}, | ||
}; | ||
const response = await fetch(endpoint, init); | ||
const deployments = await response.json(); | ||
|
||
for (const deployment of deployments.result) { | ||
// Check if the deployment was created within the last x days (as defined by `expirationDays` above) | ||
if ((Date.now() - new Date(deployment.created_on)) / 86400000 > expirationDays) { | ||
// Delete the deployment | ||
await fetch(`${endpoint}/${deployment.id}`, { | ||
method: "DELETE", | ||
headers: { | ||
"Content-Type": "application/json;charset=UTF-8", | ||
"Authorization": "Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}", | ||
}, | ||
}); | ||
} | ||
} | ||
|
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