Skip to content

Commit

Permalink
Run ssh-keygen in a temporary directory (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenpi authored Sep 14, 2022
1 parent da698c1 commit 3937ab5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# DocumenterTools.jl changelog

## Version `v0.1.16`

* ![Bugfix][badge-bugfix] DocumenterTools now runs `ssh-keygen` in a temporary directory (rather than current working directory), avoiding issues with filesystem permissions or existing files. ([#64][github-64], [#65][github-65])

## Version `v0.1.15`

* Declare compatibility with DocStringExtensions 0.9. ([#59][github-59])
Expand Down Expand Up @@ -91,6 +95,8 @@ Maintenance release declaring compatibility with Documenter 0.25. ([#39][github-
[github-54]: https://github.com/JuliaDocs/DocumenterTools.jl/pull/54
[github-55]: https://github.com/JuliaDocs/DocumenterTools.jl/pull/55
[github-56]: https://github.com/JuliaDocs/DocumenterTools.jl/pull/56
[github-64]: https://github.com/JuliaDocs/DocumenterTools.jl/issues/64
[github-65]: https://github.com/JuliaDocs/DocumenterTools.jl/pull/65


[badge-breaking]: https://img.shields.io/badge/BREAKING-red.svg
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DocumenterTools"
uuid = "35a29f4d-8980-5a13-9543-d66fff28ecb8"
version = "0.1.15"
version = "0.1.16"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
63 changes: 41 additions & 22 deletions src/genkeys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,47 @@ function genkeys(; user="\$USER", repo="\$REPO")
isfile("$(filename).pub") && error("temporary file '$(filename).pub' already exists in working directory")

# Generate the ssh key pair.
success(`$(sshkeygen) -N "" -C Documenter -m PEM -f $filename`) || error("failed to generate a SSH key pair.")

# Prompt user to add public key to github then remove the public key.
let url = "https://github.com/$user/$repo/settings/keys"
@info """
add the public key below to $url with read and write access
the title can be left empty as GitHub can infer it from the key comment
"""
println("\n", read("$filename.pub", String))
rm("$filename.pub")
end

# Base64 encode the private key and prompt user to add it to travis. The key is
# *not* encoded for the sake of security, but instead to make it easier to
# copy/paste it over to travis without having to worry about whitespace.
let travis_url = "https://travis-ci.com/$user/$repo/settings",
github_url = "https://github.com/$user/$repo/settings/secrets"
@info("add a secure environment variable named 'DOCUMENTER_KEY' to " *
"$(travis_url) (if you deploy using Travis CI) or " *
"$(github_url) (if you deploy using GitHub Actions) with value:")
println("\n", base64encode(read(filename, String)), "\n")
rm(filename)
mktempdir() do path
cd(path) do
cmd = `$(sshkeygen) -N "" -C Documenter -m PEM -f $filename`
out, err = IOBuffer(), IOBuffer()
try
run(pipeline(cmd, stdout=out, stderr=err))

# Prompt user to add public key to github then remove the public key.
let url = "https://github.com/$user/$repo/settings/keys"
@info """
add the public key below to $url with read and write access
the title can be left empty as GitHub can infer it from the key comment
"""
println("\n", read("$filename.pub", String))
end

# Base64 encode the private key and prompt user to add it to travis. The key is
# *not* encoded for the sake of security, but instead to make it easier to
# copy/paste it over to travis without having to worry about whitespace.
let travis_url = "https://travis-ci.com/$user/$repo/settings",
github_url = "https://github.com/$user/$repo/settings/secrets"
@info("add a secure environment variable named 'DOCUMENTER_KEY' to " *
"$(travis_url) (if you deploy using Travis CI) or " *
"$(github_url) (if you deploy using GitHub Actions) with value:")
println("\n", base64encode(read(filename, String)), "\n")
end
catch e
@error """
Failed to generate a SSH key pair.
> stdout from ssh-keygen:
$(String(take!(out)))
> stderr from ssh-keygen:
$(String(take!(err)))
""" isfile(filename) isfile("$(filename).pub") exception = (e, catch_backtrace())
rethrow(e)
finally
# mktempdir() should clean up the the files, but just in case..
rm(filename, force=true)
rm("$(filename).pub", force=true)
end
end
end
end

Expand Down

2 comments on commit 3937ab5

@mortenpi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Bugfix release. The changes are documented in the CHANGELOG.md file.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/68240

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.16 -m "<description of version>" 3937ab51d9dbc73da9788b695216307c1b6df32a
git push origin v0.1.16

Please sign in to comment.