Skip to content

Commit

Permalink
Fix nightly PDFs (#19)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mortenpi authored Jul 16, 2020
1 parent 3c6a58c commit 640854b
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions pdf/make.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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`)
Expand All @@ -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
Expand Down Expand Up @@ -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", "")))
Expand Down

0 comments on commit 640854b

Please sign in to comment.