-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfix_doctests.jl
78 lines (64 loc) · 1.61 KB
/
fix_doctests.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
#####
##### Activate the right project (usually `docs`)
#####
using Pkg
project_path = get(ENV, "INPUT_PROJECT", "")
if isempty(project_path)
project_path = mktempdir()
end
Pkg.activate(project_path)
#####
##### `dev` the package code into our project
#####
package_path = get(ENV, "INPUT_PACKAGE_PATH", "")
if isempty(package_path)
package_path = pwd()
end
Pkg.develop(PackageSpec(path=package_path))
Pkg.instantiate()
#####
##### parse the package name out of its Project.toml
#####
try
using TOML # stdlib on Julia v1.6+
catch
@info "Adding TOML..."
Pkg.add("TOML")
using TOML
end
name_str = TOML.parsefile(joinpath(package_path, "Project.toml"))["name"]
name_sym = Symbol(name_str)
@info "Package name: $(name_sym)"
#####
##### Load Documenter
#####
try
using Documenter
catch
@warn("Documenter.jl was not found in the `$(project_path)` environment. Adding latest release...")
Pkg.add("Documenter")
using Documenter
end
#####
##### Run the doctests with `fix=true`
#####
@eval begin
using $(name_sym)
DocMeta.setdocmeta!($(name_sym), :DocTestSetup, :(using $name_sym); recursive=true)
doctest($(name_sym); fix=true)
end
#####
##### Reset the docs Project + Manifest so that they don't show up in the diff
#####
function reset(file)
try
path = joinpath(project_path, file)
read(`git checkout HEAD -- $path`) # `read` instead of `run` to suppress output
@info "Reset $path"
catch
# We may not be in a git repo, and the file may not be committed,
# so we will ignore errors here.
end
end
reset("Project.toml")
reset("Manifest.toml")