Build package in a temp directory, refactor code

This commit is contained in:
Chris de Graaf 2017-08-15 18:46:36 -05:00
parent 9824d1a61a
commit a14131ae15
8 changed files with 242 additions and 263 deletions

View File

@ -22,21 +22,19 @@ function generate(
force::Bool=false,
ssh::Bool=false,
)
pkg_name = Pkg.splitjl(pkg_name)
pkg_dir = joinpath(t.path, pkg_name)
pkg_dir = joinpath(t.dir, pkg_name)
temp_pkg_dir = joinpath(t.temp_dir, pkg_name)
if force && ispath(pkg_dir)
rm(pkg_dir; recursive=true)
elseif ispath(pkg_dir)
if !force && ispath(pkg_dir)
throw(ArgumentError(
"A directory already exists at $pkg_dir, use force=true to overwrite it."
"Something already exists at $pkg_dir, use force=true to overwrite it."
))
end
# Initialize the repo and configure it.
repo = LibGit2.init(pkg_dir)
info("Initialized git repo at $pkg_dir")
repo = LibGit2.init(temp_pkg_dir)
info("Initialized git repo at $temp_pkg_dir")
cfg = LibGit2.GitConfig(repo)
info("Configuring git")
for (key, val) in t.git_config
@ -59,124 +57,115 @@ function generate(
LibGit2.branch!(repo, "master")
end
# Generate plugin files and common stuff like tests/entrypoint/readme.
# File generation functions that fail should return nothing.
files = filter(x -> x != nothing, [
gen_license(pkg_dir, t.license, t.authors, t.years),
gen_entrypoint(pkg_dir),
gen_require(pkg_dir, t.julia_version),
gen_tests(pkg_dir),
gen_readme(pkg_dir, t),
gen_gitignore(pkg_dir, t.plugins),
])
for plugin in values(t.plugins)
plugin_files = gen_plugin(plugin, t, pkg_name)
append!(files, plugin_files)
info("Generated files/directories: $(join(plugin_files, ", "))")
end
# Generate the files.
files = vcat(
gen_license(pkg_name, t),
gen_entrypoint(pkg_name, t),
gen_require(temp_pkg_dir, t),
gen_tests(pkg_name, t),
gen_readme(pkg_name, t),
gen_gitignore(pkg_name, t),
vcat(collect(gen_plugin(plugin, t, pkg_name) for plugin in values(t.plugins))...),
)
LibGit2.add!(repo, files...)
info("Staged $(length(files)) files/directories: $(join(files, ", "))")
LibGit2.commit(repo, "Files generated by PkgTemplates")
info("Committed files generated by PkgTemplates")
info("Copying temporary package directory into $(t.dir)")
cp(temp_pkg_dir, pkg_dir; remove_destination=force)
rm(temp_pkg_dir; recursive=true)
info("Finished")
warn("Remember to push all created branches to your remote: git push --all -u")
end
"""
gen_readme(pkg_dir::AbstractString, t::Template) -> String
gen_readme(pkg_name::AbstractString, template::Template) -> Vector{String}
Generate a README with badges for each enabled plugin.
Create a README in the temp package directory with badges for each enabled plugin.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `t::Template`: The template whose README we are generating.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose README we are generating.
Returns the name of the generated file.
Returns an array of generated file/directory names.
"""
function gen_readme(pkg_dir::AbstractString, t::Template)
pkg_name = basename(pkg_dir)
function gen_readme(pkg_name::AbstractString, template::Template)
text = "# $pkg_name\n"
# We want badges to be laid out: docs -> CI -> coverage.
ordering = [GitHubPages, TravisCI, AppVeyor, CodeCov]
for plugin_type in ordering
if haskey(t.plugins, plugin_type)
text *= "\n" * join(badges(t.plugins[plugin_type], t.user, pkg_name), "\n")
if haskey(template.plugins, plugin_type)
text *= "\n"
text *= join(
badges(template.plugins[plugin_type], template.user, pkg_name),
"\n",
)
end
end
gen_file(joinpath(pkg_dir, "README.md"), text)
return "README.md"
gen_file(joinpath(template.temp_dir, pkg_name, "README.md"), text)
return ["README.md"]
end
"""
gen_gitignore(pkg_dir, plugins) -> Union{String,Void}
gen_gitignore(pkg_name::AbstractString, template::Template) -> Vector{String}
Generate a .gitignore from the list of enabled `plugins`.
Create a .gitignore in the temp package directory.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `plugins::Dict{DataType, Plugin}`: The enabled plugins.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose .gitignore we are generating.
Returns the name of the generated file.
Returns an array of generated file/directory names.
"""
function gen_gitignore(pkg_dir::AbstractString, plugins::Dict{DataType,Plugin})
function gen_gitignore(pkg_name::AbstractString, template::Template)
text = ".DS_Store\n"
for plugin in values(plugins)
for plugin in values(template.plugins)
if !isempty(plugin.gitignore_files)
text *= join(plugin.gitignore_files, "\n") * "\n"
end
end
gen_file(joinpath(pkg_dir, ".gitignore"), text)
return ".gitignore"
gen_file(joinpath(template.temp_dir, pkg_name, ".gitignore"), text)
return [".gitignore"]
end
"""
gen_license(pkg_dir, license, authors, years) -> Union{String, Void}
gen_license(pkg_name::AbstractString, template::Template) -> Vector{String}
Creates a license file for the package.
Create a LICENSE in the temp package directory.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `license::Union{AbstractString, Void}`: Name of the license, `nothing` if no license.
* `authors::AbstractString`: Author, or comma-delimited list of authors, of the package.
* `years::AbstractString`: Copyright year or range of copyright years.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose LICENSE we are generating.
Returns the name of the generated file, or `nothing` in the case that
no license is generated.
Returns an array of generated file/directory names.
"""
function gen_license(
pkg_dir::AbstractString,
license::Union{AbstractString, Void},
authors::AbstractString,
years::AbstractString
)
if license == nothing
return nothing
function gen_license(pkg_name::AbstractString, template::Template)
if template.license == nothing
return String[]
end
pkg_name = basename(pkg_dir)
text = "Copyright (c) $years $authors\n" * read_license(license)
text = "Copyright (c) $(template.years) $(template.authors)\n"
text *= read_license(template.license)
gen_file(joinpath(pkg_dir, "LICENSE"), text)
return "LICENSE"
gen_file(joinpath(template.temp_dir, pkg_name, "LICENSE"), text)
return ["LICENSE"]
end
"""
gen_entrypoint(pkg_dir::AbstractString) -> String
gen_entrypoint(pkg_name::AbstractString, template::Template) -> Vector{String}
Creates the module entrypoint ("src/\$pkg_name.jl") in `pkg_dir`.
Create the module entrypoint in the temp package directory.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose entrypoint we are generating.
Returns the name of the generated directory.
Returns an array of generated file/directory names.
"""
function gen_entrypoint(pkg_dir::AbstractString)
pkg_name = basename(pkg_dir)
function gen_entrypoint(pkg_name::AbstractString, template::Template)
text = """
module $pkg_name
@ -185,49 +174,50 @@ function gen_entrypoint(pkg_dir::AbstractString)
end
"""
gen_file(joinpath(pkg_dir, "src", "$pkg_name.jl"), text)
return "src/"
gen_file(joinpath(template.temp_dir, pkg_name, "src", "$pkg_name.jl"), text)
return ["src/"]
end
"""
gen_require(pkg_dir::AbstractString, julia_version::VersionNumber) -> String
gen_require(pkg_name::AbstractString, template::Template) -> Vector{String}
Create the requirements file in the package directory.
Create the REQUIRE file in the temp package directory.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `julia_version::VersionNumber`: The minimum Julia version to support.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose REQUIRE we are generating.
Returns the name of the generated file.
Returns an array of generated file/directory names.
"""
function gen_require(pkg_dir::AbstractString, julia_version::VersionNumber)
text = "julia $(version_floor(julia_version))\n"
function gen_require(pkg_name::AbstractString, template::Template)
text = "julia $(version_floor(template.julia_version))\n"
gen_file(joinpath(pkg_dir, "REQUIRE"), text)
return "REQUIRE"
gen_file(joinpath(template.temp_dir, pkg_name, "REQUIRE"), text)
return ["REQUIRE"]
end
"""
gen_tests(pkg_dir::AbstractString) -> String
gen_tests(pkg_name::AbstractString, template::Template) -> Vector{String}
Creates the test file "test/runtests.jl" in the package directory.
Create the test directory and entrypoint in the temp package directory.
# Arguments
* `pkg_dir::AbstractString`: The package directory.
* `pkg_name::AbstractString`: Name of the package.
* `template::Template`: The template whose tests we are generating.
Returns the name of the generated directory.
Returns an array of generated file/directory names.
"""
function gen_tests(pkg_dir::AbstractString)
function gen_tests(pkg_name::AbstractString, template::Template)
text = """
using $(basename(pkg_dir))
using $pkg_name
using Base.Test
# Write your own tests here.
@test 1 == 2
"""
gen_file(joinpath(pkg_dir, "test", "runtests.jl"), text)
return "test/"
gen_file(joinpath(template.temp_dir, pkg_name, "test", "runtests.jl"), text)
return ["test/"]
end
"""

View File

@ -52,14 +52,13 @@ Generate a .appveyor.yml.
* `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files.
Returns an array of generated file/directory names.
"""
function gen_plugin(plugin::AppVeyor, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".appveyor.yml"), text)
gen_file(joinpath(template.temp_dir, pkg_name, ".appveyor.yml"), text)
return [".appveyor.yml"]
end

