Browse Source

Ignore build version information for automatic URLs, fixes #162.

pull/167/head
Fredrik Ekre 4 years ago
parent
commit
21c16e65c1
  1. 6
      CHANGELOG.md
  2. 17
      src/Literate.jl
  3. 4
      test/runtests.jl

6
CHANGELOG.md

@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Fixed
- Automatic URLs from `@__NBVIEWER_ROOT_URL__` and `@__BINDER_ROOT_URL__` now follow the
convention [used in Documenter.jl](https://github.com/JuliaDocs/Documenter.jl/pull/1298)
to ignore build version information. ([#162][github-162], [#163][github-163])
## [2.9.0] - 2021-07-09 ## [2.9.0] - 2021-07-09
### Added ### Added
@ -128,6 +132,8 @@ https://discourse.julialang.org/t/ann-literate-jl/10651 for release announcement
[github-152]: https://github.com/fredrikekre/Literate.jl/pull/152 [github-152]: https://github.com/fredrikekre/Literate.jl/pull/152
[github-156]: https://github.com/fredrikekre/Literate.jl/pull/156 [github-156]: https://github.com/fredrikekre/Literate.jl/pull/156
[github-159]: https://github.com/fredrikekre/Literate.jl/pull/159 [github-159]: https://github.com/fredrikekre/Literate.jl/pull/159
[github-162]: https://github.com/fredrikekre/Literate.jl/issues/162
[github-163]: https://github.com/fredrikekre/Literate.jl/pull/163
[Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.0...HEAD [Unreleased]: https://github.com/fredrikekre/Literate.jl/compare/v2.9.0...HEAD
[2.9.0]: https://github.com/fredrikekre/Literate.jl/compare/v2.8.1...v2.9.0 [2.9.0]: https://github.com/fredrikekre/Literate.jl/compare/v2.8.1...v2.9.0

17
src/Literate.jl

@ -263,11 +263,24 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
# Guess the package (or repository) root url # Guess the package (or repository) root url
edit_commit = "master" # TODO: Make this configurable like Documenter? edit_commit = "master" # TODO: Make this configurable like Documenter?
deploy_branch = "gh-pages" # TODO: Make this configurable like Documenter? deploy_branch = "gh-pages" # TODO: Make this configurable like Documenter?
# Strip build version from a tag (cf. JuliaDocs/Documenter.jl#1298, Literate.jl#162)
function version_tag_strip_build(tag)
m = match(Base.VERSION_REGEX, tag)
m === nothing && return tag
s0 = startswith(tag, 'v') ? "v" : ""
s1 = m[1] # major
s2 = m[2] === nothing ? "" : ".$(m[2])" # minor
s3 = m[3] === nothing ? "" : ".$(m[3])" # patch
s4 = m[5] === nothing ? "" : m[5] # pre-release (starting with -)
# m[7] is the build, which we want to discard
return "$s0$s1$s2$s3$s4"
end
if haskey(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL") # Travis CI if haskey(ENV, "HAS_JOSH_K_SEAL_OF_APPROVAL") # Travis CI
repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "unknown-repository") repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "unknown-repository")
deploy_folder = if get(ENV, "TRAVIS_PULL_REQUEST", nothing) == "false" deploy_folder = if get(ENV, "TRAVIS_PULL_REQUEST", nothing) == "false"
t = get(ENV, "TRAVIS_TAG", "") t = get(ENV, "TRAVIS_TAG", "")
isempty(t) ? get(user_config, "devurl", "dev") : t isempty(t) ? get(user_config, "devurl", "dev") : version_tag_strip_build(t)
else else
"previews/PR$(get(ENV, "TRAVIS_PULL_REQUEST", "##"))" "previews/PR$(get(ENV, "TRAVIS_PULL_REQUEST", "##"))"
end end
@ -281,7 +294,7 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
repo_slug = get(ENV, "GITHUB_REPOSITORY", "unknown-repository") repo_slug = get(ENV, "GITHUB_REPOSITORY", "unknown-repository")
deploy_folder = if get(ENV, "GITHUB_EVENT_NAME", nothing) == "push" deploy_folder = if get(ENV, "GITHUB_EVENT_NAME", nothing) == "push"
if (m = match(r"^refs\/tags\/(.*)$", get(ENV, "GITHUB_REF", ""))) !== nothing if (m = match(r"^refs\/tags\/(.*)$", get(ENV, "GITHUB_REF", ""))) !== nothing
String(m.captures[1]) version_tag_strip_build(String(m.captures[1]))
else else
get(user_config, "devurl", "dev") get(user_config, "devurl", "dev")
end end

4
test/runtests.jl

@ -268,7 +268,7 @@ content = """
const TRAVIS_ENV = Dict( const TRAVIS_ENV = Dict(
"TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl", "TRAVIS_REPO_SLUG" => "fredrikekre/Literate.jl",
"TRAVIS_TAG" => "v1.2.0", "TRAVIS_TAG" => "v1.2.0+docs",
"TRAVIS_PULL_REQUEST" => "false", "TRAVIS_PULL_REQUEST" => "false",
"HAS_JOSH_K_SEAL_OF_APPROVAL" => "true", "HAS_JOSH_K_SEAL_OF_APPROVAL" => "true",
"TRAVIS_BUILD_DIR" => normpath(joinpath(@__DIR__, "..")), "TRAVIS_BUILD_DIR" => normpath(joinpath(@__DIR__, "..")),
@ -278,7 +278,7 @@ const ACTIONS_ENV = Dict(
"GITHUB_ACTION" => "Build docs", "GITHUB_ACTION" => "Build docs",
"GITHUB_REPOSITORY" => "fredrikekre/Literate.jl", "GITHUB_REPOSITORY" => "fredrikekre/Literate.jl",
"GITHUB_EVENT_NAME" => "push", "GITHUB_EVENT_NAME" => "push",
"GITHUB_REF" => "refs/tags/v1.2.0", "GITHUB_REF" => "refs/tags/v1.2.0+docs",
"GITHUB_WORKSPACE" => normpath(joinpath(@__DIR__, "..")), "GITHUB_WORKSPACE" => normpath(joinpath(@__DIR__, "..")),
(k => nothing for k in keys(TRAVIS_ENV))..., (k => nothing for k in keys(TRAVIS_ENV))...,
) )

Loading…
Cancel
Save