-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathmake.jl
196 lines (180 loc) · 7.2 KB
/
make.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
import Documenter
import MathOptInterface
# Pass --fix` to rebuild the doctests.
const _FIX = findfirst(isequal("--fix"), ARGS) !== nothing
# A flag to check if we are running in a GitHub action.
const _IS_GITHUB_ACTIONS = get(ENV, "GITHUB_ACTIONS", "false") == "true"
# Pass --pdf to build the PDF. On GitHub actions, we always build the PDF.
const _PDF = findfirst(isequal("--pdf"), ARGS) !== nothing || _IS_GITHUB_ACTIONS
# ==============================================================================
# Documentation structure
# ==============================================================================
const _PAGES = [
"Introduction" => ["index.md", "background/motivation.md"],
"Tutorials" => [
"tutorials/example.md",
"tutorials/implementing.md",
"tutorials/mathprogbase.md",
"tutorials/bridging_constraint.md",
"tutorials/manipulating_expressions.md",
"tutorials/latency.md",
],
"Manual" => [
"manual/standard_form.md",
"manual/models.md",
"manual/variables.md",
"manual/constraints.md",
"manual/solutions.md",
"manual/modification.md",
],
"Background" => [
"background/duality.md",
"background/infeasibility_certificates.md",
"background/naming_conventions.md",
],
"API Reference" => [
"reference/standard_form.md",
"reference/models.md",
"reference/variables.md",
"reference/constraints.md",
"reference/modification.md",
"reference/nonlinear.md",
"reference/callbacks.md",
"reference/errors.md",
],
"Submodules" => [
"Benchmarks" => [
"Overview" => "submodules/Benchmarks/overview.md",
"API Reference" => "submodules/Benchmarks/reference.md",
],
"Bridges" => [
"Overview" => "submodules/Bridges/overview.md",
"Implementation" => "submodules/Bridges/implementation.md",
"List of bridges" => "submodules/Bridges/list_of_bridges.md",
"API Reference" => "submodules/Bridges/reference.md",
],
"FileFormats" => [
"Overview" => "submodules/FileFormats/overview.md",
"API Reference" => "submodules/FileFormats/reference.md",
],
"Nonlinear" => [
"Overview" => "submodules/Nonlinear/overview.md",
"SymbolicAD" => "submodules/Nonlinear/SymbolicAD.md",
"API Reference" => "submodules/Nonlinear/reference.md",
],
"Utilities" => [
"Overview" => "submodules/Utilities/overview.md",
"API Reference" => "submodules/Utilities/reference.md",
],
"Test" => [
"Overview" => "submodules/Test/overview.md",
"API Reference" => "submodules/Test/reference.md",
],
],
"Developer Docs" => ["developer/checklists.md"],
"Release notes" => "release_notes.md",
]
# ==============================================================================
# Modify the release notes
# ==============================================================================
function fix_release_line(
line::String,
url::String = "https://github.com/jump-dev/MathOptInterface.jl",
)
# (#XXXX) -> ([#XXXX](url/issue/XXXX))
while (m = match(r"\(\#([0-9]+)\)", line)) !== nothing
id = m.captures[1]
line = replace(line, m.match => "([#$id]($url/issues/$id))")
end
# ## vX.Y.Z -> [vX.Y.Z](url/releases/tag/vX.Y.Z)
while (m = match(r"\#\# (v[0-9]+.[0-9]+.[0-9]+)", line)) !== nothing
tag = m.captures[1]
line = replace(line, m.match => "## [$tag]($url/releases/tag/$tag)")
end
return line
end
open(joinpath(@__DIR__, "src", "changelog.md"), "r") do in_io
open(joinpath(@__DIR__, "src", "release_notes.md"), "w") do out_io
for line in readlines(in_io; keep = true)
write(out_io, fix_release_line(line))
end
end
end
# ==============================================================================
# Build the HTML docs
# ==============================================================================
# Needed to make Documenter think that there is a PDF in the right place when
# link checking. Inn production we replace this by running the LaTeX build.
write(joinpath(@__DIR__, "src", "MathOptInterface.pdf"), "")
@time Documenter.makedocs(
sitename = "MathOptInterface",
authors = "The JuMP core developers and contributors",
format = Documenter.HTML(
# See https://github.com/JuliaDocs/Documenter.jl/issues/868
prettyurls = get(ENV, "CI", nothing) == "true",
mathengine = Documenter.MathJax2(),
collapselevel = 1,
# Do no check for large pages.
size_threshold_ignore = [
"changelog.md",
"release_notes.md",
"reference/models.md",
"reference/standard_form.md",
"submodules/Bridges/list_of_bridges.md",
"submodules/Bridges/reference.md",
"submodules/Utilities/reference.md",
],
),
clean = true,
linkcheck = true,
linkcheck_ignore = [
# Ignore the PDF link, because it hasn't been built yet.
"MathOptInterface.pdf",
# Ignore tags, because prepping for a new release will otherwise cause
# it to fail.
r"https://github.com/jump-dev/MathOptInterface.jl/releases/tag/v([0-9]).([0-9]+).([0-9]+)",
# Ignore issue and pull request links, because there are many of them,
# and they sometimes time-out the linkcheck.
r"https://github.com/jump-dev/MathOptInterface.jl/issues/([0-9]+)",
"https://arxiv.org/abs/2002.03447",
],
modules = [MathOptInterface],
checkdocs = :exports,
doctest = _FIX ? :fix : true,
pages = _PAGES,
)
# ==============================================================================
# Build the LaTeX docs (if needed)
# ==============================================================================
if _PDF
latex_platform = _IS_GITHUB_ACTIONS ? "docker" : "native"
# Remove the Release Notes; we don't need them in the PDF.
pop!(_PAGES)
@time Documenter.makedocs(
sitename = "MathOptInterface",
authors = "The JuMP core developers and contributors",
format = Documenter.LaTeX(platform = latex_platform),
build = "latex_build",
pages = _PAGES,
)
# Hack for deploying: copy the PDF (and only the PDF) into the HTML build
# directory. We don't want to copy everything in `latex_build` because it
# includes lots of extraneous LaTeX files.
cp(
joinpath(@__DIR__, "latex_build", "MathOptInterface.pdf"),
joinpath(@__DIR__, "build", "MathOptInterface.pdf");
force = true,
)
end
# ==============================================================================
# Deploy everything in `build`
# ==============================================================================
Documenter.deploydocs(
repo = "github.com/jump-dev/MathOptInterface.jl.git",
push_preview = true,
)