From 640854bd98505e12a5d69b28575183d8f8ad98dc Mon Sep 17 00:00:00 2001 From: Morten Piibeleht Date: Fri, 17 Jul 2020 09:02:23 +1200 Subject: [PATCH] Fix nightly PDFs (#19) The git reset --hard in commit() is (probably) there so avoid a race condition when multiple workers are building and pushing PDFs. However, if it's a situation where a PDF needs to be updated (as opposed to the creation of a new file; as is the case for nightlies), that actually wipes out the updated PDF. With this patch, we build all the PDFs into a temporary directory and then copy them over to JULIA_DOCS only after we have run git reset --hard and updated the repository. --- pdf/make.jl | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/pdf/make.jl b/pdf/make.jl index e76eee0cab7c..90702ff728c4 100644 --- a/pdf/make.jl +++ b/pdf/make.jl @@ -1,8 +1,9 @@ using Base64 -const BUILDROOT = get(ENV, "BUILDROOT", pwd()) -const JULIA_SOURCE = get(ENV, "JULIA_SOURCE", "$(BUILDROOT)/julia") -const JULIA_DOCS = get(ENV, "JULIA_DOCS", "$(BUILDROOT)/docs.julialang.org") +const BUILDROOT = get(ENV, "BUILDROOT", pwd()) +const JULIA_SOURCE = get(ENV, "JULIA_SOURCE", "$(BUILDROOT)/julia") +const JULIA_DOCS = get(ENV, "JULIA_DOCS", "$(BUILDROOT)/docs.julialang.org") +const JULIA_DOCS_TMP = get(ENV, "JULIA_DOCS_TMP", "$(BUILDROOT)/tmp") # download and extract binary for a given version, return path to executable function download_release(v::VersionNumber) @@ -54,12 +55,14 @@ function makedocs(julia_exec) end end -function copydocs(path) +function copydocs(file) + isdir(JULIA_DOCS_TMP) || mkpath(JULIA_DOCS_TMP) output = "$(JULIA_SOURCE)/doc/_build/pdf/en" + destination = "$(JULIA_DOCS_TMP)/$(file)" for f in readdir(output) if startswith(f, "TheJuliaLanguage") && endswith(f, ".pdf") - cp("$(output)/$(f)", path; force=true) - @info "finished, output file copied to $(path)." + cp("$(output)/$(f)", destination; force=true) + @info "finished, output file copied to $(destination)." break end end @@ -70,10 +73,9 @@ function build_release_pdf(v::VersionNumber) @info "building PDF for Julia v$(x).$(y).$(z)." file = "julia-$(x).$(y).$(z).pdf" - path = "$(JULIA_DOCS)/$(file)" # early return if file exists - if isfile(path) + if isfile("$(JULIA_DOCS)/$(file)") @info "PDF for Julia v$(x).$(y).$(z) already exists, skipping." return end @@ -89,8 +91,8 @@ function build_release_pdf(v::VersionNumber) # invoke makedocs makedocs(julia_exec) - # copy built PDF to JULIA_DOCS - copydocs(path) + # copy built PDF to JULIA_DOCS_TMP + copydocs(file) end function build_nightly_pdf() @@ -100,9 +102,6 @@ function build_nightly_pdf() _, _, v = split(readchomp(`$(julia_exec) --version`)) @info "commit determined to $(commit) and version determined to $(v)." - file = "julia-$(v).pdf" - path = "$JULIA_DOCS/$file" - # checkout correct commit and clean repo run(`git -C $(JULIA_SOURCE) checkout $(commit)`) run(`git -C $(JULIA_SOURCE) clean -fdx`) @@ -111,7 +110,7 @@ function build_nightly_pdf() makedocs(julia_exec) # copy the built PDF to JULIA_DOCS - copydocs(path) + copydocs("julia-$(v).pdf") end # find all tags in the julia repo @@ -139,12 +138,24 @@ function commit() @info "skipping commit from pull requests." return end + if !isdir(JULIA_DOCS_TMP) + @info "No new PDFs created, skipping commit." + return + end @info "committing built PDF files." # Make sure the repo is up to date run(`git fetch origin`) run(`git reset --hard origin/assets`) + # Copy file from JULIA_DOCS_TMP to JULIA_DOCS + for file in readdir(JULIA_DOCS_TMP) + endswith(file, ".pdf") || continue + from = joinpath(JULIA_DOCS_TMP, file) + @debug "Copying a PDF" file from pwd() + cp(from, file; force = true) + end + mktemp() do keyfile, iokey; mktemp() do sshconfig, iossh # Set up keyfile write(iokey, base64decode(get(ENV, "DOCUMENTER_KEY_PDF", "")))