Skip to content

Commit a2d87a8

Browse files
authored
stop on demo build error (#85)
Previously, demo build error is suppressed as warning. Now that we have a new keyword `throw_error` that enables you to immediately stop the build when the demo build fails.
1 parent 07aa3b7 commit a2d87a8

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

src/generate.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
build = "build",
66
branch = "gh-pages",
77
edit_branch = "master",
8-
credit = true) -> page_path, postprocess_cb
8+
credit = true,
9+
throw_error = false) -> page_path, postprocess_cb
910
1011
Make a demo page for `source` and return the path to the generated index file.
1112
@@ -42,7 +43,9 @@ Processing pipeline:
4243
* `build::String`: should be equal to `Documenter`'s setting. By default it's `"build"`.
4344
* `edit_branch::String`: should be equal to `Documenter`'s setting. By default it's `"master"`.
4445
* `branch::String`: should be equal to `Documenter`'s setting. By default it's `"gh-pages"`.
45-
* `credit::String`: `true` to show a "This page is generated by ..." info. By default it's `true`.
46+
* `credit::Bool`: `true` to show a "This page is generated by ..." info. By default it's `true`.
47+
* `throw_error::Bool`: `true` to throw an error when the julia demo build fails; otherwise it will
48+
continue the build with warnings.
4649
4750
# Examples
4851
@@ -88,7 +91,8 @@ function makedemos(source::String, templates::Union{Dict, Nothing} = nothing;
8891
build::String = "build",
8992
branch::String = "gh-pages",
9093
edit_branch::String = "master",
91-
credit = true)
94+
credit = true,
95+
throw_error = false)
9296

9397
if !(basename(pwd()) == "docs" || basename(root) == "docs" || root == preview_build_dir())
9498
# special cases that warnings are not printed:
@@ -182,7 +186,8 @@ function makedemos(source::String, templates::Union{Dict, Nothing} = nothing;
182186
project_root = root,
183187
src = src,
184188
credit = credit,
185-
nbviewer_root_url = get_nbviewer_root_url(branch))
189+
nbviewer_root_url = get_nbviewer_root_url(branch),
190+
throw_error=throw_error)
186191
isnothing(templates) || save_cover(joinpath(absolute_root, "covers"), page)
187192
isnothing(templates) || generate(joinpath(absolute_root, "index.md"), page, templates)
188193

src/preview.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Generate a docs preview for a single demo card.
2222
* `assets = String[]`: this is passed to `Documenter.HTML`
2323
* `edit_branch = "master"`: same to that in `makedemos`
2424
* `credit = true`: same to that in `makedemos`
25+
* `throw_error = false`: same to that in `makedemos`
2526
* `require_html = true`: if it needs to trigger the Documenter workflow and generate HTML preview.
2627
If set to `false`, the return value is then the path to the generated `index.md` file. This is an
2728
experimental keyword and should not be considered stable.
@@ -33,6 +34,7 @@ function preview_demos(demo_path::String;
3334
edit_branch = "master",
3435
assets = String[],
3536
credit = true,
37+
throw_error = false,
3638
require_html = true,
3739
clean = true)
3840
# hard code these args in a sandbox environment -- there's no need for customization
@@ -84,7 +86,8 @@ function preview_demos(demo_path::String;
8486
src = src,
8587
build = build,
8688
edit_branch = edit_branch,
87-
credit = credit
89+
credit = credit,
90+
throw_error = throw_error,
8891
)
8992

9093
# In cases that addtional Documenter pipeline is not needed

src/types/card.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The return type `T` is determined by the extension of the path
99
to your demofile. Currently supported types are:
1010
1111
* [`MarkdownDemoCard`](@ref)
12+
* [`JuliaDemoCard`](@ref)
13+
1214
"""
1315
function democard(path::String)::AbstractDemoCard
1416
validate_file(path)

src/types/julia.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function save_democards(card_dir::String,
117117
nbviewer_root_url,
118118
project_dir=Base.source_dir(),
119119
src="src",
120+
throw_error = false,
120121
kwargs...)
121122
isdir(card_dir) || mkpath(card_dir)
122123
cardname = splitext(basename(card.path))[1]
@@ -154,8 +155,17 @@ function save_democards(card_dir::String,
154155
isempty(readdir(x)) && rm(x; recursive=true, force=true)
155156
end
156157
catch err
157-
# throw warnings when generating notebooks
158-
err isa LoadError || rethrow(err)
158+
if err isa LoadError
159+
# TODO: provide more informative debug message
160+
@warn "something wrong during the assets generation for demo $cardname.jl"
161+
if throw_error
162+
rethrow(err)
163+
else
164+
@warn err
165+
end
166+
else
167+
rethrow(err)
168+
end
159169
end
160170
end
161171

@@ -171,7 +181,7 @@ function save_democards(card_dir::String,
171181
try
172182
@suppress Literate.notebook(src_path, card_dir; credit=credit)
173183
catch err
174-
@warn err.msg
184+
nothing # early warning in the asserts generation
175185
end
176186

177187
# 3. markdown

test/assets/broken_demo.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f(2)

test/generate.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@
3333
@test readdir(joinpath(page_dir, "covers")) == ["democards_logo.svg"]
3434
@test readdir(joinpath(page_dir, "sec")) == ["hidden1.ipynb", "hidden1.jl", "hidden1.md", "hidden2.md", "normal.md"]
3535
end
36+
37+
@testset "throw_error" begin
38+
@suppress_err @test_throws LoadError preview_demos(joinpath(root, "broken_demo.jl"); throw_error=true)
39+
end
3640
end

0 commit comments

Comments
 (0)