make.jl 2.65 KB
Newer Older
Sylvain Arreckx's avatar
Sylvain Arreckx committed
1
using Documenter, COBREXA
2
3
using Literate

4
# Note: required to deploy the doc from Gitlab CI instead of Travis
5
ENV["TRAVIS_REPO_SLUG"] = "LCSB-BioCore/COBREXA.jl"
6
ENV["TRAVIS_BRANCH"] = "master"
7

Laurent Heirendt's avatar
Laurent Heirendt committed
8
# set the merge/pull request ID
9
10
if "CI_EXTERNAL_PULL_REQUEST_IID" in keys(ENV)
    ENV["TRAVIS_PULL_REQUEST"] = ENV["CI_EXTERNAL_PULL_REQUEST_IID"]
Laurent Heirendt's avatar
Laurent Heirendt committed
11
12
13
14
else
    ENV["TRAVIS_PULL_REQUEST"] = "false"
end

15
# generate notebooks
16
notebooks_path = joinpath(@__DIR__, "src", "notebooks")
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
17
18
notebooks =
    joinpath.(notebooks_path, filter(x -> endswith(x, ".jl"), readdir(notebooks_path)))
19
notebooks_outdir = joinpath(@__DIR__, "src", "notebooks")
20

Laurent Heirendt's avatar
Laurent Heirendt committed
21
22
23
24
25
26
27
28
29
30
# set the appropriate folder
folder = Base.CoreLogging.with_logger(Base.CoreLogging.NullLogger()) do
    Documenter.deploy_folder(
        nothing;
        repo = "github.com/$(ENV["TRAVIS_PULL_REQUEST"]).git",
        devbranch = "master",
        push_preview = true,
        devurl = "dev",
    )
end
31
32
33
34

## only temporary - will be removed once public
branch = "gh-pages"

35
36
37
38
39
40
41
42
43
44
for notebook in notebooks
    Literate.markdown(
        notebook,
        notebooks_outdir;
        repo_root_url = "https://github.com/$(ENV["TRAVIS_REPO_SLUG"])/blob/master",
        nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(ENV["TRAVIS_REPO_SLUG"])/blob/gh-pages/$(folder)",
        binder_root_url = "https://mybinder.org/v2/gh/$(ENV["TRAVIS_REPO_SLUG"])/$(branch)?filepath=$(folder)",
    )
    Literate.notebook(notebook, notebooks_outdir)
end
45

46
47
48
49
50
51
# generate index.md from .template and the quickstart in README.md
quickstart = match(
    r"<!--quickstart_begin-->\n([^\0]*)<!--quickstart_end-->",
    open(f -> read(f, String), joinpath(@__DIR__, "..", "README.md")),
).captures[1]
index_md = replace(
St. Elmo's avatar
St. Elmo committed
52
    open(f -> read(f, String), joinpath(@__DIR__, "src", "index-template.md")),
53
    "<!--insert_quickstart-->\n" => quickstart,
cylon-x's avatar
cylon-x committed
54
)
55
open(f -> write(f, index_md), joinpath(@__DIR__, "src", "index.md"), "w")
Sylvain Arreckx's avatar
Sylvain Arreckx committed
56

57
# build the docs
St. Elmo's avatar
St. Elmo committed
58
59
60
61
62
63
64
65
66
67
68
69
70
71
makedocs(
    modules = [COBREXA],
    clean = false,
    sitename = "COBREXA.jl",
    format = Documenter.HTML(
        # Use clean URLs, unless built as a "local" build
        prettyurls = !("local" in ARGS),
        assets = ["assets/favicon.ico"],
        highlights = ["yaml"],
    ),
    authors = "The developers of COBREXA.jl",
    linkcheck = !("skiplinks" in ARGS),
    pages = [
        "Home" => "index.md",
72
        "Tutorials" => "tutorials.md",
73
        "Examples and notebooks" => "notebooks.md",
74
        "Function reference" => "functions.md",
St. Elmo's avatar
St. Elmo committed
75
76
77
        "How to contribute" => "howToContribute.md",
    ],
)
78

Laurent Heirendt's avatar
Laurent Heirendt committed
79
deploydocs(
Laurent Heirendt's avatar
Laurent Heirendt committed
80
81
82
    repo = "github.com/$(ENV["TRAVIS_REPO_SLUG"]).git",
    target = "build",
    branch = "gh-pages",
Laurent Heirendt's avatar
Laurent Heirendt committed
83
    push_preview = true
Laurent Heirendt's avatar
Laurent Heirendt committed
84
)