diff --git a/README.md b/README.md index d2c04c3..5232e88 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://invenia.github.io/PkgTemplates.jl/dev) [![Build Status](https://travis-ci.org/invenia/PkgTemplates.jl.svg?branch=master)](https://travis-ci.org/invenia/PkgTemplates.jl) [![Codecov](https://codecov.io/gh/invenia/PkgTemplates.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/invenia/PkgTemplates.jl) +[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle) **PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index 9afc667..2f22247 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -18,6 +18,7 @@ export AppVeyor, CirrusCI, Citation, + DroneCI, Codecov, Coveralls, Develop, diff --git a/src/plugins/droneci.jl b/src/plugins/droneci.jl new file mode 100644 index 0000000..5ce2027 --- /dev/null +++ b/src/plugins/droneci.jl @@ -0,0 +1,45 @@ +""" + DroneCI(; config_file::Union{AbstractString, Nothing}="") -> DroneCI + +Add `DroneCI` to a template's plugins to add a `.drone.yml` configuration file to +generated repositories, and an appropriate badge to the README. The default configuration +file supports Linux on ARM32 and ARM64. + +# Keyword Arguments +* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.drone.yml`. + If `nothing` is supplied, no file will be generated. +""" +struct DroneCI <: GenericPlugin + gitignore::Vector{String} + src::Union{String, Nothing} + dest::String + badges::Vector{Badge} + view::Dict{String, Any} + + function DroneCI(; config_file::Union{AbstractString, Nothing}="") + if config_file !== nothing + config_file = if isempty(config_file) + joinpath(DEFAULTS_DIR, "drone.yml") + elseif isfile(config_file) + abspath(config_file) + else + throw(ArgumentError("File $(abspath(config_file)) does not exist")) + end + end + return new( + [], + config_file, + ".drone.yml", + [ + Badge( + "Build Status", + "https://cloud.drone.io/api/badges/{{USER}}/{{PKGNAME}}.jl/status.svg", + "https://cloud.drone.io/{{USER}}/{{PKGNAME}}.jl", + ), + ], + Dict{String, Any}(), + ) + end +end + +interactive(::Type{DroneCI}) = interactive(DroneCI; file="drone.yml") diff --git a/test/fixtures/AllPlugins/drone.yml b/test/fixtures/AllPlugins/drone.yml new file mode 100644 index 0000000..90f3f82 --- /dev/null +++ b/test/fixtures/AllPlugins/drone.yml @@ -0,0 +1,29 @@ +--- +kind: pipeline +name: linux - arm - Julia {{VERSION}} + +platform: + os: linux + arch: arm + +steps: +- name: build + image: julia:{{VERSION}} + commands: + - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" + +--- +kind: pipeline +name: linux - arm64 - Julia {{VERSION}} + +platform: + os: linux + arch: arm64 + +steps: +- name: build + image: julia:{{VERSION}} + commands: + - "julia --project=. --check-bounds=yes --color=yes -e 'using InteractiveUtils; versioninfo(verbose=true); using Pkg; Pkg.build(); Pkg.test(coverage=true)'" + +... diff --git a/test/plugins/droneci.jl b/test/plugins/droneci.jl new file mode 100644 index 0000000..5b7fc6f --- /dev/null +++ b/test/plugins/droneci.jl @@ -0,0 +1,41 @@ +t = Template(; user=me) +pkg_dir = joinpath(t.dir, test_pkg) + +@testset "DroneCI" begin + @testset "Plugin creation" begin + p = DroneCI() + @test isempty(p.gitignore) + @test p.src == joinpath(DEFAULTS_DIR, "drone.yml") + @test p.dest == ".drone.yml" + @test p.badges == [ + Badge( + "Build Status", + "https://cloud.drone.io/api/badges/{{USER}}/{{PKGNAME}}.jl/status.svg", + "https://cloud.drone.io/{{USER}}/{{PKGNAME}}.jl", + ), + ] + @test isempty(p.view) + p = DroneCI(; config_file=nothing) + @test p.src === nothing + p = DroneCI(; config_file=test_file) + @test p.src == test_file + @test_throws ArgumentError DroneCI(; config_file=fake_path) + end + + @testset "Badge generation" begin + p = DroneCI() + @test badges(p, me, test_pkg) == ["[![Build Status](https://cloud.drone.io/api/badges/$me/$test_pkg.jl/status.svg)](https://cloud.drone.io/$me/$test_pkg.jl)"] + end + + @testset "File generation" begin + # Without a coverage plugin in the template, there should be no coverage step. + p = DroneCI() + @test gen_plugin(p, t, test_pkg) == [".drone.yml"] + @test isfile(joinpath(pkg_dir, ".drone.yml")) + drone = read(joinpath(pkg_dir, ".drone.yml"), String) + @test !occursin("coverage_script", drone) + rm(joinpath(pkg_dir, ".drone.yml")) + end +end + +rm(pkg_dir; recursive=true)