View File

@ -25,7 +25,7 @@ Add CodeCov to a template's plugins to enable CodeCov coverage reports.
end
"""
badges(\_::CodeCov, pkg_name::AbstractString, t::Template) -> Vector{String}
badges(\_::CodeCov, user::AbstractString, pkg_name::AbstractString) -> Vector{String}
Generate Markdown badges for the current package.
@ -52,14 +52,13 @@ Generate a .codecov.yml.
* `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files.
Returns an array of generated file/directory names.
"""
function gen_plugin(plugin::CodeCov, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".codecov.yml"), text)
gen_file(joinpath(template.temp_dir, pkg_name, ".codecov.yml"), text)
return [".codecov.yml"]
end

View File

@ -19,7 +19,7 @@ function gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractSt
info("Adding Documenter.jl")
Pkg.add("Documenter")
end
path = joinpath(template.path, pkg_name)
path = joinpath(template.temp_dir, pkg_name)
docs_dir = joinpath(path, "docs", "src")
mkpath(docs_dir)
if !isempty(plugin.assets)
@ -62,11 +62,7 @@ function gen_plugin(plugin::Documenter, template::Template, pkg_name::AbstractSt
open(joinpath(docs_dir, "index.md"), "w") do fp
write(fp, "# $pkg_name")
end
readme_path = ""
try
readme_path = joinpath(template.path, pkg_name, "README.md")
catch
end
readme_path = joinpath(template.temp_dir, pkg_name, "README.md")
if isfile(readme_path)
cp(readme_path, joinpath(docs_dir, "index.md"), remove_destination=true)
end

View File

@ -51,7 +51,7 @@ to GitHub Pages.
* `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated directories.
Returns an array of generated file/directory names.
"""
function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractString)
invoke(
@ -59,7 +59,7 @@ function gen_plugin(plugin::GitHubPages, template::Template, pkg_name::AbstractS
plugin, template, pkg_name
)
if haskey(template.plugins, TravisCI)
docs_src = joinpath(template.path, pkg_name, "docs", "src")
docs_src = joinpath(template.temp_dir, pkg_name, "docs", "src")
open(joinpath(dirname(docs_src), "make.jl"), "a") do file
write(
file,

View File

@ -52,14 +52,13 @@ Generate a .travis.yml.
* `template::Template`: Template configuration and plugins.
* `pkg_name::AbstractString`: Name of the package.
Returns an array of generated files.
Returns an array of generated file/directory names.
"""
function gen_plugin(plugin::TravisCI, template::Template, pkg_name::AbstractString)
if plugin.config_file == nothing
return String[]
end
text = substitute(readstring(plugin.config_file), pkg_name, template)
pkg_dir = joinpath(template.path, pkg_name)
gen_file(joinpath(pkg_dir, ".travis.yml"), text)
gen_file(joinpath(template.temp_dir, pkg_name, ".travis.yml"), text)
return [".travis.yml"]
end

View File

@ -16,7 +16,7 @@ Records common information used to generate a package.
appear on the license. Supply a string for one author, and an array for multiple.
* `years::Union{Int, AbstractString}=string(Dates.year(Dates.today()))`: Copyright years
on the license. Can be supplied by a number, or a string such as "2016 - 2017".
* `path::AbstractString=Pkg.dir()`: Directory in which the package will go.
* `dir::AbstractString=Pkg.dir()`: Directory in which the package will go.
* `julia_version::VersionNumber=VERSION`: Minimum allowed Julia version.
* `git_config::Dict{String, String}=Dict{String, String}()`: Git configuration options.
* `plugins::Vector{Plugin}`: A list of `Plugin`s that the package will include.
@ -27,7 +27,8 @@ Records common information used to generate a package.
license::Union{AbstractString, Void}
authors::Union{AbstractString, Array}
years::AbstractString
path::AbstractString
dir::AbstractString
temp_dir::AbstractString
julia_version::VersionNumber
git_config::Dict{String, String}
plugins::Dict{DataType, Plugin}
@ -38,7 +39,7 @@ Records common information used to generate a package.
license::Union{AbstractString, Void}=nothing,
authors::Union{AbstractString, Array}=LibGit2.getconfig("user.name", ""),
years::Union{Int, AbstractString}=string(Dates.year(Dates.today())),
path::AbstractString=Pkg.dir(),
dir::AbstractString=Pkg.dir(),
julia_version::VersionNumber=VERSION,
git_config::Dict{String, String}=Dict{String, String}(),
plugins::Vector{P}=Vector{Plugin}(),
@ -67,13 +68,15 @@ Records common information used to generate a package.
years = string(years)
temp_dir = mktempdir()
plugin_dict = Dict{DataType, Plugin}(typeof(p) => p for p in plugins)
if (length(plugins) != length(plugin_dict))
warn("Plugin list contained duplicates, only the last of each type was kept")
end
new(
user, host, license, authors, years, path,
user, host, license, authors, years, dir, temp_dir,
julia_version, git_config, plugin_dict
)
end

View File

@ -3,8 +3,8 @@ const git_config = Dict(
"user.email" => "email@web.site",
"github.username" => "TesterMcTestFace",
)
const fake_path = joinpath(tempdir(), tempdir())
const test_pkg = "TestPkg"
const fake_path = bin(hash("/this/file/does/not/exist"))
const test_file = tempname()
template_text = """
PKGNAME: {{PKGNAME}}
@ -22,7 +22,7 @@ write(test_file, template_text)
@test t.license == nothing
@test t.years == string(Dates.year(Dates.today()))
@test t.authors == LibGit2.getconfig("user.name", "")
@test t.path == Pkg.dir()
@test t.dir == Pkg.dir()
@test t.julia_version == VERSION
@test isempty(t.git_config)
@test isempty(t.plugins)
@ -40,8 +40,8 @@ write(test_file, template_text)
t = Template(; user="invenia", authors=["Guy", "Gal"])
@test t.authors == "Guy, Gal"
t = Template(; user="invenia", path=test_file)
@test t.path == test_file
t = Template(; user="invenia", dir=test_file)
@test t.dir == test_file
t = Template(; user="invenia", julia_version=v"0.1.2")
@test t.julia_version == v"0.1.2"
@ -106,6 +106,7 @@ end
git_config=git_config,
plugins=[TravisCI(), CodeCov(), GitHubPages(), AppVeyor()],
)
pkg_dir = joinpath(t.temp_dir, test_pkg)
temp_file = tempname()
gen_file(temp_file, "Hello, world")
@ -113,79 +114,73 @@ end
@test readstring(temp_file) == "Hello, world\n"
rm(temp_file)
mktempdir() do temp_dir
@test gen_readme(temp_dir, t) == "README.md"
@test isfile(joinpath(temp_dir, "README.md"))
readme = readchomp(joinpath(temp_dir, "README.md"))
@test contains(readme, "# $(basename(temp_dir))")
@test gen_readme(test_pkg, t) == ["README.md"]
@test isfile(joinpath(pkg_dir, "README.md"))
readme = readchomp(joinpath(pkg_dir, "README.md"))
rm(joinpath(pkg_dir, "README.md"))
@test contains(readme, "# $test_pkg")
for p in values(t.plugins)
@test contains(readme, join(badges(p, t.user, basename(temp_dir)), "\n"))
@test contains(readme, join(badges(p, t.user, test_pkg), "\n"))
end
# Check the order of the badges.
@test search(readme, "github.io").start <
search(readme, "travis").start <
search(readme, "appveyor").start <
search(readme, "codecov").start
end
mktempdir() do temp_dir
@test gen_gitignore(temp_dir, t.plugins) == ".gitignore"
@test isfile(joinpath(temp_dir, ".gitignore"))
gitignore = readstring(joinpath(temp_dir, ".gitignore"))
@test gen_gitignore(test_pkg, t) == [".gitignore"]
@test isfile(joinpath(pkg_dir, ".gitignore"))
gitignore = readstring(joinpath(pkg_dir, ".gitignore"))
rm(joinpath(pkg_dir, ".gitignore"))
@test contains(gitignore, ".DS_Store")
for p in values(t.plugins)
for entry in p.gitignore_files
@test contains(gitignore, entry)
end
end
end
mktempdir() do temp_dir
@test gen_license(temp_dir, t.license, t.authors, t.years) == "LICENSE"
@test isfile(joinpath(temp_dir, "LICENSE"))
license = readchomp(joinpath(temp_dir, "LICENSE"))
@test gen_license(test_pkg, t) == ["LICENSE"]
@test isfile(joinpath(pkg_dir, "LICENSE"))
license = readchomp(joinpath(pkg_dir, "LICENSE"))
rm(joinpath(pkg_dir, "LICENSE"))
@test contains(license, t.authors)
@test contains(license, t.years)
@test contains(license, read_license(t.license))
end
mktempdir() do temp_dir
@test gen_entrypoint(temp_dir) == "src/"
@test isdir(joinpath(temp_dir, "src"))
@test isfile(joinpath(temp_dir, "src", "$(basename(temp_dir)).jl"))
entrypoint = readchomp(joinpath(temp_dir, "src", "$(basename(temp_dir)).jl"))
@test contains(entrypoint, "module $(basename(temp_dir))")
end
@test gen_entrypoint(test_pkg, t) == ["src/"]
@test isdir(joinpath(pkg_dir, "src"))
@test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl"))
entrypoint = readchomp(joinpath(pkg_dir, "src", "$test_pkg.jl"))
rm(joinpath(pkg_dir, "src"); recursive=true)
@test contains(entrypoint, "module $test_pkg")
mktempdir() do temp_dir
@test gen_require(temp_dir, t.julia_version) == "REQUIRE"
@test isfile(joinpath(temp_dir, "REQUIRE"))
@test gen_require(test_pkg, t) == ["REQUIRE"]
@test isfile(joinpath(pkg_dir, "REQUIRE"))
vf = version_floor(t.julia_version)
@test readchomp(joinpath(temp_dir, "REQUIRE")) == "julia $vf"
end
@test readchomp(joinpath(pkg_dir, "REQUIRE")) == "julia $vf"
rm(joinpath(pkg_dir, "REQUIRE"))
mktempdir() do temp_dir
@test gen_tests(temp_dir) == "test/"
@test isdir(joinpath(temp_dir, "test"))
@test isfile(joinpath(temp_dir, "test", "runtests.jl"))
runtests = readchomp(joinpath(temp_dir, "test", "runtests.jl"))
@test contains(runtests, "using $(basename(temp_dir))")
@test gen_tests(test_pkg, t) == ["test/"]
@test isdir(joinpath(pkg_dir, "test"))
@test isfile(joinpath(pkg_dir, "test", "runtests.jl"))
runtests = readchomp(joinpath(pkg_dir, "test", "runtests.jl"))
rm(joinpath(pkg_dir, "test"); recursive=true)
@test contains(runtests, "using $test_pkg")
@test contains(runtests, "using Base.Test")
end
end
@testset "Package generation" begin
t = Template(; user="invenia")
generate("TestPkg", t)
@test !isfile(Pkg.dir("TestPkg", "LICENSE"))
@test isfile(Pkg.dir("TestPkg", "README.md"))
@test isfile(Pkg.dir("TestPkg", "REQUIRE"))
@test isfile(Pkg.dir("TestPkg", ".gitignore"))
@test isdir(Pkg.dir("TestPkg", "src"))
@test isfile(Pkg.dir("TestPkg", "src", "TestPkg.jl"))
@test isdir(Pkg.dir("TestPkg", "test"))
@test isfile(Pkg.dir("TestPkg", "test", "runtests.jl"))
repo = LibGit2.GitRepo(Pkg.dir("TestPkg"))
generate(test_pkg, t)
@test !isfile(Pkg.dir(test_pkg, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, "README.md"))
@test isfile(Pkg.dir(test_pkg, "REQUIRE"))
@test isfile(Pkg.dir(test_pkg, ".gitignore"))
@test isdir(Pkg.dir(test_pkg, "src"))
@test isfile(Pkg.dir(test_pkg, "src", "TestPkg.jl"))
@test isdir(Pkg.dir(test_pkg, "test"))
@test isfile(Pkg.dir(test_pkg, "test", "runtests.jl"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
@test LibGit2.getconfig(repo, "user.name", "") == LibGit2.getconfig("user.name", "")
@ -193,20 +188,20 @@ end
@test in("master", branches)
@test !in("gh-pages", branches)
@test !LibGit2.isdirty(repo)
rm(Pkg.dir("TestPkg"); recursive=true)
rm(Pkg.dir(test_pkg); recursive=true)
generate("TestPkg", t; ssh=true)
repo = LibGit2.GitRepo(Pkg.dir("TestPkg"))
generate(test_pkg, t; ssh=true)
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
@test LibGit2.url(remote) == "git@github.com:invenia/TestPkg.jl.git"
rm(Pkg.dir("TestPkg"); recursive=true)
rm(Pkg.dir(test_pkg); recursive=true)
t = Template(; user="invenia", host="gitlab.com")
generate("TestPkg", t)
repo = LibGit2.GitRepo(Pkg.dir("TestPkg"))
generate(test_pkg, t)
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
remote = LibGit2.get(LibGit2.GitRemote, repo, "origin")
@test LibGit2.url(remote) == "https://gitlab.com/invenia/TestPkg.jl"
rm(Pkg.dir("TestPkg"); recursive=true)
rm(Pkg.dir(test_pkg); recursive=true)
t = Template(;
user="invenia",
@ -215,62 +210,61 @@ end
plugins=[AppVeyor(), GitHubPages(), CodeCov(), TravisCI()],
)
generate("TestPkg", t)
@test isfile(Pkg.dir("TestPkg", "LICENSE"))
@test isfile(Pkg.dir("TestPkg", ".travis.yml"))
@test isfile(Pkg.dir("TestPkg", ".appveyor.yml"))
@test isfile(Pkg.dir("TestPkg", ".codecov.yml"))
@test isdir(Pkg.dir("TestPkg", "docs"))
@test isfile(Pkg.dir("TestPkg", "docs", "make.jl"))
@test isdir(Pkg.dir("TestPkg", "docs", "src"))
@test isfile(Pkg.dir("TestPkg", "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir("TestPkg"))
generate(test_pkg, t)
@test isfile(Pkg.dir(test_pkg, "LICENSE"))
@test isfile(Pkg.dir(test_pkg, ".travis.yml"))
@test isfile(Pkg.dir(test_pkg, ".appveyor.yml"))
@test isfile(Pkg.dir(test_pkg, ".codecov.yml"))
@test isdir(Pkg.dir(test_pkg, "docs"))
@test isfile(Pkg.dir(test_pkg, "docs", "make.jl"))
@test isdir(Pkg.dir(test_pkg, "docs", "src"))
@test isfile(Pkg.dir(test_pkg, "docs", "src", "index.md"))
repo = LibGit2.GitRepo(Pkg.dir(test_pkg))
@test LibGit2.getconfig(repo, "user.name", "") == git_config["user.name"]
branches = [LibGit2.shortname(branch[1]) for branch in LibGit2.GitBranchIter(repo)]
@test in("gh-pages", branches)
@test !LibGit2.isdirty(repo)
rm(Pkg.dir("TestPkg"); recursive=true)
rm(Pkg.dir(test_pkg); recursive=true)
mkdir(Pkg.dir("TestPkg"))
@test_throws ArgumentError generate("TestPkg", t)
generate("TestPkg", t; force=true)
@test isfile(Pkg.dir("TestPkg", "README.md"))
mkdir(Pkg.dir(test_pkg))
@test_throws ArgumentError generate(test_pkg, t)
generate(test_pkg, t; force=true)
@test isfile(Pkg.dir(test_pkg, "README.md"))
end
@testset "Plugin generation" begin
mktempdir() do temp_dir
pkg_dir = joinpath(temp_dir, "TestPkg")
t = Template(; user="invenia", path=temp_dir)
t = Template(; user="invenia")
pkg_dir = joinpath(t.temp_dir, test_pkg)
p = TravisCI()
@test gen_plugin(p, t, "TestPkg") == [".travis.yml"]
@test gen_plugin(p, t, test_pkg) == [".travis.yml"]
@test isfile(joinpath(pkg_dir, ".travis.yml"))
rm(joinpath(pkg_dir, ".travis.yml"))
p = TravisCI(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".travis.yml"))
@test_throws ArgumentError TravisCI(; config_file=fake_path)
p = AppVeyor()
@test gen_plugin(p, t, "TestPkg") == [".appveyor.yml"]
@test gen_plugin(p, t, test_pkg) == [".appveyor.yml"]
@test isfile(joinpath(pkg_dir, ".appveyor.yml"))
rm(joinpath(pkg_dir, ".appveyor.yml"))
p = AppVeyor(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".appveyor.yml"))
@test_throws ArgumentError AppVeyor(; config_file=fake_path)
p = CodeCov()
@test gen_plugin(p, t, "TestPkg") == [".codecov.yml"]
@test gen_plugin(p, t, test_pkg) == [".codecov.yml"]
@test isfile(joinpath(pkg_dir, ".codecov.yml"))
rm(joinpath(pkg_dir, ".codecov.yml"))
p = CodeCov(; config_file=nothing)
@test isempty(gen_plugin(p, t, "TestPkg"))
@test isempty(gen_plugin(p, t, test_pkg))
@test !isfile(joinpath(pkg_dir, ".codecov.yml"))
@test_throws ArgumentError CodeCov(; config_file=fake_path)
p = GitHubPages()
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
@test gen_plugin(p, t, test_pkg) == ["docs/"]
@test isdir(joinpath(pkg_dir, "docs"))
@test isfile(joinpath(pkg_dir, "docs", "make.jl"))
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@ -282,7 +276,7 @@ end
@test index == "# TestPkg"
rm(joinpath(pkg_dir, "docs"); recursive=true)
p = GitHubPages(; assets=[test_file])
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
@test gen_plugin(p, t, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(
make,
@ -295,12 +289,11 @@ end
@test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file)))
rm(joinpath(pkg_dir, "docs"); recursive=true)
t.plugins[TravisCI] = TravisCI()
@test gen_plugin(p, t, "TestPkg") == ["docs/"]
@test gen_plugin(p, t, test_pkg) == ["docs/"]
make = readchomp(joinpath(pkg_dir, "docs", "make.jl"))
@test contains(make, "deploydocs")
rm(joinpath(pkg_dir, "docs"); recursive=true)
@test_throws ArgumentError GitHubPages(; assets=[fake_path])
end
end
@testset "Version floor" begin
@ -314,7 +307,7 @@ end
t = Template(; user="invenia")
view = Dict{String, Any}("OTHER" => false)
text = substitute(template_text, "TestPkg", t; view=view)
text = substitute(template_text, test_pkg, t; view=view)
@test contains(text, "PKGNAME: TestPkg")
@test contains(text, "VERSION: $(t.julia_version.major).$(t.julia_version.minor)")
@test !contains(text, "Documenter")
@ -322,19 +315,19 @@ end
@test !contains(text, "Other")
t.plugins[GitHubPages] = GitHubPages()
text = substitute(template_text, "TestPkg", t; view=view)
text = substitute(template_text, test_pkg, t; view=view)
@test contains(text, "Documenter")
@test contains(text, "After")
empty!(t.plugins)
t.plugins[CodeCov] = CodeCov()
text = substitute(template_text, "TestPkg", t; view=view)
text = substitute(template_text, test_pkg, t; view=view)
@test contains(text, "CodeCov")
@test contains(text, "After")
empty!(t.plugins)
view["OTHER"] = true
text = substitute(template_text, "TestPkg", t; view=view)
text = substitute(template_text, test_pkg, t; view=view)
@test contains(text, "Other")
end