From c22258fd1a1ca7ec1f56e02284bf331df44e3e3d Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 2 Mar 2023 00:51:51 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Script=20to=20delete=20old=20do?= =?UTF-8?q?cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/.prettierrc | 5 +++++ scripts/delete-old-prs.ts | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 scripts/.prettierrc create mode 100755 scripts/delete-old-prs.ts diff --git a/scripts/.prettierrc b/scripts/.prettierrc new file mode 100644 index 000000000..188b73f56 --- /dev/null +++ b/scripts/.prettierrc @@ -0,0 +1,5 @@ +{ + "tabWidth": 2, + "useTabs": true, + "printWidth": 120 +} diff --git a/scripts/delete-old-prs.ts b/scripts/delete-old-prs.ts new file mode 100755 index 000000000..5e90c0bd6 --- /dev/null +++ b/scripts/delete-old-prs.ts @@ -0,0 +1,43 @@ +#!/usr/bin/env -S deno run --allow-env --allow-net --allow-run --allow-read +// To format: npx prettier --write . +import { commit, listFiles } from "npm:@huggingface/hub@0.1.2"; + +const oneMonthAgo = new Date(Date.now() - 30 * 24 * 3600 * 1000); + +const allFiles = listFiles({ + repo: { type: "dataset", name: "hf-doc-build/doc-build-dev" }, + recursive: true, +}); + +const filesToDelete: string[] = []; + +for await (const file of allFiles) { + if (file.type !== "file" || !file.path.endsWith(".zip")) { + continue; + } + + const date = file.lastCommit?.author.date; + + if (!date) { + continue; + } + + if (oneMonthAgo < new Date(date)) { + continue; + } + + filesToDelete.push(file.path); +} + +if (filesToDelete.length) { + console.log("deleting", filesToDelete.length, "files"); + await commit({ + repo: { type: "dataset", name: "hf-doc-build/doc-build-dev" }, + credentials: { accessToken: Deno.env.get("HF_ACCESS_TOKEN") }, + title: "Delete old docs", + operations: filesToDelete.map((file) => ({ + operation: "delete", + path: file, + })), + }); +} From 6f7198d120cd8107135d99de7cd79c5a8f104182 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 2 Mar 2023 01:09:23 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=91=B7=20Add=20cron=20to=20delete=20o?= =?UTF-8?q?ld=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../delete_old_pr_documentations.yml | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/delete_old_pr_documentations.yml diff --git a/.github/workflows/delete_old_pr_documentations.yml b/.github/workflows/delete_old_pr_documentations.yml new file mode 100644 index 000000000..160e74c58 --- /dev/null +++ b/.github/workflows/delete_old_pr_documentations.yml @@ -0,0 +1,20 @@ +name: Delete old PRs docs +on: + schedule: + - cron: "11 11 * * *" + + +defaults: + run: + working-directory: scripts + +jobs: + delete_old_prs: + runs-on: ubuntu-latest + steps: + - uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - run: deno run --allow-env --allow-net --allow-run --allow-read ./delete-old-prs.ts + env: + HF_ACCESS_TOKEN: ${{ secrets.HF_ACCESS_TOKEN }} \ No newline at end of file From 72b5809f2057fcdd2b69981a8ee0601f5262eb17 Mon Sep 17 00:00:00 2001 From: coyotte508 Date: Thu, 2 Mar 2023 17:30:59 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20@huggingface/hub=200.1?= =?UTF-8?q?.3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/delete-old-prs.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/delete-old-prs.ts b/scripts/delete-old-prs.ts index 5e90c0bd6..04c1c15fc 100755 --- a/scripts/delete-old-prs.ts +++ b/scripts/delete-old-prs.ts @@ -1,6 +1,6 @@ #!/usr/bin/env -S deno run --allow-env --allow-net --allow-run --allow-read // To format: npx prettier --write . -import { commit, listFiles } from "npm:@huggingface/hub@0.1.2"; +import { commit, listFiles } from "npm:@huggingface/hub@0.1.3"; const oneMonthAgo = new Date(Date.now() - 30 * 24 * 3600 * 1000); @@ -16,7 +16,7 @@ for await (const file of allFiles) { continue; } - const date = file.lastCommit?.author.date; + const date = file.lastCommit?.date; if (!date) { continue;