Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 16 additions & 65 deletions .github/workflows/DocPreviewCleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
schedule:
- cron: "0 0 */14 * *"

concurrency:
group: gh-pages
cancel-in-progress: false
queue: max

jobs:
doc-preview-cleanup:
runs-on: ubuntu-latest
Expand All @@ -14,69 +19,15 @@ jobs:
uses: actions/checkout@v7
with:
ref: gh-pages

- uses: julia-actions/setup-julia@v3
with:
version: '1'
- uses: julia-actions/cache@v3

- name: Check for stale PR previews
shell: julia --color=yes {0}
run: |
using Pkg
Pkg.activate(temp = true)
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()
url = "https://api.github.com/repos/$repo/pulls?per_page=100;page="
query_prs(page) = JSON3.read(HTTP.get(url * string(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"
println(ENV["GITHUB_ENV"], "FOUND_STALE_PREVIEWS=false")
exit()
end
println(ENV["GITHUB_ENV"], "FOUND_STALE_PREVIEWS=true")

for pr in stale_previews
path = joinpath("previews", "PR$pr")
@info "Removing $path"
run(`git rm -rf $path`)
end
- name: Push changes
if: ${{ env.FOUND_STALE_PREVIEWS == 'true' }}
- name: Delete preview and history + push changes
run: |
git config user.name "Documenter.jl"
git config user.email "documenter@juliadocs.github.io"
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
if [ -d "${preview_dir}" ]; then
git config user.name "Documenter.jl"
git config user.email "documenter@juliadocs.github.io"
git rm -rfq "${preview_dir}"
git commit -m "delete preview"
git branch gh-pages-new "$(echo "delete history" | git commit-tree "HEAD^{tree}")"
git push --force-with-lease origin gh-pages-new:gh-pages
fi
env:
preview_dir: previews/PR${{ github.event.number }}
6 changes: 6 additions & 0 deletions .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
pull_request:
schedule:
- cron: '15 2 * * *' # 2:15 AM UTC every day

concurrency:
group: gh-pages
cancel-in-progress: false
queue: max

jobs:
docs:
name: build
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ DemoCards = "0.5.5"
Documenter = "1"
DocumenterInterLinks = "1.1.0"
Glob = "1.5.0"
MultiDocumenter = "0.8.1"
Revise = "3.16.1"
15 changes: 14 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ wrapper_packages = [
"WCS",
]

function pages_url(repo)
m = match(r"^https://github\.com/([^/]+)/([^/]+?)(?:\.git)?/?$", repo)
if isnothing(m)
@warn "Cannot derive a GitHub Pages URL; the version selector will have no \"See All Versions\" entry" repo
return nothing
end
return "https://$(lowercase(m[1])).github.io/$(m[2])/"
end

function generate_multidoc_refs((name, p); clonedir=clonedir)
package_path = string(chopsuffix(name, ".jl"))
package_name = if package_path in wrapper_packages
Expand All @@ -132,6 +141,10 @@ function generate_multidoc_refs((name, p); clonedir=clonedir)
path = package_path,
name = package_name,
giturl = p["repo"],
versions = MultiDocumenter.VersionSelection(
["stable"];
all_versions_url = pages_url(p["repo"]),
),
)
else
MultiDocumenter.Link(
Expand Down Expand Up @@ -187,7 +200,7 @@ MultiDocumenter.make(
)
@info "Aggregate build complete"

# Remove dev/latest docs from JuliaAstro site
# Cleanup
rm.(glob(joinpath("*", "dev"), outpath); recursive=true)
rm.(glob(joinpath("*", "latest*"), outpath); recursive=true)

Expand Down
Loading