Browse Source

Add support for links when running in GitHub Actions.

pull/77/head
Fredrik Ekre 6 years ago
parent
commit
51a0363670
  1. 26
      src/Literate.jl
  2. 72
      test/runtests.jl

26
src/Literate.jl

@ -189,22 +189,28 @@ function replace_default(content, sym; @@ -189,22 +189,28 @@ function replace_default(content, sym;
@warn("mybinder.org requires the notebook to be in a git repository, " *
"which does not work with DocumentationGenerator.jl")
end
elseif get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") == "true"
## Travis CI
elseif haskey(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL") || haskey(ENV, "GITHUB_ACTION")
## Travis CI / GitHub Actions
### Use same logic as Documenter to figure out the deploy folder
travis_repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "TRAVIS_REPO_SLUG")
travis_tag = get(ENV, "TRAVIS_TAG", "TRAVIS_TAG")
repo_slug = get(ENV, "TRAVIS_REPO_SLUG", get(ENV, "GITHUB_REPOSITORY", "REPO_SLUG"))
tag = get(ENV, "TRAVIS_TAG") do
github_ref = get(ENV, "GITHUB_REF", nothing)
github_ref === nothing && return nothing
m = match(r"^refs/tags/(.*)$", github_ref)
m === nothing && return nothing
return String(m.captures[1])
end
### use the versioned directory for links, even for the stable
### and release folders since these will not change
folder = isempty(travis_tag) ? "dev" : travis_tag
folder = (tag === nothing || isempty(tag)) ? "dev" : tag
### replace @__REPO_ROOT_URL__ to master/commit
repo_root_url = "https://github.com/$(travis_repo_slug)/blob/$(commit)"
repo_root_url = "https://github.com/$(repo_slug)/blob/$(commit)"
push!(repls, "@__REPO_ROOT_URL__" => repo_root_url)
### replace @__NBVIEWER_ROOT_URL__ to dev or version directory
nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(travis_repo_slug)/blob/$(branch)/$(folder)"
nbviewer_root_url = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(branch)/$(folder)"
push!(repls, "@__NBVIEWER_ROOT_URL__" => nbviewer_root_url)
### replace @__BINDER_ROOT_URL__ to dev or version directory
binder_root_url = "https://mybinder.org/v2/gh/$(travis_repo_slug)/$(branch)?filepath=$(folder)"
binder_root_url = "https://mybinder.org/v2/gh/$(repo_slug)/$(branch)?filepath=$(folder)"
push!(repls, "@__BINDER_ROOT_URL__" => binder_root_url)
else
## Warn about broken link expansions
@ -212,8 +218,8 @@ function replace_default(content, sym; @@ -212,8 +218,8 @@ function replace_default(content, sym;
(match(r"@__NBVIEWER_ROOT_URL__", content) !== nothing) ||
(match(r"@__BINDER_ROOT_URL__", content) !== nothing)
@warn("expansion of `@__REPO_ROOT_URL__`, `@__REPO_ROOT_URL__` and " *
" `@__REPO_ROOT_URL__` will only be correct if running in " *
"DocumentationGenerator.jl or Travis CI.")
" `@__REPO_ROOT_URL__` will only be correct if running from " *
"DocumentationGenerator.jl, Travis CI or GitHub Actions.")
end
end

72
test/runtests.jl

@ -294,6 +294,30 @@ const expansion_warning = get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") == "true" @@ -294,6 +294,30 @@ const expansion_warning = get(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL", "") == "true"
script = read(joinpath(outdir, "inputfile.jl"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", script)
# GitHub Actions with a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/tags/v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.script(inputfile, outdir)
end
script = read(joinpath(outdir, "inputfile.jl"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/", script)
# GitHub Actions without a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/heads/master",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.script(inputfile, outdir)
end
script = read(joinpath(outdir, "inputfile.jl"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", script)
# building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do
@ -449,6 +473,30 @@ end @@ -449,6 +473,30 @@ end
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", markdown)
# GitHub Actions with a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/tags/v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.markdown(inputfile, outdir)
end
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/", markdown)
# GitHub Actions without a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/heads/master",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.markdown(inputfile, outdir)
end
markdown = read(joinpath(outdir, "inputfile.md"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", markdown)
# building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do
@ -679,6 +727,30 @@ end @@ -679,6 +727,30 @@ end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", notebook)
# GitHub Actions with a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/tags/v1.2.0",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.notebook(inputfile, outdir, execute = false)
end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/", notebook)
# GitHub Actions without a tag
withenv("GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_REF" => "refs/heads/master",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => nothing,
"TRAVIS_REPO_SLUG" => nothing,
"TRAVIS_TAG" => nothing) do
Literate.notebook(inputfile, outdir, execute = false)
end
notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("fredrikekre/Literate.jl/blob/gh-pages/dev/", notebook)
# building under DocumentationGenerator.jl
withenv("DOCUMENTATIONGENERATOR" => "true",
"DOCUMENTATIONGENERATOR_BASE_URL" => "pkg.julialang.org/docs/Literate/XPnWG/1.2.0") do

Loading…
Cancel
Save