diff --git a/CHANGELOG.md b/CHANGELOG.md index fc722bce39..8bae0a03f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,9 @@ * ![Enhancement][badge-enhancement] Videos can now be included in the HTML output using the image syntax (`![]()`) if the file extension matches a known format (`.webm`, `.mp4`, `.ogg`, `.ogm`, `.ogv`, `.avi`). ([#1034][github-1034]) + +* ![Enhancement][badge-enhancement] `deploydocs` now reads the appropriate environment variables on Travis CI, Gitlab CI, Cirrus CI, Drone CI, and AppVeyor, as does `LaTeXWriter`. However, be aware that CI systems other than Travis CI have not received extensive testing. ([#1067][github-1067]) + * ![Enhancement][badge-enhancement] The PDF output now uses the DejaVu Sans and DejaVu Sans Mono fonts to provide better Unicode coverage. ([#803][github-803], [#1066][github-1066]) * ![Bugfix][badge-bugfix] The HTML output now outputs HTML files for pages that are not referenced in the `pages` keyword too (Documenter finds them according to their extension). But they do exists outside of the standard navigation hierarchy (as defined by `pages`). This fixes a bug where these pages could still be referenced by `@ref` links and `@contents` blocks, but in the HTML output, the links ended up being broken. ([#1031][github-1031], [#1047][github-1047]) @@ -383,6 +386,7 @@ [github-1061]: https://github.com/JuliaDocs/Documenter.jl/pull/1061 [github-1062]: https://github.com/JuliaDocs/Documenter.jl/pull/1062 [github-1066]: https://github.com/JuliaDocs/Documenter.jl/pull/1066 +[github-1067]: https://github.com/JuliaDocs/Documenter.jl/pull/1067 [github-1071]: https://github.com/JuliaDocs/Documenter.jl/pull/1071 [documenterlatex]: https://github.com/JuliaDocs/DocumenterLaTeX.jl diff --git a/docs/src/lib/internals/documenter.md b/docs/src/lib/internals/documenter.md index de28117576..c73c3286f9 100644 --- a/docs/src/lib/internals/documenter.md +++ b/docs/src/lib/internals/documenter.md @@ -3,4 +3,5 @@ ```@docs Documenter.gitrm_copy Documenter.git_push +Documenter.read_ci_env ``` diff --git a/docs/src/lib/public.md b/docs/src/lib/public.md index 7231b11d25..ff38e632f0 100644 --- a/docs/src/lib/public.md +++ b/docs/src/lib/public.md @@ -31,6 +31,17 @@ DocMeta.getdocmeta DocMeta.setdocmeta! ``` +### CI platforms supported by `deploydocs` + +```@docs +Documenter.CI_SYSTEM +TRAVIS +GITLAB_CI +CIRRUS_CI +DRONE +APPVEYOR +``` + ## DocumenterTools ```@docs diff --git a/docs/src/man/hosting.md b/docs/src/man/hosting.md index e9bb4f7c41..eee3a7af6c 100644 --- a/docs/src/man/hosting.md +++ b/docs/src/man/hosting.md @@ -2,10 +2,17 @@ After going through the [Package Guide](@ref) and [Doctests](@ref) page you will need to host the generated documentation somewhere for potential users to read. This guide will -describe how to setup automatic updates for your package docs using the Travis build service +describe how to setup automatic updates for your package docs using CI build services and GitHub Pages. This is the same approach used by this package to host its own docs -- the docs you're currently reading. +!!! warning + + Documenter.jl only supports Travis CI, Gitlab CI, Cirrus CI, Drone CI, and AppVeyor. + + If you want to use another CI service, please either [open an issue](https://github.com/JuliaDocs/Documenter.jl/issues/new) + or set the relevant environment variables yourself. + !!! note Following this guide should be the *final* step you take after you are comfortable with @@ -14,8 +21,8 @@ the docs you're currently reading. documentation locally with Documenter. This guide assumes that you already have [GitHub](https://github.com/) and - [Travis](https://travis-ci.com/) accounts setup. If not then go set those up first and - then return here. + a CI system, like [Travis](https://travis-ci.com/) accounts setup. If not, + then go set those up first and then return here. ## Overview diff --git a/docs/src/man/hosting/walkthrough.md b/docs/src/man/hosting/walkthrough.md index eab7fd69f9..9cab33129b 100644 --- a/docs/src/man/hosting/walkthrough.md +++ b/docs/src/man/hosting/walkthrough.md @@ -130,7 +130,8 @@ to GitHub. The next step is to add the private key to Travis. In this section, we explain how to upload a private SSH key to Travis. By this point, you should have generated a private key and saved it to a file. If you haven't done this, go -read [Generating an SSH Key](@ref). +read [Generating an SSH Key](@ref). If you are using a different CI system, you will need +to do something else - consult your CI system's documentation. First, we need to Base64 encode the private key. Open Julia, and run the command diff --git a/src/CISystems.jl b/src/CISystems.jl new file mode 100644 index 0000000000..94df9d7657 --- /dev/null +++ b/src/CISystems.jl @@ -0,0 +1,136 @@ +""" + enum CI_SYSTEM + +The supported CI systems to deploy docs from, using Documenter.jl. + +Values: +* [`TRAVIS`](@ref) +* [`GITLAB_CI`](@ref) +* [`CIRRUS_CI`](@ref) +* [`DRONE`](@ref) +* [`APPVEYOR`](@ref) +""" +@enum CI_SYSTEM begin + TRAVIS + GITLAB_CI + CIRRUS_CI + DRONE + APPVEYOR +end +# docstrings for CI_SYSTEM values +"Specialize [`deploydocs`](@ref) for [Travis CI](https://travis-ci.org/). See also [`Documenter.CI_SYSTEM`](@ref)." +TRAVIS +"Specialize [`deploydocs`](@ref) for [Appveyor](https://www.appveyor.com/). See also [`Documenter.CI_SYSTEM`](@ref)." +APPVEYOR +"Specialize [`deploydocs`](@ref) for [GitLab CI](https://about.gitlab.com/product/continuous-integration/). See also [`Documenter.CI_SYSTEM`](@ref)." +GITLAB_CI +"Specialize [`deploydocs`](@ref) for [Cirrus CI](https://cirrus-ci.org/). See also [`Documenter.CI_SYSTEM`](@ref)." +CIRRUS_CI +"Specialize [`deploydocs`](@ref) for [Drone](https://drone.io/). See also [`Documenter.CI_SYSTEM`](@ref)." +DRONE + +""" + read_ci_env([returnfinaldeploy::Bool]; uploader::CI_SYSTEM = TRAVIS) + +Read the CI environment variables, and return (always) a NamedTuple where the first +five elements are, in order: + - `cibranch`: which branch is CI running on? + - `pull_request`: is CI building a pull request? Empty string if not. + - `repo_slug`: The URL-friendly repo name. + - `tag`: The tag being built bu CI. Empty string if not. + - `event_type`: The event that triggered CI. +Furthermore, if `returnfinaldeploy` is true, the function will check whether the +current CI provider matches `uploader` (set by default to Travis). + +Returns a NamedTuple. +""" +function read_ci_env(returnfinaldeploy=false; uploader::CI_SYSTEM = TRAVIS) + + arraylength = returnfinaldeploy ? 6 : 5 + + ret = nothing + + if haskey(ENV, "TRAVIS") + + @info "Travis CI detected" + + cibranch = get(ENV, "TRAVIS_BRANCH", "") + pull_request = get(ENV, "TRAVIS_PULL_REQUEST", "") + repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "") + tag = get(ENV, "TRAVIS_TAG", "") + event_type = get(ENV, "TRAVIS_EVENT_TYPE", "") + + ret = (cibranch = cibranch, pull_request = pull_request, repo_slug = repo_slug, tag = tag, event_type = event_type) + + returnfinaldeploy && begin ret = (ret..., uploader = uploader == TRAVIS) end + + elseif haskey(ENV, "GITLAB_CI") + + @info "Gitlab CI detected" + + cibranch = get(ENV, "CI_COMMIT_REF_NAME", "") + pull_request = get(ENV, "CI_MERGE_REQUEST_ID", "false") + repo_slug = get(ENV, "CI_PROJECT_PATH", "") + tag = get(ENV, "CI_COMMIT_TAG", "") + event_type = get(ENV, "CI_PIPELINE_SOURCE", "") + + ret = (cibranch = cibranch, pull_request = pull_request, repo_slug = repo_slug, tag = tag, event_type = event_type) + + returnfinaldeploy && begin ret = (ret..., uploader = uploader == GITLAB_CI) end + + elseif haskey(ENV, "DRONE") + + @info "Drone CI detected" + + cibranch = get(ENV, "DRONE_COMMIT_BRANCH", "") + pull_request = get(ENV, "DRONE_PULL_REQUEST", "false") + repo_slug = get(ENV, "DRONE_REPO_NAMESPACE", "") * "/" * get(ENV, "DRONE_REPO_NAME", "") + tag = get(ENV, "DRONE_TAG", "") + event_type = get(ENV, "DRONE_BUILD_EVENT", "") + + ret = (cibranch = cibranch, pull_request = pull_request, repo_slug = repo_slug, tag = tag, event_type = event_type) + + returnfinaldeploy && begin ret = (ret..., uploader = uploader == DRONE) end + + elseif haskey(ENV, "CIRRUS_CI") + + @info "Cirrus CI detected" + + cibranch = get(ENV, "CIRRUS_BRANCH", "") + pull_request = get(ENV, "CIRRUS_PR", "false") + repo_slug = get(ENV, "CIRRUS_REPO_FULL_NAME", "") + tag = get(ENV, "CIRRUS_TAG", "") + event_type = "unknown" # Cirrus CI doesn't seem to provide the triggering event... + + ret[1:5] .= (cibranch, pull_request, repo_slug, tag, event_type) + + returnfinaldeploy && begin ret[6] = uploader == CIRRUS_CI end + + elseif haskey(ENV, "APPVEYOR") # the worst of them all + + @info "AppVeyor CI detected" + + pull_request = get(ENV, "APPVEYOR_PULL_REQUEST_NUMBER", "false") + cibranch = if haskey(ENV, "APPVEYOR_PULL_REQUEST_NUMBER" ) + ENV["APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"] + else + get(ENV, "APPVEYOR_REPO_BRANCH", "") + end + repo_slug = get(ENV, "APPVEYOR_PROJECT_SLUG", "") + tag = get(ENV, "APPVEYOR_REPO_TAG_NAME", "") + event_type = "unknown" # Appveyor has four env vars for this... + + ret = (cibranch = cibranch, pull_request = pull_request, repo_slug = repo_slug, tag = tag, event_type = event_type) + + returnfinaldeploy && begin ret = (ret..., uploader = uploader == APPVEYOR) end + + else + @warn """ + We don't recognize the CI service you're running, or haven't added support for it. + We currently support Travis CI, Gitlab CI, Drone CI, Cirrus CI and AppVeyor. + """ + ret = (cibranch = nothing, pull_request = nothing, repo_slug = nothing, tag = nothing, event_type = nothing) + returnfinaldeploy && begin ret = (ret..., uploader = uploader == nothing) end + + end +end diff --git a/src/Documenter.jl b/src/Documenter.jl index d347378283..fdd1f9388d 100644 --- a/src/Documenter.jl +++ b/src/Documenter.jl @@ -36,6 +36,7 @@ abstract type Writer end # Submodules # ---------- +include("CISystems.jl") include("Utilities/Utilities.jl") include("DocMeta.jl") include("DocSystem.jl") @@ -57,6 +58,8 @@ import .Writers.HTMLWriter: HTML # --------------- export Deps, makedocs, deploydocs, hide, doctest, DocMeta +export TRAVIS, GITLAB_CI, CIRRUS_CI, DRONE, APPVEYOR + """ makedocs( root = "", @@ -381,7 +384,9 @@ hide(root::AbstractString, children) = (true, nothing, root, map(hide, children) make = nothing | , devbranch = "master", devurl = "dev", - versions = ["stable" => "v^", "v#.#", devurl => devurl] + versions = ["stable" => "v^", "v#.#", devurl => devurl], + uploader = TRAVIS, + tag = "" # or "v*.*" if you want a specific tag ) Converts markdown files generated by [`makedocs`](@ref) to HTML and pushes them to `repo`. @@ -462,12 +467,17 @@ the generated html. The following entries are valied in the `versions` vector: The second argument can be `"v^"`, to point to the maximum version docs (as in e.g. `"stable" => "v^"`). +**uploader** determines _which_ CI service will upload the documentation. Defaults to +Travis ([`TRAVIS`](@ref)). Other options are [`GITLAB_CI`](@ref), [`CIRRUS_CI`](@ref), +[`DRONE`](@ref), and [`APPVEYOR`](@ref). + # Environment variables -[`deploydocs`](@ref)'s behavior is influenced by the following environment variables, many -of which are specific to the [Travis CI platform](https://travis-ci.com/). +- **`DOCUMENTER_KEY`**: must contain the Base64-encoded SSH private key for the repository. - - **`DOCUMENTER_KEY`**: must contain the Base64-encoded SSH private key for the repository. +[`deploydocs`](@ref)'s behavior is influenced by environment variables when in a CI environment. +Please refer to the source to see what these variables are for each system; below is the description +of the Travis CI environment variables that [`deploydocs`](@ref) parses. - **`TRAVIS_PULL_REQUEST`**: must be set to `false`. @@ -495,7 +505,7 @@ of which are specific to the [Travis CI platform](https://travis-ci.com/). version number in `TRAVIS_TAG` instead. The `TRAVIS_*` variables are set automatically on Travis, but could be set manually to -appropriate values as well to run [`deploydocs`](@ref) locally or on other CI platforms. +appropriate values as well to run [`deploydocs`](@ref) locally. More information on how Travis sets the `TRAVIS_*` variables can be found in the [Travis documentation](https://docs.travis-ci.com/user/environment-variables/#default-environment-variables). @@ -524,6 +534,7 @@ function deploydocs(; devurl = "dev", versions = ["stable" => "v^", "v#.#", devurl => devurl], forcepush::Bool = false, + uploader::CI_SYSTEM = TRAVIS ) # deprecation of latest kwarg (renamed to devbranch) if latest !== nothing @@ -534,7 +545,7 @@ function deploydocs(; # deprecation/removal of `julia` and `osname` kwargs if julia !== nothing Base.depwarn("the `julia` keyword argument to `Documenter.deploydocs` is " * - "removed. Use Travis Build Stages for determining from where to deploy instead. " * + "removed. Use CI Build Stages for determining from where to deploy instead. " * "See the section about Hosting in the Documenter manual for more details.", :deploydocs) @info "skipping docs deployment." return @@ -547,13 +558,23 @@ function deploydocs(; return end - # Get environment variables. - documenter_key = get(ENV, "DOCUMENTER_KEY", "") - travis_branch = get(ENV, "TRAVIS_BRANCH", "") - travis_pull_request = get(ENV, "TRAVIS_PULL_REQUEST", "") - travis_repo_slug = get(ENV, "TRAVIS_REPO_SLUG", "") - travis_tag = get(ENV, "TRAVIS_TAG", "") - travis_event_type = get(ENV, "TRAVIS_EVENT_TYPE", "") + local cibranch, pull_request, repo_slug, tag, event_type, finaldeploy + + if haskey(ENV, "CI") + cibranch, pull_request, repo_slug, tag, event_type, finaldeploy = read_ci_env(true, uploader=uploader) + else + # TODO add a better way to manually deploy + @error """ + You seem to be deploying manually, but ENV[\"CI\"] is not set. + Please set the appropriate environment variables before you try to deploy. + These environment variables can be seen in the documentation for `deploydocs`, + which can be accessed by `?deploydocs` in the REPL. + """ + end + + # Get authentication key. + documenter_key = get(ENV, "DOCUMENTER_KEY", "") + # Other variables. @@ -573,30 +594,37 @@ function deploydocs(; end # Check criteria for deployment - ## The deploydocs' repo should match TRAVIS_REPO_SLUG - repo_ok = occursin(travis_repo_slug, repo) + ## The deploydocs' repo should match the repo slug provided by CI + repo_ok = occursin(repo_slug, repo) ## Do not deploy for PRs - pr_ok = travis_pull_request == "false" - ## If a tag exist it should be a valid VersionNumber - tag_ok = isempty(travis_tag) || occursin(Base.VERSION_REGEX, travis_tag) - ## If no tag exists deploydocs' devbranch should match TRAVIS_BRANCH - branch_ok = !isempty(travis_tag) || travis_branch == devbranch + pr_ok = pull_request in ("false", "False") # Appveyor env vars are capitalized on Windows + ## If a tag exists, it should be a valid VersionNumber + tag_ok = isempty(tag) || occursin(Base.VERSION_REGEX, tag) + ## If no tag exists deploydocs' devbranch should match the CI branch + branch_ok = !isempty(tag) || cibranch == devbranch ## DOCUMENTER_KEY should exist key_ok = !isempty(documenter_key) ## Cron jobs should not deploy - type_ok = travis_event_type != "cron" - should_deploy = repo_ok && pr_ok && tag_ok && branch_ok && key_ok && type_ok + type_ok = event_type != "cron" + + should_deploy = repo_ok && pr_ok && tag_ok && branch_ok && key_ok && type_ok && finaldeploy marker(x) = x ? "✔" : "✘" - @info """Deployment criteria: - - $(marker(repo_ok)) ENV["TRAVIS_REPO_SLUG"]="$(travis_repo_slug)" occurs in repo="$(repo)" - - $(marker(pr_ok)) ENV["TRAVIS_PULL_REQUEST"]="$(travis_pull_request)" is "false" - - $(marker(tag_ok)) ENV["TRAVIS_TAG"]="$(travis_tag)" is (i) empty or (ii) a valid VersionNumber - - $(marker(branch_ok)) ENV["TRAVIS_BRANCH"]="$(travis_branch)" matches devbranch="$(devbranch)" (if tag is empty) - - $(marker(key_ok)) ENV["DOCUMENTER_KEY"] exists - - $(marker(type_ok)) ENV["TRAVIS_EVENT_TYPE"]="$(travis_event_type)" is not "cron" - Deploying: $(marker(should_deploy)) - """ + if haskey(ENV, "CI") + @info """ + Deploying on CI. + Deployment criteria: + - $(marker(repo_ok)) CI repo slug = "$(repo_slug)" occurs in repo = "$(repo)" + - $(marker(pr_ok)) CI pull request indicator = "$(pull_request)" is "false" or "False" + - $(marker(tag_ok)) CI tag indicator = "$(tag)" is (i) empty or (ii) a valid VersionNumber + - $(marker(branch_ok)) CI branch = "$(cibranch)" matches devbranch="$(devbranch)" (if tag is empty) + - $(marker(key_ok)) ENV["DOCUMENTER_KEY"] exists + - $(marker(type_ok)) CI event type = "$(event_type)" is not "cron" + - $(marker(finaldeploy)) CI service is $uploader + Deploying: $(marker(should_deploy)) + """ + # TODO add a better way to manually deploy + end if should_deploy # Add local bin path if needed. @@ -620,7 +648,7 @@ function deploydocs(; git_push( root, temp, repo; branch=branch, dirname=dirname, target=target, - tag=travis_tag, key=documenter_key, sha=sha, + tag=tag, key=documenter_key, sha=sha, devurl = devurl, versions = versions, forcepush = forcepush, ) end @@ -667,100 +695,106 @@ function git_push( end chmod(keyfile, 0o600) - try - # Use a custom SSH config file to avoid overwriting the default user config. - withfile(joinpath(homedir(), ".ssh", "config"), - """ - Host $host - StrictHostKeyChecking no - HostName $host - IdentityFile "$keyfile" - BatchMode yes - """ - ) do - cd(temp) do - # Setup git. - run(`git init`) - run(`git config user.name "zeptodoctor"`) - run(`git config user.email "44736852+zeptodoctor@users.noreply.github.com"`) - - # Fetch from remote and checkout the branch. - run(`git remote add upstream $upstream`) - try - run(`git fetch upstream`) - catch e - @error """ - Git failed to fetch $upstream - This can be caused by a DOCUMENTER_KEY variable that is not correctly set up. - Make sure that the environment variable is properly set up as a Base64-encoded string - of the SSH private key. You may need to re-generate the keys with DocumenterTools. - """ - rethrow(e) - end + function _push() + cd(temp) do + # Setup git. + run(`git init`) + run(`git config user.name "zeptodoctor"`) + run(`git config user.email "44736852+zeptodoctor@users.noreply.github.com"`) + + # Fetch from remote and checkout the branch. + run(`git remote add upstream $upstream`) + try + run(`git fetch upstream`) + catch e + @error """ + Git failed to fetch $upstream + This can be caused by a DOCUMENTER_KEY variable that is not correctly set up. + Make sure that the environment variable is properly set up as a Base64-encoded string + of the SSH private key. You may need to re-generate the keys with DocumenterTools. + """ + rethrow(e) + end - try - run(`git checkout -b $branch upstream/$branch`) - catch e - @debug "checking out $branch failed with error: $e" - @debug "creating a new local $branch branch." - run(`git checkout --orphan $branch`) - run(`git commit --allow-empty -m "Initial empty commit for docs"`) - end + try + run(`git checkout -b $branch upstream/$branch`) + catch e + @debug "checking out $branch failed with error: $e" + @debug "creating a new local $branch branch." + run(`git checkout --orphan $branch`) + run(`git commit --allow-empty -m "Initial empty commit for docs"`) + end - # Copy docs to `devurl`, or `stable`, ``, and `` directories. - if isempty(tag) - devurl_dir = joinpath(dirname, devurl) - gitrm_copy(target_dir, devurl_dir) - Writers.HTMLWriter.generate_siteinfo_file(devurl_dir, devurl) - # symlink "latest" to devurl to preserve links (remove in some future release) - if devurl != "latest" - rm(joinpath(dirname, "latest"); recursive = true, force = true) - @warn(string("creating symlink from `latest` to `$(devurl)` for backwards ", - "compatibility with old links. In future Documenter versions this symlink ", - "will not be created. Please update any links that point to `latest`.")) - cd(dirname) do; rm_and_add_symlink(devurl, "latest"); end - end - else - tagged_dir = joinpath(dirname, tag) - gitrm_copy(target_dir, tagged_dir) - Writers.HTMLWriter.generate_siteinfo_file(tagged_dir, tag) + # Copy docs to `devurl`, or `stable`, ``, and `` directories. + if isempty(tag) + devurl_dir = joinpath(dirname, devurl) + gitrm_copy(target_dir, devurl_dir) + Writers.HTMLWriter.generate_siteinfo_file(devurl_dir, devurl) + # symlink "latest" to devurl to preserve links (remove in some future release) + if devurl != "latest" + rm(joinpath(dirname, "latest"); recursive = true, force = true) + @warn(string("creating symlink from `latest` to `$(devurl)` for backwards ", + "compatibility with old links. In future Documenter versions this symlink ", + "will not be created. Please update any links that point to `latest`.")) + cd(dirname) do; rm_and_add_symlink(devurl, "latest"); end end + else + tagged_dir = joinpath(dirname, tag) + gitrm_copy(target_dir, tagged_dir) + Writers.HTMLWriter.generate_siteinfo_file(tagged_dir, tag) + end - # Expand the users `versions` vector - entries, symlinks = Writers.HTMLWriter.expand_versions(dirname, versions) - - # Create the versions.js file containing a list of `entries`. - # This must always happen after the folder copying. - Writers.HTMLWriter.generate_version_file(joinpath(dirname, "versions.js"), entries) - - # generate the symlinks, make sure we don't overwrite devurl - cd(dirname) do - for kv in symlinks - i = findfirst(x -> x.first == devurl, symlinks) - if i === nothing - rm_and_add_symlink(kv.second, kv.first) - else - throw(ArgumentError(string("link `$(kv)` cannot overwrite ", - "`devurl = $(devurl)` with the same name."))) - end - end - end + # Expand the users `versions` vector + entries, symlinks = Writers.HTMLWriter.expand_versions(dirname, versions) - # Add, commit, and push the docs to the remote. - run(`git add -A .`) - if !success(`git diff --cached --exit-code`) - if forcepush - run(`git commit --amend --date=now -m "build based on $sha"`) - run(`git push -fq upstream HEAD:$branch`) + # Create the versions.js file containing a list of `entries`. + # This must always happen after the folder copying. + Writers.HTMLWriter.generate_version_file(joinpath(dirname, "versions.js"), entries) + + # generate the symlinks, make sure we don't overwrite devurl + cd(dirname) do + for kv in symlinks + i = findfirst(x -> x.first == devurl, symlinks) + if i === nothing + rm_and_add_symlink(kv.second, kv.first) else - run(`git commit -m "build based on $sha"`) - run(`git push -q upstream HEAD:$branch`) + throw(ArgumentError(string("link `$(kv)` cannot overwrite ", + "`devurl = $(devurl)` with the same name."))) end + end + end + + # Add, commit, and push the docs to the remote. + run(`git add -A .`) + if !success(`git diff --cached --exit-code`) + if forcepush + run(`git commit --amend --date=now -m "build based on $sha"`) + run(`git push -fq upstream HEAD:$branch`) else - @debug "new docs identical to the old -- not committing nor pushing." + run(`git commit -m "build based on $sha"`) + run(`git push -q upstream HEAD:$branch`) end + else + @debug "new docs identical to the old -- not committing nor pushing." end end + end + + try + # Use a custom SSH config file to avoid overwriting the default user config. + if haskey(ENV, "CI") + withfile(_push, joinpath(homedir(), ".ssh", "config"), + """ + Host $host + StrictHostKeyChecking no + HostName $host + IdentityFile "$keyfile" + BatchMode yes + """ + ) + else + _push() + end finally # Remove the unencrypted private key. isfile(keyfile) && rm(keyfile) diff --git a/src/Writers/LaTeXWriter.jl b/src/Writers/LaTeXWriter.jl index 185e98b2cd..a357def001 100644 --- a/src/Writers/LaTeXWriter.jl +++ b/src/Writers/LaTeXWriter.jl @@ -13,7 +13,7 @@ navigation menu. It goes into the `\\title` LaTeX command. """ module LaTeXWriter -import ...Documenter: Documenter +import ...Documenter: Documenter, read_ci_env """ LaTeXWriter.LaTeX(; kwargs...) @@ -90,8 +90,9 @@ function render(doc::Documents.Document, settings::LaTeX=LaTeX()) cp(joinpath(doc.user.root, doc.user.build), joinpath(path, "build")) cd(joinpath(path, "build")) do name = doc.user.sitename - let tag = get(ENV, "TRAVIS_TAG", "") - if occursin(Base.VERSION_REGEX, tag) + let tag = read_ci_env()[:tag] + + if occursin(Base.VERSION_REGEX, tag === nothing ? "" : tag) v = VersionNumber(tag) name *= "-$(v.major).$(v.minor).$(v.patch)" end @@ -188,6 +189,8 @@ end function writeheader(io::IO, doc::Documents.Document) custom = joinpath(doc.user.root, doc.user.source, "assets", "custom.sty") isfile(custom) ? cp(custom, "custom.sty"; force = true) : touch("custom.sty") + + tag = haskey(ENV, "CI") ? read_ci_env(false)[:tag] : "" preamble = """ \\documentclass{memoir} @@ -197,7 +200,7 @@ function writeheader(io::IO, doc::Documents.Document) \\title{ {\\HUGE $(doc.user.sitename)}\\\\ - {\\Large $(get(ENV, "TRAVIS_TAG", ""))} + {\\Large $tag} } \\author{$(doc.user.authors)}