Skip to content

Commit

Permalink
Script to delete old docs (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
coyotte508 authored Mar 3, 2023
1 parent 3de0a0e commit 64775a6
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/delete_old_pr_documentations.yml
Original file line number Diff line number Diff line change
@@ -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 }}
5 changes: 5 additions & 0 deletions scripts/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"tabWidth": 2,
"useTabs": true,
"printWidth": 120
}
43 changes: 43 additions & 0 deletions scripts/delete-old-prs.ts
Original file line number Diff line number Diff line change
@@ -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.3";

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?.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,
})),
});
}

0 comments on commit 64775a6

Please sign in to comment.