This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.jl
53 lines (46 loc) · 1.57 KB
/
build.jl
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
import Pkg
srcpath = joinpath(@__DIR__(), "Courses")
buildpath = joinpath(@__DIR__(), "Notebooks")
if isempty(ARGS)
courses = filter(x->isdir(joinpath(srcpath), x) && x !== "Template", readdir(srcpath))
else
courses = ARGS
end
rm(buildpath, recursive=true, force=true)
mkdir(buildpath)
notebooks_failed = String[]
Base.julia_cmd()
for dir in courses
@info "building $dir..."
src_course = joinpath(srcpath, dir)
build_course = mkdir(joinpath(buildpath, dir))
cp(src_course, build_course; force=true)
Pkg.activate(build_course)
test = false
Pkg.instantiate()
for file in readdir(build_course)
if endswith(file, ".jl")
course = joinpath(build_course, file)
academy_environment = @__DIR__
# Create a stacked environment with the JuliaAcademy environment in
# it so we can load Literate for each notebook
script = """
pushfirst!(LOAD_PATH, $(repr(academy_environment)));
import Literate;
Literate.notebook($(repr(course)), $(repr(build_course)); credit=false, execute=false)
"""
try
run(`$(Base.julia_cmd()) -e $script`)
catch
err_src_course = relpath(joinpath(src_course, file), @__DIR__)
@error "Script failed to build: $err_src_course)"
push!(notebooks_failed, err_src_course)
end
rm(course)
end
end
end
if !isempty(notebooks_failed)
error("The following notebooks failed: \n",
join(notebooks_failed, '\n'))
end