-
-
Notifications
You must be signed in to change notification settings - Fork 4
73 lines (64 loc) · 2.2 KB
/
stale_preview_removal.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
name: Doc Preview Cleanup
on:
schedule:
- cron: "0 0 * * *"
jobs:
doc-preview-cleanup:
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
- uses: julia-actions/setup-julia@v2
with:
version: '1'
- name: Check for stale PR previews
shell: julia {0}
run: |
using Pkg
pkg"activate --temp"
pkg"add HTTP JSON3"
using HTTP
using JSON3
using Dates
repo = ENV["GITHUB_REPOSITORY"]
retention_days = 14
pr_previews = map(filter(startswith("PR"), readdir("previews"))) do dir
parse(Int, match(r"PR(\d*)", dir)[1])
end
function all_prs()
query_prs(page) = JSON3.read(HTTP.get("https://api.github.com/repos/$repo/pulls?per_page=100;page=$(page)").body)
prs = []
page = 1
while true
page_prs = query_prs(page)
isempty(page_prs) && break
append!(prs, page_prs)
page += 1
end
return prs
end
prs = all_prs()
open_within_threshold = map(x -> x.number, filter(prs) do pr
time = DateTime(pr.updated_at[1:19], ISODateTimeFormat)
return pr.state == "open" && Dates.days(now() - time) <= retention_days
end)
stale_previews = setdiff(pr_previews, open_within_threshold)
@info "Found $(length(stale_previews)) stale previews"
if isempty(stale_previews)
@info "No stale previews"
exit(1)
end
for pr in stale_previews
path = joinpath("previews", "PR$pr")
@info "Removing $path"
run(`git rm -rf $path`)
end
- name: Push changes
run: |
git config user.name "Documenter.jl"
git config user.email "[email protected]"
git commit -m "delete preview"
git branch gh-pages-new $(echo "delete history" | git commit-tree HEAD^{tree})
git push --force origin gh-pages-new:gh-pages