Skip to content

Commit

Permalink
Use Changelog.jl for changelog infrastructure.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 1, 2023
1 parent 2fabe9c commit bee303d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 144 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* At-docs blocks no longer give an error when containing empty lines. ([#823], [#824])


<!-- Links to pull requests/issues/etc. generated by docs/changelog.jl -->
<!-- Links generated by Changelog.jl -->

[v0.20.0]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v0.20.0
[v0.21.0]: https://github.com/JuliaDocs/Documenter.jl/releases/tag/v0.21.0
Expand Down Expand Up @@ -1362,7 +1362,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#1222]: https://github.com/JuliaDocs/Documenter.jl/issues/1222
[#1223]: https://github.com/JuliaDocs/Documenter.jl/issues/1223
[#1232]: https://github.com/JuliaDocs/Documenter.jl/issues/1232
[#1234]: https://github.com/JuliaDocs/Documenter.jl/issues/1234
[#1240]: https://github.com/JuliaDocs/Documenter.jl/issues/1240
[#1254]: https://github.com/JuliaDocs/Documenter.jl/issues/1254
[#1258]: https://github.com/JuliaDocs/Documenter.jl/issues/1258
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ docs: docs-instantiate
${JULIA} --project=docs docs/make.jl

changelog:
${JULIA} docs/changelog.jl
${JULIA} --project=docs docs/changelog.jl

themes: docs-instantiate
${JULIA} --project=docs -e 'using DocumenterTools; DocumenterTools.Themes.compile_native_themes()'
Expand Down
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterTools = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
MarkdownAST = "d0879d2d-cac2-40c8-9cee-1863dc0c7391"
149 changes: 12 additions & 137 deletions docs/changelog.jl
Original file line number Diff line number Diff line change
@@ -1,138 +1,13 @@
# =================================================================================
# Utilities for managing CHANGELOG.md and generating a Documenter-friendly version
# =================================================================================

const CHANGELOG_LINK_SEPARATOR = "<!-- Links to pull requests/issues/etc. generated by docs/changelog.jl -->"

function collect_links(;
changelog_inputfile::String,
repo::String,
)
# Output mapping tokens to the full URL
# (e.g. "[#123]" => "https://github.com/JuliaDocs/Documenter.jl/issues/123")
linkmap = Dict{String, String}()

# Read the source file and split the content to ignore the list of links
content = read(changelog_inputfile, String)
content = first(split(content, CHANGELOG_LINK_SEPARATOR))

# Rule: [abc#XXXX] -> https://github.com/abc/issues/XXXX
# Description: Replace issue/PR numbers with a link to the default repo
# Example: [JuliaLang/julia#123] -> https://github.com/JuliaLang/julia/issues/123
# There is no need to distinguish between PRs and Issues because GitHub redirects.
for m in eachmatch(r"\[(?<repo>[a-zA-Z0-9/]+?)\#(?<id>[0-9]+)\]", content)
linkmap[m.match] = "https://github.com/$(m["repo"])/issues/$(m["id"])"
end

# Rule: [#XXXX] -> https://github.com/url/issue/XXXX
# Description: Replace issue/PR numbers with a link to the default repo
# Example: [#123] -> https://github.com/JuliaDocs/Documenter.jl/issues/123
# There is no need to distinguish between PRs and Issues because GitHub redirects.
for m in eachmatch(r"\[\#(?<id>[0-9]+)\]", content)
linkmap[m.match] = "https://github.com/$(repo)/issues/$(m["id"])"
end

# Rule: [@XXXX] -> https://github.com/XXXX
# Description: Replace users with a link to their GitHub
# Example: [@odow] -> https://github.com/odow
for m in eachmatch(r"\[@(?<id>.+?)\]", content)
linkmap[m.match] = "https://github.com/$(m["id"])"
end

# Rule: ## Version [vX.Y.Z] -> url/releases/tag/vX.Y.Z
# Description: Replace version headers with a link to the GitHub release
# Example: ## Version [v0.27.0] -> https://github.com/JuliaDocs/Documenter.jl/releases/tag/v0.27.0
for m in eachmatch(r"^\#\# Version (?<token>\[(?<tag>v[0-9]+.[0-9]+.[0-9]+)\])"m, content)
linkmap[m["token"]] = "https://github.com/$(repo)/releases/tag/$(m["tag"])"
end

return linkmap
end

# Rewrite CHANGELOG.md to a Documenter-friendly markdown file
function rewrite_changelog(;
changelog_inputfile::String,
changelog_outputfile::String,
# current_module::String,
repo::String,
branch::String = "master",
)
# Get the map of token to full URL
linkmap = collect_links(; changelog_inputfile, repo)

# Read the source file and split the content to ignore the list of links
content = read(changelog_inputfile, String)
content = first(split(content, CHANGELOG_LINK_SEPARATOR))

# Replace all link tokens with full URLs
for (k, v) in linkmap
content = replace(content, k => "$k($v)")
end

# Header to set EditURL
header = """
```@meta
EditURL = "https://github.com/$repo/blob/$branch/CHANGELOG.md"
```
"""

# Write it all out
open(changelog_outputfile, "w") do io
write(io, header)
write(io, content)
end

return
end

# Collect and add all links to the CHANGELOG.md footer.
function write_link_footer(;
changelog_inputfile::String,
changelog_outputfile::String = changelog_inputfile,
repo::String,
using Changelog

# Changelog.generate(
# Changelog.Documenter(),
# joinpath(@__DIR__, "..", "CHANGELOG.md"),
# joinpath(@__DIR__, "src", "release-notes.md");
# repo = "JuliaDocs/Documenter.jl",
# )
Changelog.generate(
Changelog.CommonMark(),
joinpath(@__DIR__, "..", "CHANGELOG.md");
repo = "JuliaDocs/Documenter.jl",
)
# Get the map of token to full URL
linkmap = collect(collect_links(; changelog_inputfile, repo))

# Sort releases first, then own issues, then external issues, then other things
sort!(linkmap; by = function(x)
k, v = x
if occursin("/releases/tag/", v)
# Sort releases by version number
return (1, VersionNumber(match(r"\[(?<version>.*)\]", k)["version"]))
elseif occursin("github.com/$(repo)/issues/", v)
# Sort issues by number
n = parse(Int, match(r"\[\#(?<id>\d+)\]", k)["id"])
return (2, n)
elseif occursin(r"github\.com/.*/issues/", v)
# Sort by repo name, then issues by number
m = match(r"\[(?<repo>.*)\#(?<id>\d+)\]", k)
n = parse(Int, m["id"])
return (3, m["repo"], n)
else
return (4,)
end
end)

# Read the source file and split the content to ignore the list of links
content = read(changelog_inputfile, String)
content = strip(first(split(content, CHANGELOG_LINK_SEPARATOR)))

# Write it all out
open(changelog_outputfile, "w") do io
write(io, content)
write(io, "\n\n\n")
write(io, CHANGELOG_LINK_SEPARATOR)
write(io, "\n\n")
for (k, v) in linkmap
println(io, k, ": ", v)
end
end

return
end

# Run write_link_footer if this script is invoked by `julia docs/changelog.jl`
if abspath(PROGRAM_FILE) == @__FILE__
write_link_footer(; changelog_inputfile = "CHANGELOG.md", repo = "JuliaDocs/Documenter.jl")
end
9 changes: 5 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ if haskey(ENV, "DOCSARGS")
end

# Generate a Documenter-friendly changelog from CHANGELOG.md
include("changelog.jl")
rewrite_changelog(;
changelog_inputfile = joinpath(dirname(@__DIR__), "CHANGELOG.md"),
changelog_outputfile = joinpath(@__DIR__, "src", "release-notes.md"),
import Changelog
Changelog.generate(
Changelog.Documenter(),
joinpath(@__DIR__, "..", "CHANGELOG.md"),
joinpath(@__DIR__, "src", "release-notes.md");
repo = "JuliaDocs/Documenter.jl",
)

Expand Down

0 comments on commit bee303d

Please sign in to comment.