Skip to content

Commit 640854b

Browse files
authored
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.
1 parent 3c6a58c commit 640854b

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

pdf/make.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using Base64
22

3-
const BUILDROOT = get(ENV, "BUILDROOT", pwd())
4-
const JULIA_SOURCE = get(ENV, "JULIA_SOURCE", "$(BUILDROOT)/julia")
5-
const JULIA_DOCS = get(ENV, "JULIA_DOCS", "$(BUILDROOT)/docs.julialang.org")
3+
const BUILDROOT = get(ENV, "BUILDROOT", pwd())
4+
const JULIA_SOURCE = get(ENV, "JULIA_SOURCE", "$(BUILDROOT)/julia")
5+
const JULIA_DOCS = get(ENV, "JULIA_DOCS", "$(BUILDROOT)/docs.julialang.org")
6+
const JULIA_DOCS_TMP = get(ENV, "JULIA_DOCS_TMP", "$(BUILDROOT)/tmp")
67

78
# download and extract binary for a given version, return path to executable
89
function download_release(v::VersionNumber)
@@ -54,12 +55,14 @@ function makedocs(julia_exec)
5455
end
5556
end
5657

57-
function copydocs(path)
58+
function copydocs(file)
59+
isdir(JULIA_DOCS_TMP) || mkpath(JULIA_DOCS_TMP)
5860
output = "$(JULIA_SOURCE)/doc/_build/pdf/en"
61+
destination = "$(JULIA_DOCS_TMP)/$(file)"
5962
for f in readdir(output)
6063
if startswith(f, "TheJuliaLanguage") && endswith(f, ".pdf")
61-
cp("$(output)/$(f)", path; force=true)
62-
@info "finished, output file copied to $(path)."
64+
cp("$(output)/$(f)", destination; force=true)
65+
@info "finished, output file copied to $(destination)."
6366
break
6467
end
6568
end
@@ -70,10 +73,9 @@ function build_release_pdf(v::VersionNumber)
7073
@info "building PDF for Julia v$(x).$(y).$(z)."
7174

7275
file = "julia-$(x).$(y).$(z).pdf"
73-
path = "$(JULIA_DOCS)/$(file)"
7476

7577
# early return if file exists
76-
if isfile(path)
78+
if isfile("$(JULIA_DOCS)/$(file)")
7779
@info "PDF for Julia v$(x).$(y).$(z) already exists, skipping."
7880
return
7981
end
@@ -89,8 +91,8 @@ function build_release_pdf(v::VersionNumber)
8991
# invoke makedocs
9092
makedocs(julia_exec)
9193

92-
# copy built PDF to JULIA_DOCS
93-
copydocs(path)
94+
# copy built PDF to JULIA_DOCS_TMP
95+
copydocs(file)
9496
end
9597

9698
function build_nightly_pdf()
@@ -100,9 +102,6 @@ function build_nightly_pdf()
100102
_, _, v = split(readchomp(`$(julia_exec) --version`))
101103
@info "commit determined to $(commit) and version determined to $(v)."
102104

103-
file = "julia-$(v).pdf"
104-
path = "$JULIA_DOCS/$file"
105-
106105
# checkout correct commit and clean repo
107106
run(`git -C $(JULIA_SOURCE) checkout $(commit)`)
108107
run(`git -C $(JULIA_SOURCE) clean -fdx`)
@@ -111,7 +110,7 @@ function build_nightly_pdf()
111110
makedocs(julia_exec)
112111

113112
# copy the built PDF to JULIA_DOCS
114-
copydocs(path)
113+
copydocs("julia-$(v).pdf")
115114
end
116115

117116
# find all tags in the julia repo
@@ -139,12 +138,24 @@ function commit()
139138
@info "skipping commit from pull requests."
140139
return
141140
end
141+
if !isdir(JULIA_DOCS_TMP)
142+
@info "No new PDFs created, skipping commit."
143+
return
144+
end
142145
@info "committing built PDF files."
143146

144147
# Make sure the repo is up to date
145148
run(`git fetch origin`)
146149
run(`git reset --hard origin/assets`)
147150

151+
# Copy file from JULIA_DOCS_TMP to JULIA_DOCS
152+
for file in readdir(JULIA_DOCS_TMP)
153+
endswith(file, ".pdf") || continue
154+
from = joinpath(JULIA_DOCS_TMP, file)
155+
@debug "Copying a PDF" file from pwd()
156+
cp(from, file; force = true)
157+
end
158+
148159
mktemp() do keyfile, iokey; mktemp() do sshconfig, iossh
149160
# Set up keyfile
150161
write(iokey, base64decode(get(ENV, "DOCUMENTER_KEY_PDF", "")))

0 commit comments

Comments
 (0)