PkgTemplates.jl/src/plugins/ci.jl

168 lines
5.2 KiB
Julia
Raw Normal View History

const VersionsOrStrings = Vector{Union{VersionNumber, String}}
2019-08-31 10:33:33 +00:00
const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs.
const DEFAULT_CI_VERSIONS = VersionsOrStrings([VERSION, default_version(), "nightly"])
format_version(v::VersionNumber) = "$(v.major).$(v.minor)"
2019-08-29 16:04:11 +00:00
format_version(v::AbstractString) = string(v)
2019-08-29 16:04:11 +00:00
function collect_versions(t::Template, versions::Vector)
2019-08-31 10:33:33 +00:00
vs = map(format_version, [t.julia_version, versions...])
return unique(sort(vs))
end
2019-08-29 16:04:11 +00:00
@with_kw struct TravisCI <: BasicPlugin
file::String = default_file("travis.yml")
linux::Bool = true
osx::Bool = true
windows::Bool = true
x86::Bool = false
coverage::Bool = true
extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS
end
source(p::TravisCI) = p.file
destination(::TravisCI) = ".travis.yml"
badges(::TravisCI) = Badge(
"Build Status",
"https://travis-ci.com/{{USER}}/{{PKG}}.jl.svg?branch=master",
"https://travis-ci.com/{{USER}}/{{PKG}}.jl",
)
function view(p::TravisCI, t::Template, pkg::AbstractString)
2019-08-27 05:43:10 +00:00
os = String[]
p.linux && push!(os, "linux")
p.osx && push!(os, "osx")
p.windows && push!(os, "windows")
2019-08-29 16:04:11 +00:00
versions = collect_versions(t, p.extra_versions)
allow_failures = filter(in(versions), ALLOWED_FAILURES)
2019-08-27 05:43:10 +00:00
x86 = Dict{String, String}[]
if p.x86
foreach(versions) do v
2019-08-31 10:33:33 +00:00
p.linux && push!(x86, Dict("JULIA" => v, "OS" => "linux"))
p.windows && push!(x86, Dict("JULIA" => v, "OS" => "windows"))
end
end
2019-08-27 05:43:10 +00:00
return Dict(
2019-08-27 05:43:10 +00:00
"ALLOW_FAILURES" => allow_failures,
"HAS_ALLOW_FAILURES" => !isempty(allow_failures),
"HAS_CODECOV" => hasplugin(t, Codecov),
2019-08-29 16:04:11 +00:00
"HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage),
"HAS_COVERALLS" => hasplugin(t, Coveralls),
"HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}),
2019-08-27 05:43:10 +00:00
"HAS_JOBS" => p.x86 || hasplugin(t, Documenter{TravisCI}),
"OS" => os,
"PKG" => pkg,
2019-08-29 16:04:11 +00:00
"USER" => t.user,
"VERSION" => format_version(t.julia_version),
2019-08-29 16:04:11 +00:00
"VERSIONS" => versions,
2019-08-27 05:43:10 +00:00
"X86" => x86,
)
end
2019-08-29 16:04:11 +00:00
@with_kw struct AppVeyor <: BasicPlugin
file::String = default_file("appveyor.yml")
x86::Bool = false
coverage::Bool = true
extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS
end
source(p::AppVeyor) = p.file
destination(::AppVeyor) = ".appveyor.yml"
badges(::AppVeyor) = Badge(
"Build Status",
"https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKG}}.jl?svg=true",
"https://ci.appveyor.com/project/{{USER}}/{{PKG}}-jl",
)
2019-08-29 16:04:11 +00:00
function view(p::AppVeyor, t::Template, pkg::AbstractString)
platforms = ["x64"]
2019-08-29 16:04:11 +00:00
p.x86 && push!(platforms, "x86")
versions = collect_versions(t, p.extra_versions)
allow_failures = filter(in(versions), ALLOWED_FAILURES)
return Dict(
2019-08-29 16:04:11 +00:00
"ALLOW_FAILURES" => allow_failures,
"HAS_ALLOW_FAILURES" => !isempty(allow_failures),
"HAS_CODECOV" => p.coverage && hasplugin(t, Codecov),
"PKG" => pkg,
2019-08-29 16:04:11 +00:00
"PLATFORMS" => platforms,
"USER" => t.user,
"VERSIONS" => versions,
)
end
2019-08-29 16:04:11 +00:00
@with_kw struct CirrusCI <: BasicPlugin
file::String = default_file("cirrus.yml")
image::String = "freebsd-12-0-release-amd64"
coverage::Bool = true
extra_versions::VersionsOrStrings = DEFAULT_CI_VERSIONS
end
source(p::CirrusCI) = p.file
destination(::CirrusCI) = ".cirrus.yml"
badges(::CirrusCI) = Badge(
"Build Status",
"https://api.cirrus-ci.com/github/{{USER}}/{{PACKAGE}}.jl.svg",
"https://cirrus-ci.com/github/{{USER}}/{{PKG}}.jl",
)
2019-08-31 11:45:41 +00:00
function view(p::CirrusCI, t::Template, pkg::AbstractString)
return Dict(
"HAS_CODECOV" => hasplugin(t, Codecov),
"HAS_COVERALLS" => hasplugin(t, Coveralls),
2019-08-29 16:04:11 +00:00
"HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage),
"IMAGE" => p.image,
"PKG" => pkg,
2019-08-29 16:04:11 +00:00
"USER" => t.user,
"VERSIONS" => collect_versions(t, p.extra_versions),
)
end
2019-08-29 16:04:11 +00:00
@with_kw struct GitLabCI <: BasicPlugin
2019-08-31 10:33:33 +00:00
file::String = default_file("gitlab-ci.yml")
documentation::Bool = true
coverage::Bool = true
2019-08-31 10:33:33 +00:00
extra_versions::VersionsOrStrings = ["1.0"] # Nightly has no Docker image.
end
gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[]
2019-08-31 11:45:41 +00:00
source(p::GitLabCI) = p.file
destination(::GitLabCI) = ".gitlab-ci.yml"
function badges(p::GitLabCI)
ci = Badge(
"Build Status",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/build.svg",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/pipelines",
)
cov = Badge(
"Coverage",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/badges/master/coverage.svg",
"https://gitlab.com/{{USER}}/{{PKG}}.jl/commits/master",
)
return p.coverage ? [ci, cov] : [ci]
end
2019-08-31 11:45:41 +00:00
function view(p::GitLabCI, t::Template, pkg::AbstractString)
return Dict(
"HAS_COVERAGE" => p.coverage,
"HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}),
"PKG" => pkg,
2019-08-29 16:04:11 +00:00
"USER" => t.user,
"VERSION" => format_version(t.julia_version),
2019-08-29 16:04:11 +00:00
"VERSIONS" => collect_versions(t, p.extra_versions),
)
end
2019-08-29 16:04:11 +00:00
is_ci(::Type) = false
is_ci(::Type{<:Union{AppVeyor, TravisCI, CirrusCI, GitLabCI}}) = true