diff --git a/.codecov.yml b/.codecov.yml deleted file mode 100644 index 69cb7601..00000000 --- a/.codecov.yml +++ /dev/null @@ -1 +0,0 @@ -comment: false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..fae8897c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* eol=lf diff --git a/.gitignore b/.gitignore index 7be7ea33..96092701 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ -.DS_Store -*.jl.cov +/docs/build/ *.jl.*.cov +*.jl.cov *.jl.mem -/docs/build/ -/docs/site/ diff --git a/.travis.yml b/.travis.yml index 24b05746..a979400e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,40 @@ language: julia +notifications: + email: false os: - linux - osx + - windows julia: - 1.0 - - 1.1 + - 1.2 + - 1.3 - nightly +before_script: + - git config --global user.name Tester + - git config --global user.email te@st.er matrix: + fast_finish: true allow_failures: + - julia: 1.3 - julia: nightly - fast_finish: true -notifications: - email: false -after_success: julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' -jobs: include: + - arch: x86 + julia: 1.0 - stage: Documentation - julia: 1.1 - script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' + julia: 1.0 + script: + - git config --global user.name name + - git config --global user.email email + - git config --global github.user username + - julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' after_success: skip +after_success: julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' diff --git a/LICENSE b/LICENSE index a1486d40..2d40ab71 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +MIT License + Copyright (c) 2017-2019 Chris de Graaf, Invenia Technical Computing Corporation Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/Manifest.toml b/Manifest.toml index 95994a2e..e9084606 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -3,6 +3,16 @@ [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +[[DataAPI]] +git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.1.0" + +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -39,9 +49,21 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[Mustache]] deps = ["Printf", "Tables"] -git-tree-sha1 = "d27b8b8b99c052ea1fdd40c678bfb2dfaec4e96e" +git-tree-sha1 = "f39de3a12232eb47bd0629b3a661054287780276" uuid = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" -version = "0.5.12" +version = "0.5.13" + +[[OrderedCollections]] +deps = ["Random", "Serialization", "Test"] +git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.1.0" + +[[Parameters]] +deps = ["OrderedCollections"] +git-tree-sha1 = "b62b2558efb1eef1fa44e4be5ff58a515c287e38" +uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a" +version = "0.12.0" [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] @@ -59,12 +81,6 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" deps = ["Serialization"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -[[Requires]] -deps = ["Test"] -git-tree-sha1 = "f6fbf4ba64d295e146e49e021207993b6b48c7d1" -uuid = "ae029012-a4dd-5104-9daa-d747884805df" -version = "0.5.2" - [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -81,21 +97,15 @@ uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" version = "1.0.0" [[Tables]] -deps = ["IteratorInterfaceExtensions", "LinearAlgebra", "Requires", "TableTraits", "Test"] -git-tree-sha1 = "351a4b894122e1553c6ed05fda54086ab036adef" +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" -version = "0.2.5" +version = "0.2.11" [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" -[[URIParser]] -deps = ["Test", "Unicode"] -git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69" -uuid = "30578b45-9adc-5946-b283-645ec420af67" -version = "0.4.0" - [[UUIDs]] deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" diff --git a/Project.toml b/Project.toml index fc66eec9..713da4f9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,22 +1,26 @@ name = "PkgTemplates" uuid = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" -authors = ["Chris de Graaf "] -version = "0.6.3" +authors = ["Chris de Graaf", "Invenia Technical Computing Corporation"] +version = "0.7.0" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Mustache = "ffc61752-8dc7-55ee-8c37-f3e9cdd09e70" +Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" -URIParser = "30578b45-9adc-5946-b283-645ec420af67" +UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [compat] +Mustache = ">= 0.5.13" julia = "1" [extras] +Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" +SimpleMock = "a896ed2c-15a5-4479-b61d-a0e88e2a1d25" +Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["Suppressor", "Random", "ReferenceTests", "SimpleMock", "Test"] diff --git a/README.md b/README.md index 003eacee..8ede9010 100644 --- a/README.md +++ b/README.md @@ -1,147 +1,56 @@ # PkgTemplates [![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://invenia.github.io/PkgTemplates.jl/stable) -[![Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/latest) +[![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) -[![Build Status](https://ci.appveyor.com/api/projects/status/r24xamruqlm88uti/branch/master?svg=true)](https://ci.appveyor.com/project/christopher-dG/pkgtemplates-jl/branch/master) [![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 is a Julia package for creating new Julia packages in an easy, -repeatable, and customizable way.** +**PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** ## Installation -```julia -pkg> add PkgTemplates -``` - -## Plugins +Install with Pkg, just like any other registered Julia package: -`PkgTemplates` is based on plugins which handle the setup of individual package components. -The available plugins are: - -* Continuous Integration (CI) - * [Travis CI](https://travis-ci.com) (Linux, MacOS) - * [AppVeyor](https://appveyor.com) (Windows) - * [GitLabCI](https://gitlab.com) (Linux) - * [CirrusCI](https://cirrus-ci.org) (FreeBSD) -* Code Coverage - * [Codecov](https://codecov.io) - * [Coveralls](https://coveralls.io) -* Documentation - * [GitHubPages](https://pages.github.com) -* Citation +```jl +pkg> add PkgTemplates # Press ']' to enter te Pkg REPL mode. +``` ## Usage -Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, the simplest template requires no arguments: - -```julia -julia> using PkgTemplates - -julia> t = Template() -Template: - → User: christopher-dG - → Host: github.com - → License: MIT (Chris de Graaf 2018) - → Package directory: ~/.julia/dev - → Minimum Julia version: v1.0 - → SSH remote: No - → Commit Manifest.toml: No - → Plugins: None - -julia> generate("MyPkg", t) - -julia> run(`git -C $(joinpath(t.dir, "MyPkg")) ls-files`); -.gitignore -LICENSE -Manifest.toml -Project.toml -README.md -REQUIRE -src/MyPkg.jl -test/runtests.jl -``` +Creating a `Template` is as simple as: -However, we can also configure a number of keyword arguments to `Template`: - -```julia -julia> t = Template(; - user="myusername", - license="ISC", - authors=["Chris de Graaf", "Invenia Technical Computing Corporation"], - dir="~/code", - julia_version=v"0.7", - plugins=[ - TravisCI(), - Codecov(), - Coveralls(), - AppVeyor(), - GitHubPages(), - CirrusCI(), - ], - ) -Template: - → User: myusername - → Host: github.com - → License: ISC (Chris de Graaf, Invenia Technical Computing Corporation 2018) - → Package directory: ~/code - → Minimum Julia version: v0.7 - → SSH remote: No - → Commit Manifest.toml: No - → Plugins: - • AppVeyor: - → Config file: Default - → 0 gitignore entries - • Codecov: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • Coveralls: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • GitHubPages: - → 0 asset files - → 2 gitignore entries: "/docs/build/", "/docs/site/" - • TravisCI: - → Config file: Default - → 0 gitignore entries - -julia> generate(t, "MyPkg2") - -julia> run(`git -C $(joinpath(t.dir, "MyPkg2")) ls-files`); -.appveyor.yml -.gitignore -.travis.yml -LICENSE -Project.toml -README.md -REQUIRE -docs/Manifest.toml -docs/Project.toml -docs/make.jl -docs/src/index.md -src/MyPkg2.jl -test/runtests.jl +```jl +using PkgTemplates +t = Template() ``` -Information on each keyword as well as plugin types can be found in the -[documentation](https://invenia.github.io/PkgTemplates.jl/stable). +The no-keywords constructor assumes the existence of some preexisting Git configuration (set with `git config --global`): -If that looks like a lot of work, you can also create templates interactively -with `interactive_template`: +- `user.name`: Your real name, e.g. John Smith. +- `user.email`: Your email address, eg. john.smith@acme.corp. +- `github.user`: Your GitHub username: e.g. john-smith. -[![asciicast](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV.png)](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV) +Once you have a `Template`, use it to generate a package: -And if that's **still** too much work for you, you can call -`interactive_template` with `fast=true` to use default values for everything -but username and plugin selection. +```jl +t("MyPkg") +``` -You can also use `generate_interactive` to interactively generate a template and then -immediately use it to create a new package. +However, it's probably desirable to customize the template to your liking with various options and plugins: + +```jl +t = Template(; + dir="~/code", + plugins=[ + Git(; manifest=true, ssh=true), + Codecov(), + TravisCI(; x86=true), + Documenter{TravisCI}(), + ], +) +``` -## Contributing +--- -It's extremely easy to extend `PkgTemplates` with new plugins. To get started, -check out the -[plugin development guide](https://invenia.github.io/PkgTemplates.jl/stable/pages/plugin_development.html). +For a much more detailled overview, please see the documentation. diff --git a/REQUIRE b/REQUIRE deleted file mode 100644 index c08c8c1a..00000000 --- a/REQUIRE +++ /dev/null @@ -1,3 +0,0 @@ -julia 0.7 -Mustache -URIParser diff --git a/defaults/drone.yml b/defaults/drone.yml deleted file mode 100644 index 90f3f82b..00000000 --- a/defaults/drone.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -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/defaults/gitlab-ci.yml b/defaults/gitlab-ci.yml deleted file mode 100644 index ab0908b6..00000000 --- a/defaults/gitlab-ci.yml +++ /dev/null @@ -1,26 +0,0 @@ -Julia {{VERSION}}: - image: julia:{{VERSION}} - script: julia --project='@.' -e 'using Pkg; Pkg.build(); Pkg.test({{#GITLABCOVERAGE}}; coverage=true{{/GITLABCOVERAGE}})' -{{#GITLABCOVERAGE}} - coverage: /Test Coverage (\d+\.\d+%)/ - after_script: - - julia -e 'using Printf; using Pkg; Pkg.add("Coverage"); using Coverage; c, t = get_summary(process_folder()); @printf "Test Coverage %.2f%%\n" 100c/t' -{{/GITLABCOVERAGE}} -{{#DOCUMENTER}} -pages: - image: julia:{{VERSION}} - stage: deploy - script: - - julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' - - mkdir -p public - - mv docs/build public/dev - artifacts: - paths: - - public - only: - - master -{{/DOCUMENTER}} diff --git a/defaults/travis.yml b/defaults/travis.yml deleted file mode 100644 index 91e1500f..00000000 --- a/defaults/travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Documentation: http://docs.travis-ci.com/user/languages/julia/ -language: julia -os: - - linux - - osx -julia: - - {{VERSION}} - - nightly -matrix: - allow_failures: - - julia: nightly - fast_finish: true -notifications: - email: false -{{#COVERAGE}} -after_success: -{{#CODECOV}} - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())' -{{/CODECOV}} -{{#COVERALLS}} - - julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())' -{{/COVERALLS}} -{{/COVERAGE}} -{{#DOCUMENTER}} -jobs: - include: - - stage: Documentation - julia: {{VERSION}} - script: julia --project=docs -e ' - using Pkg; - Pkg.develop(PackageSpec(path=pwd())); - Pkg.instantiate(); - include("docs/make.jl");' - after_success: skip -{{/DOCUMENTER}} diff --git a/docs/Manifest.toml b/docs/Manifest.toml index 2af149e4..2fbd4f44 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -1,3 +1,5 @@ +# This file is machine-generated - editing it directly is not advised + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -6,35 +8,34 @@ deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" [[Distributed]] -deps = ["LinearAlgebra", "Random", "Serialization", "Sockets"] +deps = ["Random", "Serialization", "Sockets"] uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[DocStringExtensions]] deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "1df01539a1c952cef21f2d2d1c092c2bcf0177d7" +git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.6.0" +version = "0.8.1" [[Documenter]] -deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "LibGit2", "Logging", "Markdown", "Pkg", "REPL", "Random", "Test", "Unicode"] -git-tree-sha1 = "a6db1c69925cdc53aafb38caec4446be26e0c617" +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "d45c163c7a3ae293c15361acc52882c0f853f97c" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.21.0" +version = "0.23.4" [[InteractiveUtils]] -deps = ["LinearAlgebra", "Markdown"] +deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + [[LibGit2]] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" -[[Libdl]] -uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" - -[[LinearAlgebra]] -deps = ["Libdl"] -uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" - [[Logging]] uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -42,6 +43,15 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" deps = ["Base64"] uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.7" + [[Pkg]] deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" @@ -72,7 +82,7 @@ deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [[UUIDs]] -deps = ["Random"] +deps = ["Random", "SHA"] uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [[Unicode]] diff --git a/docs/make.jl b/docs/make.jl index 1ed399d0..d8c0af6f 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,20 +1,22 @@ -using Documenter, PkgTemplates +using Documenter: Documenter, makedocs, deploydocs +using PkgTemplates: PkgTemplates makedocs(; modules=[PkgTemplates], - format=Documenter.HTML(), + authors="Chris de Graaf, Invenia Technical Computing Corporation", + repo="https://github.com/invenia/PkgTemplates.jl/blob/{commit}{path}#L{line}", + sitename="PkgTemplates.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://invenia.github.io/PkgTemplates.jl", + assets=String[], + ), pages=[ "Home" => "index.md", - "Package Generation" => "pages/package_generation.md", - "Plugins" => "pages/plugins.md", - "Plugin Development" => "pages/plugin_development.md", - "Licenses" => "pages/licenses.md", - "Index" => "pages/index.md", + "User Guide" => "user.md", + "Developer Guide" => "developer.md", + "Migrating To PkgTemplates 0.7+" => "migrating.md", ], - repo="https://github.com/invenia/PkgTemplates.jl/blob/{commit}{path}#L{line}", - sitename="PkgTemplates.jl", - authors="Chris de Graaf, Invenia Technical Computing Corporation", - assets=[], ) deploydocs(; diff --git a/docs/src/developer.md b/docs/src/developer.md new file mode 100644 index 00000000..16e7c6a4 --- /dev/null +++ b/docs/src/developer.md @@ -0,0 +1,344 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# PkgTemplates Developer Guide + +```@contents +Pages = ["developer.md"] +``` + +PkgTemplates can be easily extended by adding new [`Plugin`](@ref)s. + +There are two types of plugins: [`Plugin`](@ref) and [`BasicPlugin`](@ref). + +```@docs +Plugin +BasicPlugin +``` + +## Template + Package Creation Pipeline + +The [`Template`](@ref) constructor basically does this: + +``` +- extract values from keyword arguments +- create a Template from the values +- for each plugin: + - validate plugin against the template +``` + +The plugin validation step uses the [`validate`](@ref) function. +It lets us catch mistakes before we try to generate packages. + +```@docs +validate +``` + +The package generation process looks like this: + +``` +- create empty directory for the package +- for each plugin, ordered by priority: + - run plugin prehook +- for each plugin, ordered by priority: + - run plugin hook +- for each plugin, ordered by priority: + - run plugin posthook +``` + +As you can tell, plugins play a central role in setting up a package. + +The three main entrypoints for plugins to do work are the [`prehook`](@ref), the [`hook`](@ref), and the [`posthook`](@ref). +As the names might imply, they basically mean "before the main stage", "the main stage", and "after the main stage", respectively. + +Each stage is basically identical, since the functions take the exact same arguments. +However, the multiple stages allow us to depend on artifacts of the previous stages. +For example, the [`Git`](@ref) plugin uses [`posthook`](@ref) to commit all generated files, but it wouldn't make sense to do that before the files are generated. + +But what about dependencies within the same stage? +In this case, we have [`priority`](@ref) to define which plugins go when. +The [`Git`](@ref) plugin also uses this function to lower its posthook's priority, so that even if other plugins generate files in their posthooks, they still get committed (provided that those plugins didn't set an even lower priority). + +```@docs +prehook +hook +posthook +priority +``` + +## `Plugin` Walkthrough + +Concrete types that subtype [`Plugin`](@ref) directly are free to do almost anything. +To understand how they're implemented, let's look at simplified versions of two plugins: [`Documenter`](@ref) to explore templating, and [`Git`](@ref) to further clarify the multi-stage pipeline. + +### Example: `Documenter` + +```julia +@with_kw_noshow struct Documenter <: Plugin + make_jl::String = default_file("docs", "make.jl") <- "Path to make.jl template" + index_md::String = default_file("docs", "src", "index.md") <- "Path to index.md template" +end + +gitignore(::Documenter) = ["/docs/build/"] + +badges(::Documenter) = [ + Badge( + "Stable", + "https://img.shields.io/badge/docs-stable-blue.svg", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable", + ), + Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev", + ), +] + +view(p::Documenter, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "PKG" => pkg, + "REPO" => "$(t.host)/$(t.user)/$pkg.jl", + "USER" => t.user, +) + +function hook(p::Documenter, t::Template, pkg_dir::AbstractString) + pkg = basename(pkg_dir) + docs_dir = joinpath(pkg_dir, "docs") + + make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "make.jl"), make) + + index = render_file(p.index_md, combined_view(p, t, pkg), tags(p)) + gen_file(joinpath(docs_dir, "src", "index.md"), index) + + # What this function does is not relevant here. + create_documentation_project() +end +``` + +The `@with_kw_noshow` macro defines keyword constructors for us. +Inside of our struct definition, we're using [`default_file`](@ref) to refer to files in this repository. + +```@docs +default_file +``` + +The first method we implement for `Documenter` is [`gitignore`](@ref), so that packages created with this plugin ignore documentation build artifacts. + +```@docs +gitignore +``` + +Second, we implement [`badges`](@ref) to add a couple of badges to new packages' README files. + +```@docs +badges +Badge +``` + +These two functions, [`gitignore`](@ref) and [`badges`](@ref), are currently the only "special" functions for cross-plugin interactions. +In other cases, you can still access the [`Template`](@ref)'s plugins to depend on the presence/properties of other plugins, although that's less powerful. + +Third, we implement [`view`](@ref), which is used to fill placeholders in badges and rendered files. + +```@docs +view +``` + +Finally, we implement [`hook`](@ref), which is the real workhorse for the plugin. +Inside of this function, we generate a couple of files with the help of a few more text templating functions. + +```@docs +render_file +render_text +gen_file +combined_view +tags +``` + +For more information on text templating, see the [`BasicPlugin` Walkthrough](@ref) and the section on [Custom Template Files](@ref). + +### Example: `Git` + +```julia +struct Git <: Plugin end + +priority(::Git, ::typeof(posthook)) = 5 + +function validate(::Git, ::Template) + foreach(("user.name", "user.email")) do k + if isempty(LibGit2.getconfig(k, "")) + throw(ArgumentError("Git: Global Git config is missing required value '$k'")) + end + end +end + +function prehook(::Git, t::Template, pkg_dir::AbstractString) + LibGit2.with(LibGit2.init(pkg_dir)) do repo + LibGit2.commit(repo, "Initial commit") + pkg = basename(pkg_dir) + url = "https://$(t.host)/$(t.user)/$pkg.jl" + close(GitRemote(repo, "origin", url)) + end +end + +function hook(::Git, t::Template, pkg_dir::AbstractString) + ignore = mapreduce(gitignore, append!, t.plugins) + unique!(sort!(ignore)) + gen_file(joinpath(pkg_dir, ".gitignore"), join(ignore, "\n")) +end + +function posthook(::Git, ::Template, pkg_dir::AbstractString) + LibGit2.with(GitRepo(pkg_dir)) do repo + LibGit2.add!(repo, ".") + LibGit2.commit(repo, "Files generated by PkgTemplates") + end +end +``` + +Validation and all three hooks are implemented: + +- [`validate`](@ref) makes sure that all required Git configuration is present. +- [`prehook`](@ref) creates the Git repository for the package. +- [`hook`](@ref) generates the `.gitignore` file, using the special [`gitignore`](@ref) function. +- [`posthook`](@ref) adds and commits all the generated files. + +As previously mentioned, we use [`priority`](@ref) to make sure that we wait until all other plugins are finished their work before committing files. + +Hopefully, this demonstrates the level of control you have over the package generation process when developing plugins, and when it makes sense to exercise that power! + +## `BasicPlugin` Walkthrough + +Most of the time, you don't really need all of the control that we showed off above. +Plugins that subtype [`BasicPlugin`](@ref) perform a much more limited task. +In general, they just generate one templated file. + +To illustrate, let's look at the [`Citation`](@ref) plugin, which creates a `CITATION.bib` file. + +```julia +@with_kw_noshow struct Citation <: BasicPlugin + file::String = default_file("CITATION.bib") +end + +source(p::Citation) = p.file +destination(::Citation) = "CITATION.bib" + +tags(::Citation) = "<<", ">>" + +view(::Citation, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "MONTH" => month(today()), + "PKG" => pkg, + "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", + "YEAR" => year(today()), +) +``` + +Similar to the `Documenter` example above, we're defining a keyword constructor, and assigning a default template file from this repository. +This plugin adds nothing to `.gitignore`, and it doesn't add any badges, so implementations for [`gitignore`](@ref) and [`badges`](@ref) are omitted. + +First, we implement [`source`](@ref) and [`destination`](@ref) to define where the template file comes from, and where it goes. +These functions are specific to [`BasicPlugin`](@ref)s, and have no effect on regular [`Plugin`](@ref)s by default. + +```@docs +source +destination +``` + +Next, we implement [`tags`](@ref). +We briefly saw this function earlier, but in this case it's necessary to change its behaviour from the default. +To see why, it might help to see the template file in its entirety: + +``` +@misc{<<&PKG>>.jl, + author = {<<&AUTHORS>>}, + title = {<<&PKG>>.jl}, + url = {<<&URL>>}, + version = {v0.1.0}, + year = {<<&YEAR>>}, + month = {<<&MONTH>>} +} +``` + +Because the file contains its own `{}` delimiters, we need to use different ones for templating to work properly. + +Finally, we implement [`view`](@ref) to fill in the placeholders that we saw in the template file. + +## Doing Extra Work With `BasicPlugin`s + +Notice that we didn't have to implement [`hook`](@ref) for our plugin. +It's implemented for all [`BasicPlugin`](@ref)s, like so: + +```julia +function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) + return render_file(source(p), combined_view(p, t, pkg), tags(p)) +end + +function hook(p::BasicPlugin, t::Template, pkg_dir::AbstractString) + source(p) === nothing && return + pkg = basename(pkg_dir) + path = joinpath(pkg_dir, destination(p)) + text = render_plugin(p, t, pkg) + gen_file(path, text) +end +``` + +But what if we want to do a little more than just generate one file? + +A good example of this is the [`Tests`](@ref) plugin. +It creates `runtests.jl`, but it also modifies the `Project.toml` to include the `Test` dependency. + +Of course, we could use a normal [`Plugin`](@ref), but it turns out there's a way to avoid that while still getting the extra capbilities that we want. + +The plugin implements its own `hook`, but uses `invoke` to avoid duplicating the file creation code: + +```julia +@with_kw_noshow struct Tests <: BasicPlugin + file::String = default_file("runtests.jl") +end + +source(p::Tests) = p.file +destination(::Tests) = joinpath("test", "runtests.jl") +view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +function hook(p::Tests, t::Template, pkg_dir::AbstractString) + # Do the normal BasicPlugin behaviour to create the test script. + invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + # Do some other work. + add_test_dependency() +end +``` + +There is also a default [`validate`](@ref) implementation for [`BasicPlugin`](@ref)s, which checks that the plugin's [`source`](@ref) file exists, and throws an `ArgumentError` otherwise. +If you want to extend the validation but keep the file existence check, use the `invoke` method as described above. + +For more examples, see the plugins in the [Continuous Integration (CI)](@ref) and [Code Coverage](@ref) sections. + +## Miscellaneous Tips + +### Writing Template Files + +For an overview of writing template files for Mustache.jl, see [Custom Template Files](@ref) in the user guide. + +### Predicates + +There are a few predicate functions for plugins that are occasionally used to answer questions like "does this `Template` have any code coverage plugins?". +If you're implementing a plugin that fits into one of the following categories, it would be wise to implement the corresponding predicate function to return `true` for instances of your type. + +```@docs +needs_username +is_ci +is_coverage +``` + +### Formatting Version Numbers + +When writing configuration files for CI services, working with version numbers is often needed. +There are a few convenience functions that can be used to make this a little bit easier. + +```@docs +compat_version +format_version +collect_versions +``` diff --git a/docs/src/index.md b/docs/src/index.md index b41a3f5f..924afa83 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -1,107 +1,20 @@ -# PkgTemplates - -[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://invenia.github.io/PkgTemplates.jl/stable) -[![Latest](https://img.shields.io/badge/docs-latest-blue.svg)](https://invenia.github.io/PkgTemplates.jl/latest) -[![Build Status](https://travis-ci.org/invenia/PkgTemplates.jl.svg?branch=master)](https://travis-ci.org/invenia/PkgTemplates.jl) -[![Build Status](https://ci.appveyor.com/api/projects/status/r24xamruqlm88uti/branch/master?svg=true)](https://ci.appveyor.com/project/christopher-dG/pkgtemplates-jl/branch/master) -[![Codecov](https://codecov.io/gh/invenia/PkgTemplates.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/invenia/PkgTemplates.jl) - -**PkgTemplates is a Julia package for creating new Julia packages in an easy, -repeatable, and customizable way.** - -## Installation - -```julia -pkg> add PkgTemplates +```@meta +CurrentModule = PkgTemplates ``` -## Plugins - -`PkgTemplates` is based on plugins which handle the setup of individual package components. -The available plugins are: - -* Continuous Integration (CI) - * [Travis CI](https://travis-ci.com) (Linux, MacOS) - * [AppVeyor](https://appveyor.com) (Windows) - * [GitLabCI](https://gitlab.com) (Linux) - * [CirrusCI](https://cirrus-ci.org) (FreeBSD) -* Code Coverage - * [Codecov](https://codecov.io) - * [Coveralls](https://coveralls.io) -* Documentation - * [GitHubPages](https://pages.github.com) -* Citation +# PkgTemplates -## Usage +**PkgTemplates creates new Julia packages in an easy, repeatable, and customizable way.** -```@setup usage -using LibGit2: getconfig -isempty(getconfig("user.name", "")) && run(`git config --global user.name "Travis"`) -isempty(getconfig("user.email", "")) && run(`git config --global user.email "travis@c.i"`) -isempty(getconfig("github.user", "")) && run(`git config --global github.user "travis"`) -using Pkg -Pkg.activate(mktempdir()) -# This code gets run in docs/build/, so this path evaluates to the repo root. -Pkg.add(PackageSpec(path=dirname(dirname(pwd())))) -``` +## Documentation -Assuming you have the relatively standard Git options `user.name`, `user.email` and `github.user` set up globally with `git config --global`, the simplest template requires no arguments: +If you're looking to **create new packages**, see the [User Guide](user.md). +If you want to **create new plugins**, see the [Developer Guide](developer.md). -```@repl usage -using PkgTemplates -t = Template() -generate("MyPkg", t) -run(`git -C $(joinpath(t.dir, "MyPkg")) ls-files`); -``` +if you're trying to **migrate from an older version of PkgTemplates**, see [Migrating To PkgTemplates 0.7+](migrating.md). -However, we can also configure a number of keyword arguments to -[`Template`](@ref): +## Index -```@repl usage -using PkgTemplates -t = Template(; - user="myusername", - license="MIT", - authors=["Chris de Graaf", "Invenia Technical Computing Corporation"], - dir="~/code", - julia_version=v"0.7", - ssh=true, - plugins=[ - TravisCI(), - Codecov(), - Coveralls(), - AppVeyor(), - GitHubPages(), - CirrusCI(), - ], -) -generate("MyPkg2", t) -run(`git -C $(joinpath(t.dir, "MyPkg2")) ls-files`); +```@index ``` - -If that looks like a lot of work, you can also create templates interactively -with [`interactive_template`](@ref): - -[![asciicast](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV.png)](https://asciinema.org/a/31bZqW9u8h5RHpd7gtsemioRV) - -And if that's **still** too much work for you, you can call -`interactive_template` with `fast=true` to use default values for everything -but username and plugin selection. - -You can also use [`generate_interactive`](@ref) to interactively generate a template and then -immediately use it to create a new package. - -## Comparison to PkgDev - -`PkgTemplates` is similar in functionality to -[`PkgDev`](https://github.com/JuliaLang/PkgDev.jl)'s `generate` function. However, -`PkgTemplates` offers more customizability in templates and more extensibility via plugins. -For the package registration and release management features that `PkgTemplates` doesn't -include, you are encouraged to use [AttoBot](https://github.com/apps/attobot) instead. - -## Contributing - -It's extremely easy to extend `PkgTemplates` with new plugins. To get started, -check out the -[plugin development guide](https://invenia.github.io/PkgTemplates.jl/stable/pages/plugin_development.html). diff --git a/docs/src/migrating.md b/docs/src/migrating.md new file mode 100644 index 00000000..f2d0e5b0 --- /dev/null +++ b/docs/src/migrating.md @@ -0,0 +1,61 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# Migrating To PkgTemplates 0.7+ + +PkgTemplates 0.7 is a ground-up rewrite of the package with similar functionality but with updated APIs and internals. +Here is a summary of things that existed in older versions but have been moved elsewhere or removed. +However, it might be easier to just read the [User Guide](user.md). + +## Template keywords + +The recurring theme is "everything is a plugin now". + +| Old | New | +| :------------------: | :-------------------------------: | +| `license="ISC"` | `plugins=[License(; name="ISC")]` | +| `develop=true` * | `plugins=[Develop()]` | +| `git=false` | `disable_defaults=[Git]` | +| `julia_version=v"1"` | `julia=v"1"` | +| `ssh=true` | `plugins=[Git(; ssh=true)]` | +| `manifest=true` | `plugins=[Git(; manifest=true)]` | + +\* `develop=true` was the default setting, but it is no longer the default in PkgTemplates 0.7+. + +## Plugins + +Aside from renamings, basically every plugin has had their constructors reworked. +So if you are using anything non-default, you should consult the new docstring. + +| Old | New | +| :-----------: | :--------------------: | +| `GitHubPages` | `Documenter{TravisCI}` | +| `GitLabPages` | `Documenter{GitLabCI}` | + +## Package Generation + +One less name to remember! + +| Old | New | +| :-----------------------------------------: | :---------------------------------: | +| `generate(::Template, pkg::AbstractString)` | `(::Template)(pkg::AbstractString)` | + +## Interactive Templates + +Currently not implemented, but will be in the future. + +## Other Functions + +Two less names to remember! +Although it's unlikely that anyone used these. + +| Old | New | +| :------------------: | :--------------------------------------------------------------------------------------------------: | +| `available_licenses` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | +| `show_license` | [View licenses on GitHub](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses) | + +## Custom Plugins + +In addition to the changes in usage, custom plugins from older versions of PkgTemplates will not work in 0.7+. +See the [Developer Guide](developer.md) for more information on the new extension API. diff --git a/docs/src/pages/index.md b/docs/src/pages/index.md deleted file mode 100644 index aa651b91..00000000 --- a/docs/src/pages/index.md +++ /dev/null @@ -1,4 +0,0 @@ -# Index - -```@index -``` diff --git a/docs/src/pages/licenses.md b/docs/src/pages/licenses.md deleted file mode 100644 index bf6b886b..00000000 --- a/docs/src/pages/licenses.md +++ /dev/null @@ -1,20 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Licenses - -[Many open-source licenses](https://github.com/christopher-dG/PkgTemplates.jl/tree/master/licenses) -are available for use with `PkgTemplates`, but if you see that one is missing, -don't hesitate to open an issue or PR. - -```@docs -available_licenses -show_license -``` - -### Helper Functions - -```@docs -read_license -``` diff --git a/docs/src/pages/package_generation.md b/docs/src/pages/package_generation.md deleted file mode 100644 index 24a1995d..00000000 --- a/docs/src/pages/package_generation.md +++ /dev/null @@ -1,31 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Package Generation - -Creating new packages with `PkgTemplates` revolves around creating a new -[`Template`](@ref), then calling [`generate`](@ref) on it. - -## `Template` - -```@docs -Template -interactive_template -``` - -## `generate` - -```@docs -generate -generate_interactive -``` - -### Helper Functions - -```@docs -gen_tests -gen_readme -gen_gitignore -gen_license -``` diff --git a/docs/src/pages/plugin_development.md b/docs/src/pages/plugin_development.md deleted file mode 100644 index 31aa9927..00000000 --- a/docs/src/pages/plugin_development.md +++ /dev/null @@ -1,75 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Plugin Development - -The best and easiest way to contribute to `PkgTemplates` is to write new -plugins. - -```@docs -Plugin -``` - -## Generic Plugins - -```@docs -GenericPlugin -``` - -## Custom Plugins - -```@docs -CustomPlugin -``` - -### `CustomPlugin` Required Methods - -#### `gen_plugin` - -```@docs -gen_plugin -interactive -``` - -**Note**: [`interactive`](@ref) is not strictly required, however without it, -your custom plugin will not be available when creating templates with -[`interactive_template`](@ref). - -#### `badges` - -```@docs -badges -``` - -## Helper Types/Functions - -#### `gen_file` - -```@docs -gen_file -``` - -#### `substitute` - -```@docs -substitute -``` - -#### `Badge` - -```@docs -Badge -``` - -#### `format` - -```@docs -format -``` - -#### `version_floor` - -```@docs -version_floor -``` diff --git a/docs/src/pages/plugins.md b/docs/src/pages/plugins.md deleted file mode 100644 index dd4f07a9..00000000 --- a/docs/src/pages/plugins.md +++ /dev/null @@ -1,33 +0,0 @@ -```@meta -CurrentModule = PkgTemplates -``` - -# Plugins - -Plugins are the secret sauce behind `PkgTemplates`'s customization and extension. This page -describes plugins that already exist; for information on writing your own plugins, see -[Plugin Development](@ref). - -## Continuous Integration (CI) - -```@docs -TravisCI -AppVeyor -GitLabCI -CirrusCI -``` - -## Code Coverage - -```@docs -Codecov -Coveralls -``` - -## Documentation - -```@docs -Documenter -GitHubPages -GitLabPages -``` diff --git a/docs/src/user.md b/docs/src/user.md new file mode 100644 index 00000000..d2771ac3 --- /dev/null +++ b/docs/src/user.md @@ -0,0 +1,276 @@ +```@meta +CurrentModule = PkgTemplates +``` + +# PkgTemplates User Guide + +```@contents +Pages = ["user.md"] +``` + +Using PkgTemplates is straightforward. +Just create a [`Template`](@ref), and call it on a package name to generate that package: + +```julia +using PkgTemplates +t = Template() +t("MyPkg") +``` + +## Template + +```@docs +Template +``` + +## Plugins + +Plugins add functionality to `Template`s. +There are a number of plugins available to automate common boilerplate tasks. + +### Default Plugins + +These plugins are included by default. +They can be overridden by supplying another value via the `plugins` keyword, or disabled by supplying the type via the `disable_defaults` keyword. + +```@docs +ProjectFile +SrcDir +Tests +Readme +License +Git +``` + +### Continuous Integration (CI) + +These plugins will create the configuration files of common CI services for you. + +```@docs +AppVeyor +CirrusCI +DroneCI +GitHubActions +GitLabCI +TravisCI +``` + +### Code Coverage + +These plugins will enable code coverage reporting from CI. + +```@docs +Codecov +Coveralls +``` + +### Documentation + +```@docs +Documenter +``` + +### Miscellaneous + +```@docs +Develop +Citation +``` + +## A More Complicated Example + +Here are a few example templates that use the options and plugins explained above. + +This one includes plugins suitable for a project hosted on GitHub, and some other customizations: + +```julia +Template(; + user="my-username", + dir="~/code", + authors="Acme Corp", + julia=v"1.1", + plugins=[ + License(; name="MPL"), + Git(; manifest=true, ssh=true), + GitHubActions(; x86=true), + Codecov(), + Documenter{GitHubActions}(), + Develop(), + ], +) +``` + +Here's one that works well for projects hosted on GitLab: + +```julia +Template(; + user="my-username", + host="gitlab.com", + plugins=[ + GitLabCI(), + Documenter{GitLabCI}(), + ], +) +``` + +## Custom Template Files + +!!! note "Templates vs Templating" + This documentation refers plenty to [`Template`](@ref)s, the package's main type, but it also refers to "template files" and "text templating", which are plaintext files with placeholders to be filled with data, and the technique of filling those placeholders with data, respectively. + + These concepts should be familiar if you've used [Jinja](https://palletsprojects.com/p/jinja) or [Mustache](https://mustache.github.io) (Mustache is the particular flavour used by PkgTemplates, via [Mustache.jl](https://github.com/jverzani/Mustache.jl)). + Please keep the difference between these two things in mind! + +Many plugins support a `file` argument or similar, which sets the path to the template file to be used for generating files. +Each plugin has a sensible default that should make sense for most people, but you might have a specialized workflow that requires a totally different template file. + +If that's the case, a basic understanding of [Mustache](https://mustache.github.io)'s syntax is required. +Here's an example template file: + +``` +Hello, {{{name}}}. + +{{#weather}} +It's {{{weather}}} outside. +{{/weather}} +{{^weather}} +I don't know what the weather outside is. +{{/weather}} + +{{#has_things}} +I have the following things: +{{/has_things}} +{{#things}} +- Here's a thing: {{{.}}} +{{/things}} + +{{#people}} +- {{{name}}} is {{{mood}}} +{{/people}} +``` + +In the first section, `name` is a key, and its value replaces `{{{name}}}`. + +In the second section, `weather`'s value may or may not exist. +If it does exist, then "It's $weather outside" is printed. +Otherwise, "I don't know what the weather outside is" is printed. +Mustache uses a notion of "truthiness" similar to Python or JavaScript, where values of `nothing`, `false`, or empty collections are all considered to not exist. + +In the third section, `has_things`' value is printed if it's truthy. +Then, if the `things` list is truthy (i.e. not empty), its values are each printed on their own line. +The reason that we have two separate keys is that `{{#things}}` iterates over the whole `things` list, even when there are no `{{{.}}}` placeholders, which would duplicate "I have the following things:" `n` times. + +The fourth section iterates over the `people` list, but instead of using the `{{{.}}}` placeholder, we have `name` and `mood`, which are keys or fields of the list elements. +Most types are supported here, including `Dict`s and structs. +`NamedTuple`s require you to use `{{{:name}}}` instead of the normal `{{{name}}}`, though. + +You might notice that some curlies are in groups of two (`{{key}}`), and some are in groups of three (`{{{key}}}`). +Whenever we want to subtitute in a value, using the triple curlies disables HTML escaping, which we rarely want for the types of files we're creating. +If you do want escaping, just use the double curlies. +And if you're using different delimiters, for example `<>`, use `<<&foo>>` to disable escaping. + +Assuming the following view: + +```julia +struct Person; name::String; mood::String; end +things = ["a", "b", "c"] +view = Dict( + "name" => "Chris", + "weather" => "sunny", + "has_things" => !isempty(things), + "things" => things, + "people" => [Person("John", "happy"), Person("Jane", "sad")], +) +``` + +Our example template would produce this: + +``` +Hello, Chris. + +It's sunny outside. + +I have the following things: +- Here's a thing: a +- Here's a thing: b +- Here's a thing: c + +- John is happy +- Jane is sad +``` + +## Extending Existing Plugins + +Most of the existing plugins generate a file from a template file. +If you want to use custom template files, you may run into situations where the data passed into the templating engine is not sufficient. +In this case, you can look into implementing [`user_view`](@ref) to supply whatever data is necessary for your use case. + +```@docs +user_view +``` + +For example, suppose you were using the [`Readme`](@ref) plugin with a custom template file that looked like this: + +```md +# {{PKG}} + +Created on *{{TODAY}}*. +``` + +The [`view`](@ref) function supplies a value for `PKG`, but it does not supply a value for `TODAY`. +Rather than override [`view`](@ref), we can implement this function to get both the default values and whatever else we need to add. + +```julia +user_view(::Readme, ::Template, ::AbstractString) = Dict("TODAY" => today()) +``` + +## Saving Templates + +One of the main reasons for PkgTemplates' existence is for new packages to be consistent. +This means using the same template more than once, so we want a way to save a template to be used later. + +Here's my recommendation for loading a template whenever it's needed: + +```julia +function template() + @eval using PkgTemplates + Template(; #= ... =#) +end +``` + +Add this to your `startup.jl`, and you can create your template from anywhere, without incurring any startup cost. + +Another strategy is to write the string representation of the template to a Julia file: + +```julia +const t = Template(; #= ... =#) +open("template.jl", "w") do io + println(io, "using PkgTemplates") + sprint(show, io, t) +end +``` + +Then the template is just an `include` away: + +```julia +const t = include("template.jl") +``` + +The only disadvantage to this approach is that the saved template is much less human-readable than code you wrote yourself. + +One more method of saving templates is to simply use the Serialization package in the standard library: + +```julia +const t = Template(; #= ... =#) +using Serialization +open(io -> serialize(io, t), "template.bin", "w") +``` + +Then simply `deserialize` to load: + +```julia +using Serialization +const t = open(deserialize, "template.bin") +``` + +This approach has the same disadvantage as the previous one, and the serialization format is not guaranteed to be stable across Julia versions. diff --git a/licenses/BSD3 b/licenses/BSD3 deleted file mode 100644 index bd84765d..00000000 --- a/licenses/BSD3 +++ /dev/null @@ -1,12 +0,0 @@ - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -* Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/licenses/EUPL-1.2+ b/licenses/EUPL-1.2+ deleted file mode 100644 index 6603aeb5..00000000 --- a/licenses/EUPL-1.2+ +++ /dev/null @@ -1,191 +0,0 @@ - -EUROPEAN UNION PUBLIC LICENCE v. 1.2 -EUPL © the European Union 2007, 2016 - -This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the -terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such -use is covered by a right of the copyright holder of the Work). -The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following -notice immediately following the copyright notice for the Work: - Licensed under the EUPL -or has expressed by any other means his willingness to license under the EUPL. - -1.Definitions -In this Licence, the following terms have the following meaning: -— ‘The Licence’:this Licence. -— ‘The Original Work’:the work or software distributed or communicated by the Licensor under this Licence, available -as Source Code and also as Executable Code as the case may be. -— ‘Derivative Works’:the works or software that could be created by the Licensee, based upon the Original Work or -modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work -required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in -the country mentioned in Article 15. -— ‘The Work’:the Original Work or its Derivative Works. -— ‘The Source Code’:the human-readable form of the Work which is the most convenient for people to study and -modify. -— ‘The Executable Code’:any code which has generally been compiled and which is meant to be interpreted by -a computer as a program. -— ‘The Licensor’:the natural or legal person that distributes or communicates the Work under the Licence. -— ‘Contributor(s)’:any natural or legal person who modifies the Work under the Licence, or otherwise contributes to -the creation of a Derivative Work. -— ‘The Licensee’ or ‘You’:any natural or legal person who makes any usage of the Work under the terms of the -Licence. -— ‘Distribution’ or ‘Communication’:any act of selling, giving, lending, renting, distributing, communicating, -transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential -functionalities at the disposal of any other natural or legal person. - -2.Scope of the rights granted by the Licence -The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for -the duration of copyright vested in the Original Work: -— use the Work in any circumstance and for all usage, -— reproduce the Work, -— modify the Work, and make Derivative Works based upon the Work, -— communicate to the public, including the right to make available or display the Work or copies thereof to the public -and perform publicly, as the case may be, the Work, -— distribute the Work or copies thereof, -— lend and rent the Work or copies thereof, -— sublicense rights in the Work or copies thereof. -Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the -applicable law permits so. -In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed -by law in order to make effective the licence of the economic rights here above listed. -The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the -extent necessary to make use of the rights granted on the Work under this Licence. - -3.Communication of the Source Code -The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as -Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with -each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to -the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to -distribute or communicate the Work. - -4.Limitations on copyright -Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the -exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations -thereto. - -5.Obligations of the Licensee -The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those -obligations are the following: - -Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to -the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the -Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work -to carry prominent notices stating that the Work has been modified and the date of modification. - -Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this -Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless -the Original Work is expressly distributed only under this version of the Licence — for example by communicating -‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the -Work or Derivative Work that alter or restrict the terms of the Licence. - -Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both -the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done -under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed -in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with -his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. - -Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide -a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available -for as long as the Licensee continues to distribute or communicate the Work. -Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names -of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and -reproducing the content of the copyright notice. - -6.Chain of Authorship -The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or -licensed to him/her and that he/she has the power and authority to grant the Licence. -Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or -licensed to him/her and that he/she has the power and authority to grant the Licence. -Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions -to the Work, under the terms of this Licence. - -7.Disclaimer of Warranty -The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work -and may therefore contain defects or ‘bugs’ inherent to this type of development. -For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind -concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or -errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this -Licence. -This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. - -8.Disclaimer of Liability -Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be -liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the -Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss -of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, -the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. - -9.Additional agreements -While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services -consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole -responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, -defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by -the fact You have accepted any warranty or additional liability. - -10.Acceptance of the Licence -The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window -displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of -applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms -and conditions. -Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You -by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution -or Communication by You of the Work or copies thereof. - -11.Information to the public -In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, -by offering to download the Work from a remote location) the distribution channel or media (for example, a website) -must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence -and the way it may be accessible, concluded, stored and reproduced by the Licensee. - -12.Termination of the Licence -The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms -of the Licence. -Such a termination will not terminate the licences of any person who has received the Work from the Licensee under -the Licence, provided such persons remain in full compliance with the Licence. - -13.Miscellaneous -Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the -Work. -If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or -enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid -and enforceable. -The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of -the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. -New versions of the Licence will be published with a unique version number. -All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take -advantage of the linguistic version of their choice. - -14.Jurisdiction -Without prejudice to specific agreement between parties, -— any litigation resulting from the interpretation of this License, arising between the European Union institutions, -bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice -of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, -— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to -the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. - -15.Applicable Law -Without prejudice to specific agreement between parties, -— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, -resides or has his registered office, -— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside -a European Union Member State. - - - Appendix - -‘Compatible Licences’ according to Article 5 EUPL are: -— GNU General Public License (GPL) v. 2, v. 3 -— GNU Affero General Public License (AGPL) v. 3 -— Open Software License (OSL) v. 2.1, v. 3.0 -— Eclipse Public License (EPL) v. 1.0 -— CeCILL v. 2.0, v. 2.1 -— Mozilla Public Licence (MPL) v. 2 -— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 -— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software -— European Union Public Licence (EUPL) v. 1.1, v. 1.2 -— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+). - -The European Commission may update this Appendix to later versions of the above licences without producing -a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the -covered Source Code from exclusive appropriation. -All other changes or additions to this Appendix require the production of a new EUPL version. diff --git a/licenses/LGPL-3.0+ b/licenses/LGPL-3.0+ deleted file mode 100644 index 52a81ac9..00000000 --- a/licenses/LGPL-3.0+ +++ /dev/null @@ -1,182 +0,0 @@ - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 3 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. - - END OF TERMS AND CONDITIONS diff --git a/licenses/MPL b/licenses/MPL deleted file mode 100644 index 7be29a13..00000000 --- a/licenses/MPL +++ /dev/null @@ -1,363 +0,0 @@ - -Mozilla Public License, version 2.0 - -1. Definitions - -1.1. "Contributor" - - means each individual or legal entity that creates, contributes to the - creation of, or owns Covered Software. - -1.2. "Contributor Version" - - means the combination of the Contributions of others (if any) used by a - Contributor and that particular Contributor's Contribution. - -1.3. "Contribution" - - means Covered Software of a particular Contributor. - -1.4. "Covered Software" - - means Source Code Form to which the initial Contributor has attached the - notice in Exhibit A, the Executable Form of such Source Code Form, and - Modifications of such Source Code Form, in each case including portions - thereof. - -1.5. "Incompatible With Secondary Licenses" - means - - a. that the initial Contributor has attached the notice described in - Exhibit B to the Covered Software; or - - b. that the Covered Software was made available under the terms of - version 1.1 or earlier of the License, but not also under the terms of - a Secondary License. - -1.6. "Executable Form" - - means any form of the work other than Source Code Form. - -1.7. "Larger Work" - - means a work that combines Covered Software with other material, in a - separate file or files, that is not Covered Software. - -1.8. "License" - - means this document. - -1.9. "Licensable" - - means having the right to grant, to the maximum extent possible, whether - at the time of the initial grant or subsequently, any and all of the - rights conveyed by this License. - -1.10. "Modifications" - - means any of the following: - - a. any file in Source Code Form that results from an addition to, - deletion from, or modification of the contents of Covered Software; or - - b. any new file in Source Code Form that contains any Covered Software. - -1.11. "Patent Claims" of a Contributor - - means any patent claim(s), including without limitation, method, - process, and apparatus claims, in any patent Licensable by such - Contributor that would be infringed, but for the grant of the License, - by the making, using, selling, offering for sale, having made, import, - or transfer of either its Contributions or its Contributor Version. - -1.12. "Secondary License" - - means either the GNU General Public License, Version 2.0, the GNU Lesser - General Public License, Version 2.1, the GNU Affero General Public - License, Version 3.0, or any later versions of those licenses. - -1.13. "Source Code Form" - - means the form of the work preferred for making modifications. - -1.14. "You" (or "Your") - - means an individual or a legal entity exercising rights under this - License. For legal entities, "You" includes any entity that controls, is - controlled by, or is under common control with You. For purposes of this - definition, "control" means (a) the power, direct or indirect, to cause - the direction or management of such entity, whether by contract or - otherwise, or (b) ownership of more than fifty percent (50%) of the - outstanding shares or beneficial ownership of such entity. - - -2. License Grants and Conditions - -2.1. Grants - - Each Contributor hereby grants You a world-wide, royalty-free, - non-exclusive license: - - a. under intellectual property rights (other than patent or trademark) - Licensable by such Contributor to use, reproduce, make available, - modify, display, perform, distribute, and otherwise exploit its - Contributions, either on an unmodified basis, with Modifications, or - as part of a Larger Work; and - - b. under Patent Claims of such Contributor to make, use, sell, offer for - sale, have made, import, and otherwise transfer either its - Contributions or its Contributor Version. - -2.2. Effective Date - - The licenses granted in Section 2.1 with respect to any Contribution - become effective for each Contribution on the date the Contributor first - distributes such Contribution. - -2.3. Limitations on Grant Scope - - The licenses granted in this Section 2 are the only rights granted under - this License. No additional rights or licenses will be implied from the - distribution or licensing of Covered Software under this License. - Notwithstanding Section 2.1(b) above, no patent license is granted by a - Contributor: - - a. for any code that a Contributor has removed from Covered Software; or - - b. for infringements caused by: (i) Your and any other third party's - modifications of Covered Software, or (ii) the combination of its - Contributions with other software (except as part of its Contributor - Version); or - - c. under Patent Claims infringed by Covered Software in the absence of - its Contributions. - - This License does not grant any rights in the trademarks, service marks, - or logos of any Contributor (except as may be necessary to comply with - the notice requirements in Section 3.4). - -2.4. Subsequent Licenses - - No Contributor makes additional grants as a result of Your choice to - distribute the Covered Software under a subsequent version of this - License (see Section 10.2) or under the terms of a Secondary License (if - permitted under the terms of Section 3.3). - -2.5. Representation - - Each Contributor represents that the Contributor believes its - Contributions are its original creation(s) or it has sufficient rights to - grant the rights to its Contributions conveyed by this License. - -2.6. Fair Use - - This License is not intended to limit any rights You have under - applicable copyright doctrines of fair use, fair dealing, or other - equivalents. - -2.7. Conditions - - Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in - Section 2.1. - - -3. Responsibilities - -3.1. Distribution of Source Form - - All distribution of Covered Software in Source Code Form, including any - Modifications that You create or to which You contribute, must be under - the terms of this License. You must inform recipients that the Source - Code Form of the Covered Software is governed by the terms of this - License, and how they can obtain a copy of this License. You may not - attempt to alter or restrict the recipients' rights in the Source Code - Form. - -3.2. Distribution of Executable Form - - If You distribute Covered Software in Executable Form then: - - a. such Covered Software must also be made available in Source Code Form, - as described in Section 3.1, and You must inform recipients of the - Executable Form how they can obtain a copy of such Source Code Form by - reasonable means in a timely manner, at a charge no more than the cost - of distribution to the recipient; and - - b. You may distribute such Executable Form under the terms of this - License, or sublicense it under different terms, provided that the - license for the Executable Form does not attempt to limit or alter the - recipients' rights in the Source Code Form under this License. - -3.3. Distribution of a Larger Work - - You may create and distribute a Larger Work under terms of Your choice, - provided that You also comply with the requirements of this License for - the Covered Software. If the Larger Work is a combination of Covered - Software with a work governed by one or more Secondary Licenses, and the - Covered Software is not Incompatible With Secondary Licenses, this - License permits You to additionally distribute such Covered Software - under the terms of such Secondary License(s), so that the recipient of - the Larger Work may, at their option, further distribute the Covered - Software under the terms of either this License or such Secondary - License(s). - -3.4. Notices - - You may not remove or alter the substance of any license notices - (including copyright notices, patent notices, disclaimers of warranty, or - limitations of liability) contained within the Source Code Form of the - Covered Software, except that You may alter any license notices to the - extent required to remedy known factual inaccuracies. - -3.5. Application of Additional Terms - - You may choose to offer, and to charge a fee for, warranty, support, - indemnity or liability obligations to one or more recipients of Covered - Software. However, You may do so only on Your own behalf, and not on - behalf of any Contributor. You must make it absolutely clear that any - such warranty, support, indemnity, or liability obligation is offered by - You alone, and You hereby agree to indemnify every Contributor for any - liability incurred by such Contributor as a result of warranty, support, - indemnity or liability terms You offer. You may include additional - disclaimers of warranty and limitations of liability specific to any - jurisdiction. - -4. Inability to Comply Due to Statute or Regulation - - If it is impossible for You to comply with any of the terms of this License - with respect to some or all of the Covered Software due to statute, - judicial order, or regulation then You must: (a) comply with the terms of - this License to the maximum extent possible; and (b) describe the - limitations and the code they affect. Such description must be placed in a - text file included with all distributions of the Covered Software under - this License. Except to the extent prohibited by statute or regulation, - such description must be sufficiently detailed for a recipient of ordinary - skill to be able to understand it. - -5. Termination - -5.1. The rights granted under this License will terminate automatically if You - fail to comply with any of its terms. However, if You become compliant, - then the rights granted under this License from a particular Contributor - are reinstated (a) provisionally, unless and until such Contributor - explicitly and finally terminates Your grants, and (b) on an ongoing - basis, if such Contributor fails to notify You of the non-compliance by - some reasonable means prior to 60 days after You have come back into - compliance. Moreover, Your grants from a particular Contributor are - reinstated on an ongoing basis if such Contributor notifies You of the - non-compliance by some reasonable means, this is the first time You have - received notice of non-compliance with this License from such - Contributor, and You become compliant prior to 30 days after Your receipt - of the notice. - -5.2. If You initiate litigation against any entity by asserting a patent - infringement claim (excluding declaratory judgment actions, - counter-claims, and cross-claims) alleging that a Contributor Version - directly or indirectly infringes any patent, then the rights granted to - You by any and all Contributors for the Covered Software under Section - 2.1 of this License shall terminate. - -5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user - license agreements (excluding distributors and resellers) which have been - validly granted by You or Your distributors under this License prior to - termination shall survive termination. - -6. Disclaimer of Warranty - - Covered Software is provided under this License on an "as is" basis, - without warranty of any kind, either expressed, implied, or statutory, - including, without limitation, warranties that the Covered Software is free - of defects, merchantable, fit for a particular purpose or non-infringing. - The entire risk as to the quality and performance of the Covered Software - is with You. Should any Covered Software prove defective in any respect, - You (not any Contributor) assume the cost of any necessary servicing, - repair, or correction. This disclaimer of warranty constitutes an essential - part of this License. No use of any Covered Software is authorized under - this License except under this disclaimer. - -7. Limitation of Liability - - Under no circumstances and under no legal theory, whether tort (including - negligence), contract, or otherwise, shall any Contributor, or anyone who - distributes Covered Software as permitted above, be liable to You for any - direct, indirect, special, incidental, or consequential damages of any - character including, without limitation, damages for lost profits, loss of - goodwill, work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses, even if such party shall have been - informed of the possibility of such damages. This limitation of liability - shall not apply to liability for death or personal injury resulting from - such party's negligence to the extent applicable law prohibits such - limitation. Some jurisdictions do not allow the exclusion or limitation of - incidental or consequential damages, so this exclusion and limitation may - not apply to You. - -8. Litigation - - Any litigation relating to this License may be brought only in the courts - of a jurisdiction where the defendant maintains its principal place of - business and such litigation shall be governed by laws of that - jurisdiction, without reference to its conflict-of-law provisions. Nothing - in this Section shall prevent a party's ability to bring cross-claims or - counter-claims. - -9. Miscellaneous - - This License represents the complete agreement concerning the subject - matter hereof. If any provision of this License is held to be - unenforceable, such provision shall be reformed only to the extent - necessary to make it enforceable. Any law or regulation which provides that - the language of a contract shall be construed against the drafter shall not - be used to construe this License against a Contributor. - - -10. Versions of the License - -10.1. New Versions - - Mozilla Foundation is the license steward. Except as provided in Section - 10.3, no one other than the license steward has the right to modify or - publish new versions of this License. Each version will be given a - distinguishing version number. - -10.2. Effect of New Versions - - You may distribute the Covered Software under the terms of the version - of the License under which You originally received the Covered Software, - or under the terms of any subsequent version published by the license - steward. - -10.3. Modified Versions - - If you create software not governed by this License, and you want to - create a new license for such software, you may create and use a - modified version of this License if you rename the license and remove - any references to the name of the license steward (except to note that - such modified license differs from this License). - -10.4. Distributing Source Code Form that is Incompatible With Secondary - Licenses If You choose to distribute Source Code Form that is - Incompatible With Secondary Licenses under the terms of this version of - the License, the notice described in Exhibit B of this License must be - attached. - -Exhibit A - Source Code Form License Notice - - This Source Code Form is subject to the - terms of the Mozilla Public License, v. - 2.0. If a copy of the MPL was not - distributed with this file, You can - obtain one at - http://mozilla.org/MPL/2.0/. - -If it is not possible or desirable to put the notice in a particular file, -then You may include the notice in a location (such as a LICENSE file in a -relevant directory) where a recipient would be likely to look for such a -notice. - -You may add additional accurate notices of copyright ownership. - -Exhibit B - "Incompatible With Secondary Licenses" Notice - - This Source Code Form is "Incompatible - With Secondary Licenses", as defined by - the Mozilla Public License, v. 2.0. diff --git a/src/PkgTemplates.jl b/src/PkgTemplates.jl index ebd05c24..2e080db4 100644 --- a/src/PkgTemplates.jl +++ b/src/PkgTemplates.jl @@ -1,57 +1,57 @@ module PkgTemplates -using Dates -using InteractiveUtils -using LibGit2 -using Mustache -using Pkg -using REPL.TerminalMenus -using URIParser +using Base: active_project +using Base.Filesystem: contractuser + +using Dates: month, today, year +using LibGit2: LibGit2, GitRemote, GitRepo +using Pkg: Pkg, TOML, PackageSpec +using UUIDs: uuid4 + +using Mustache: render +using Parameters: @with_kw_noshow export - # Template/package generation. Template, - generate, - interactive_template, - generate_interactive, - # Licenses. - show_license, - available_licenses, - # Plugins. - GitHubPages, - GitLabPages, AppVeyor, - TravisCI, - GitLabCI, CirrusCI, + Citation, DroneCI, Codecov, Coveralls, - Citation + Develop, + Documenter, + Git, + GitHubActions, + GitLabCI, + License, + ProjectFile, + Readme, + SrcDir, + Tests, + TravisCI """ -A plugin to be added to a [`Template`](@ref), which adds some functionality or integration. -New plugins should almost always extend [`GenericPlugin`](@ref) or [`CustomPlugin`](@ref). +Plugins are PkgTemplates' source of customization and extensibility. +Add plugins to your [`Template`](@ref)s to enable extra pieces of repository setup. + +When implementing a new plugin, subtype this type to have full control over its behaviour. """ abstract type Plugin end -include("licenses.jl") include("template.jl") -include("generate.jl") include("plugin.jl") -include(joinpath("plugins", "documenter.jl")) -include(joinpath("plugins", "coveralls.jl")) -include(joinpath("plugins", "appveyor.jl")) -include(joinpath("plugins", "codecov.jl")) -include(joinpath("plugins", "travisci.jl")) -include(joinpath("plugins", "gitlabci.jl")) -include(joinpath("plugins", "cirrusci.jl")) -include(joinpath("plugins", "droneci.jl")) -include(joinpath("plugins", "githubpages.jl")) -include(joinpath("plugins", "gitlabpages.jl")) -include(joinpath("plugins", "citation.jl")) - -const DEFAULTS_DIR = normpath(joinpath(@__DIR__, "..", "defaults")) -const BADGE_ORDER = [GitHubPages, GitLabPages, TravisCI, AppVeyor, GitLabCI, Codecov, Coveralls] +include("show.jl") + +# Run some function with a project activated at the given path. +function with_project(f::Function, path::AbstractString) + proj = active_project() + try + Pkg.activate(path) + f() + finally + proj === nothing ? Pkg.activate() : Pkg.activate(proj) + end +end end diff --git a/src/generate.jl b/src/generate.jl deleted file mode 100644 index 3ab577de..00000000 --- a/src/generate.jl +++ /dev/null @@ -1,359 +0,0 @@ -""" - generate(pkg::AbstractString, t::Template) -> Nothing - generate(t::Template, pkg::AbstractString) -> Nothing - -Generate a package named `pkg` from `t`. If `git` is `false`, no Git repository is created. -""" -function generate( - pkg::AbstractString, - t::Template; - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - pkg = splitjl(pkg) - pkg_dir = joinpath(t.dir, pkg) - ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) - - try - # Create the directory with some boilerplate inside. - Pkg.generate(pkg_dir) - - # Add a [compat] section for Julia. - open(joinpath(pkg_dir, "Project.toml"), "a") do io - println(io, "\n[compat]\njulia = $(repr_version(t.julia_version))") - end - - # Replace the authors field with the template's authors. - if !isempty(t.authors) - path = joinpath(pkg_dir, "Project.toml") - project = read(path, String) - authors = string("[", join(map(repr ∘ strip, split(t.authors, ",")), ", "), "]") - write(path, replace(project, r"authors = .*" => "authors = $authors")) - end - - if git - # Initialize the repo. - repo = LibGit2.init(pkg_dir) - @info "Initialized Git repo at $pkg_dir" - - if gitconfig !== nothing - # Configure the repo. - repoconfig = GitConfig(repo) - for c in LibGit2.GitConfigIter(gitconfig) - LibGit2.set!(repoconfig, unsafe_string(c.name), unsafe_string(c.value)) - end - end - - # Commit and set the remote. - LibGit2.commit(repo, "Initial commit") - rmt = if t.ssh - "git@$(t.host):$(t.user)/$pkg.jl.git" - else - "https://$(t.host)/$(t.user)/$pkg.jl" - end - # We need to set the remote in a strange way, see #8. - close(LibGit2.GitRemote(repo, "origin", rmt)) - @info "Set remote origin to $rmt" - - # Create the gh-pages branch if necessary. - if haskey(t.plugins, GitHubPages) - LibGit2.branch!(repo, "gh-pages") - LibGit2.commit(repo, "Initial commit") - @info "Created empty gh-pages branch" - LibGit2.branch!(repo, "master") - end - end - - # Generate the files. - files = vcat( - "src/", "Project.toml", # Created by Pkg.generate. - gen_tests(pkg_dir, t), - gen_readme(pkg_dir, t), - gen_license(pkg_dir, t), - vcat(map(p -> gen_plugin(p, t, pkg), values(t.plugins))...), - ) - - if git - append!(files, gen_gitignore(pkg_dir, t)) - LibGit2.add!(repo, files...) - LibGit2.commit(repo, "Files generated by PkgTemplates") - @info "Committed $(length(files)) files/directories: $(join(files, ", "))" - - - if length(collect(LibGit2.GitBranchIter(repo))) > 1 - @info "Remember to push all created branches to your remote: git push --all" - end - end - - if t.dev - # Add the new package to the current environment. - Pkg.develop(PackageSpec(path=pkg_dir)) - end - - @info "New package is at $pkg_dir" - catch e - rm(pkg_dir; recursive=true) - rethrow(e) - end -end - -function generate( - t::Template, - pkg::AbstractString; - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - generate(pkg, t; git=git, gitconfig=gitconfig) -end - -""" - generate_interactive(pkg::AbstractString; fast::Bool=false, git::Bool=true) -> Template - -Interactively create a template, and then generate a package with it. Arguments and -keywords are used in the same way as in [`generate`](@ref) and -[`interactive_template`](@ref). -""" -function generate_interactive( - pkg::AbstractString; - fast::Bool=false, - git::Bool=true, - gitconfig::Union{GitConfig, Nothing}=nothing, -) - t = interactive_template(; git=git, fast=fast) - generate(pkg, t; git=git, gitconfig=gitconfig) - return t -end - -""" - gen_tests(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create the test entrypoint in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The package directory in which the files will be generated -* `t::Template`: The template whose tests we are generating. - -Returns an array of generated file/directory names. -""" -function gen_tests(pkg_dir::AbstractString, t::Template) - # TODO: Silence Pkg for this section? Adding and removing Test creates a lot of noise. - proj = Base.current_project() - try - Pkg.activate(pkg_dir) - Pkg.add("Test") - - # Move the Test dependency into the [extras] section. - toml = read(joinpath(pkg_dir, "Project.toml"), String) - lines = split(toml, "\n") - idx = findfirst(l -> startswith(l, "Test = "), lines) - testdep = lines[idx] - deleteat!(lines, idx) - toml = join(lines, "\n") * """ - [extras] - $testdep - - [targets] - test = ["Test"] - """ - gen_file(joinpath(pkg_dir, "Project.toml"), toml) - Pkg.update() # Regenerate Manifest.toml (this cleans up Project.toml too). - finally - proj === nothing ? Pkg.activate() : Pkg.activate(proj) - end - - pkg = basename(pkg_dir) - text = """ - using $pkg - using Test - - @testset "$pkg.jl" begin - # Write your own tests here. - end - """ - - gen_file(joinpath(pkg_dir, "test", "runtests.jl"), text) - return ["test/"] -end - -""" - gen_readme(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a README in `pkg_dir` with badges for each enabled plugin. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose README we are generating. - -Returns an array of generated file/directory names. -""" -function gen_readme(pkg_dir::AbstractString, t::Template) - pkg = basename(pkg_dir) - text = "# $pkg\n" - done = [] - # Generate the ordered badges first, then add any remaining ones to the right. - for plugin_type in BADGE_ORDER - if haskey(t.plugins, plugin_type) - text *= "\n" - text *= join( - badges(t.plugins[plugin_type], t.user, pkg), - "\n", - ) - push!(done, plugin_type) - end - end - for plugin_type in setdiff(keys(t.plugins), done) - text *= "\n" - text *= join( - badges(t.plugins[plugin_type], t.user, pkg), - "\n", - ) - end - if haskey(t.plugins, Citation) && t.plugins[Citation].readme_section - text *= "\n## Citing\n\nSee `CITATION.bib` for the relevant reference(s).\n" - end - - - gen_file(joinpath(pkg_dir, "README.md"), text) - return ["README.md"] -end - -""" - gen_gitignore(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a `.gitignore` in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose .gitignore we are generating. - -Returns an array of generated file/directory names. -""" -function gen_gitignore(pkg_dir::AbstractString, t::Template) - pkg = basename(pkg_dir) - init = [".DS_Store", "/dev/"] - entries = mapfoldl(p -> p.gitignore, append!, values(t.plugins); init=init) - if !t.manifest && !in("Manifest.toml", entries) - push!(entries, "/Manifest.toml") # Only ignore manifests at the repo root. - end - unique!(sort!(entries)) - text = join(entries, "\n") - - gen_file(joinpath(pkg_dir, ".gitignore"), text) - files = [".gitignore"] - t.manifest && push!(files, "Manifest.toml") - return files -end - -""" - gen_license(pkg_dir::AbstractString, t::Template) -> Vector{String} - -Create a license in `pkg_dir`. - -# Arguments -* `pkg_dir::AbstractString`: The directory in which the files will be generated. -* `t::Template`: The template whose LICENSE we are generating. - -Returns an array of generated file/directory names. -""" -function gen_license(pkg_dir::AbstractString, t::Template) - if isempty(t.license) - return String[] - end - - text = "Copyright (c) $(year(today())) $(t.authors)\n" - text *= read_license(t.license) - - gen_file(joinpath(pkg_dir, "LICENSE"), text) - return ["LICENSE"] -end - -""" - gen_file(file::AbstractString, text::AbstractString) -> Int - -Create a new file containing some given text. Always ends the file with a newline. - -# Arguments -* `file::AbstractString`: Path to the file to be created. -* `text::AbstractString`: Text to write to the file. - -Returns the number of bytes written to the file. -""" -function gen_file(file::AbstractString, text::AbstractString) - mkpath(dirname(file)) - if !endswith(text , "\n") - text *= "\n" - end - return write(file, text) -end - -""" - version_floor(v::VersionNumber=VERSION) -> String - -Format the given Julia version. - -# Keyword arguments -* `v::VersionNumber=VERSION`: Version to floor. - -Returns "major.minor" for the most recent release version relative to v. For prereleases -with v.minor == v.patch == 0, returns "major.minor-". -""" -function version_floor(v::VersionNumber=VERSION) - return if isempty(v.prerelease) || v.patch > 0 - "$(v.major).$(v.minor)" - else - "$(v.major).$(v.minor)-" - end -end - -""" - substitute(template::AbstractString, view::Dict{String, Any}) -> String - substitute( - template::AbstractString, - pkg_template::Template; - view::Dict{String, Any}=Dict{String, Any}(), - ) -> String - -Replace placeholders in `template` with values in `view` via -[`Mustache`](https://github.com/jverzani/Mustache.jl). `template` is not modified. -If `pkg_template` is supplied, some default replacements are also performed. - -For information on how to structure `template`, see "Defining Template Files" section in -[Custom Plugins](@ref). - -**Note**: Conditionals in `template` without a corresponding key in `view` won't error, -but will simply be evaluated as false. -""" -substitute(template::AbstractString, view::Dict{String, Any}) = render(template, view) - -function substitute( - template::AbstractString, - pkg_template::Template; - view::Dict{String, Any}=Dict{String, Any}(), -) - # Don't use version_floor here because we don't want the trailing '-' on prereleases. - v = pkg_template.julia_version - d = Dict{String, Any}( - "USER" => pkg_template.user, - "VERSION" => "$(v.major).$(v.minor)", - "DOCUMENTER" => any(map(p -> isa(p, Documenter), values(pkg_template.plugins))), - "CODECOV" => haskey(pkg_template.plugins, Codecov), - "COVERALLS" => haskey(pkg_template.plugins, Coveralls), - ) - # d["AFTER"] is true whenever something needs to occur in a CI "after_script". - d["AFTER"] = d["DOCUMENTER"] || d["CODECOV"] || d["COVERALLS"] - # d["COVERAGE"] is true whenever a coverage plugin is enabled. - # TODO: This doesn't handle user-defined coverage plugins. - # Maybe we need an abstract CoveragePlugin <: GenericPlugin? - d["COVERAGE"] = d["CODECOV"] || d["COVERALLS"] - return substitute(template, merge(d, view)) -end - -splitjl(pkg::AbstractString) = endswith(pkg, ".jl") ? pkg[1:end-3] : pkg - -# Format a version in a way suitable for a Project.toml file. -function repr_version(v::VersionNumber) - s = string(v.major) - v.minor == 0 || (s *= ".$(v.minor)") - v.patch == 0 || (s *= ".$(v.patch)") - return repr(s) -end diff --git a/src/licenses.jl b/src/licenses.jl deleted file mode 100644 index 0ef1bd83..00000000 --- a/src/licenses.jl +++ /dev/null @@ -1,45 +0,0 @@ -const LICENSE_DIR = normpath(joinpath(@__DIR__, "..", "licenses")) -const LICENSES = Dict( - "MIT" => "MIT \"Expat\" License", - "BSD2" => "Simplified \"2-clause\" BSD License", - "BSD3" => "Modified \"3-clause\" BSD License", - "ISC" => "Internet Systems Consortium License", - "ASL" => "Apache License, Version 2.0", - "MPL" => "Mozilla Public License, Version 2.0", - "GPL-2.0+" => "GNU Public License, Version 2.0+", - "GPL-3.0+" => "GNU Public License, Version 3.0+", - "LGPL-2.1+" => "Lesser GNU Public License, Version 2.1+", - "LGPL-3.0+" => "Lesser GNU Public License, Version 3.0+", - "EUPL-1.2+" => "European Union Public Licence, Version 1.2+", -) - -""" - available_licenses([io::IO]) -> Nothing - -Print the names of all available licenses. -""" -available_licenses(io::IO) = print(io, join(("$k: $v" for (k, v) in LICENSES), "\n")) -available_licenses() = available_licenses(stdout) - -""" - show_license([io::IO], license::AbstractString) -> Nothing - -Print the text of `license`. Errors if the license is not found. -""" -show_license(io::IO, license::AbstractString) = print(io, read_license(license)) -show_license(license::AbstractString) = show_license(stdout, license) - -""" - read_license(license::AbstractString) -> String - -Returns the contents of `license`. Errors if the license is not found. Use -[`available_licenses`](@ref) to view available licenses. -""" -function read_license(license::AbstractString) - path = joinpath(LICENSE_DIR, license) - if isfile(path) - return string(readchomp(path)) - else - throw(ArgumentError("License '$license' is not available")) - end -end diff --git a/src/plugin.jl b/src/plugin.jl index 0fc082d0..a9f12f8a 100644 --- a/src/plugin.jl +++ b/src/plugin.jl @@ -1,156 +1,131 @@ +const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) +const DEFAULT_PRIORITY = 1000 + """ -Generic plugins are plugins that add any number of patterns to the generated package's -`.gitignore`, and have at most one associated file to generate. - -# Attributes -* `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of - generated packages that use this plugin. -* `src::Union{AbstractString, Nothing}`: Path to the file that will be copied into the generated - package repository. If set to `nothing`, no file will be generated. When this defaults - to an empty string, there should be a default file in `defaults` that will be copied. - That file's name is usually the same as the plugin's name, except in all lowercase and - with the `.yml` extension. If this is not the case, an `interactive` method needs to be - implemented to call `interactive(; file="file.ext")`. -* `dest::AbstractString`: Path to the generated file, relative to the root of the generated - package repository. -* `badges::Vector{Badge}`: Array of [`Badge`](@ref)s containing information used to - create Markdown-formatted badges from the plugin. Entries will be run through - [`substitute`](@ref), so they may contain placeholder values. -* `view::Dict{String, Any}`: Additional substitutions to make in both the plugin's badges - and its associated file. See [`substitute`](@ref) for details. - -# Example -```julia -struct MyPlugin <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{AbstractString, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - - function MyPlugin(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - joinpath(DEFAULTS_DIR, "my-plugin.toml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError( - "File \$(abspath(config_file)) does not exist" - )) - end - end - new( - ["*.mgp"], - config_file, - ".my-plugin.toml", - [ - Badge( - "My Plugin", - "https://myplugin.com/badge-{{YEAR}}.png", - "https://myplugin.com/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}("YEAR" => year(today())), - ) - end -end +A simple plugin that, in general, creates a single file. +""" +abstract type BasicPlugin <: Plugin end -interactive(::Type{MyPlugin}) = interactive(MyPlugin; file="my-plugin.toml") -``` +""" + default_file(paths::AbstractString...) -> String -The above plugin ignores files ending with `.mgp`, copies `defaults/my-plugin.toml` by -default, and creates a badge that links to the project on its own site, using the default -substitutions with one addition: `{{YEAR}} => year(today())`. Since the default config -template file doesn't follow the generic naming convention, we added another `interactive` -method to correct the assumed filename. +Return a path relative to the default template file directory +(`$(contractuser(TEMPLATES_DIR))`). """ -abstract type GenericPlugin <: Plugin end +default_file(paths::AbstractString...) = joinpath(TEMPLATES_DIR, paths...) -function Base.show(io::IO, p::GenericPlugin) - spc = " " - println(io, nameof(typeof(p)), ":") +""" + view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} - cfg = if p.src === nothing - "None" - else - dirname(p.src) == DEFAULTS_DIR ? "Default" : p.src - end - println(io, spc, "→ Config file: ", cfg) +Return the view to be passed to the text templating engine for this plugin. +`pkg` is the name of the package being generated. - n = length(p.gitignore) - s = n == 1 ? "" : "s" - print(io, spc, "→ $n gitignore entrie$s") - n > 0 && print(io, ": ", join(map(repr, p.gitignore), ", ")) -end +For [`BasicPlugin`](@ref)s, this is used for both the plugin badges +(see [`badges`](@ref)) and the template file (see [`source`](@ref)). +For other [`Plugin`](@ref)s, it is used only for badges, +but you can always call it yourself as part of your [`hook`](@ref) implementation. + +By default, an empty `Dict` is returned. +""" +view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() + +""" + user_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} + +The same as [`view`](@ref), but for use by package *users* for extension. +Values returned by this function will override those from [`view`](@ref) +when the keys are the same. """ -Custom plugins are plugins whose behaviour does not follow the [`GenericPlugin`](@ref) -pattern. They can implement [`gen_plugin`](@ref), [`badges`](@ref), and -[`interactive`](@ref) in any way they choose, as long as they conform to the usual type -signature. - -# Attributes -* `gitignore::Vector{AbstractString}`: Array of patterns to be added to the `.gitignore` of - generated packages that use this plugin. - -# Example -```julia -struct MyPlugin <: CustomPlugin - gitignore::Vector{AbstractString} - lucky::Bool - - MyPlugin() = new([], rand() > 0.8) - - function gen_plugin(p::MyPlugin, t::Template, pkg_name::AbstractString) - return if p.lucky - text = substitute("You got lucky with {{PKGNAME}}, {{USER}}!", t) - gen_file(joinpath(t.dir, pkg_name, ".myplugin.yml"), text) - [".myplugin.yml"] - else - println("Maybe next time.") - String[] - end - end - - function badges(p::MyPlugin, user::AbstractString, pkg_name::AbstractString) - return if p.lucky - [ - format(Badge( - "You got lucky!", - "https://myplugin.com/badge.png", - "https://myplugin.com/\$user/\$pkg_name.jl", - )), - ] - else - String[] - end - end +user_view(::Plugin, ::Template, ::AbstractString) = Dict{String, Any}() + +""" + combined_view(::Plugin, ::Template, pkg::AbstractString) -> Dict{String, Any} + +This function combines [`view`](@ref) and [`user_view`](@ref) for use in text templating. +If you're doing manual file creation or text templating (i.e. writing [`Plugin`](@ref)s +that are not [`BasicPlugin`](@ref)s), then you should use this function +rather than either of the former two. + +!!! note + Do not implement this function yourself! + If you're implementing a plugin, you should implement [`view`](@ref). + If you're customizing a plugin as a user, you should implement [`user_view`](@ref). +""" +function combined_view(p::Plugin, t::Template, pkg::AbstractString) + return merge(view(p, t, pkg), user_view(p, t, pkg)) end -interactive(:Type{MyPlugin}) = MyPlugin() -``` +""" + tags(::Plugin) -> Tuple{String, String} -This plugin doesn't do much, but it demonstrates how [`gen_plugin`](@ref), [`badges`](@ref) -and [`interactive`](@ref) can be implemented using [`substitute`](@ref), -[`gen_file`](@ref), [`Badge`](@ref), and [`format`](@ref). +Return the delimiters used for text templating. +See the [`Citation`](@ref) plugin for a rare case where changing the tags is necessary. -# Defining Template Files -Often, the contents of the config file that your plugin generates depends on variables like -the package name, the user's username, etc. Template files (which are stored in `defaults`) -can use [here](https://github.com/jverzani/Mustache.jl)'s syntax to define replacements. +By default, the tags are `"{{"` and `"}}"`. """ -abstract type CustomPlugin <: Plugin end +tags(::Plugin) = "{{", "}}" """ - Badge(hover::AbstractString, image::AbstractString, link::AbstractString) -> Badge + priority(::Plugin, ::Union{typeof(prehook), typeof(hook), typeof(posthook)}) -> Int -A `Badge` contains the data necessary to generate a Markdown badge. +Determines the order in which plugins are processed (higher goes first). +The default priority (`DEFAULT_PRIORITY`), is `$DEFAULT_PRIORITY`. -# Arguments -* `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. -* `image::AbstractString`: URL to the image to display. -* `link::AbstractString`: URL to go to upon clicking the badge. +You can implement this function per-stage (by using `::typeof(hook)`, for example), +or for all stages by simply using `::Function`. +""" +priority(::Plugin, ::Function) = DEFAULT_PRIORITY + +""" + gitignore(::Plugin) -> Vector{String} + +Return patterns that should be added to `.gitignore`. +These are used by the [`Git`](@ref) plugin. + +By default, an empty list is returned. +""" +gitignore(::Plugin) = String[] + +""" + badges(::Plugin) -> Union{Badge, Vector{Badge}} + +Return a list of [`Badge`](@ref)s, or just one, to be added to `README.md`. +These are used by the [`Readme`](@ref) plugin to add badges to the README. + +By default, an empty list is returned. +""" +badges(::Plugin) = Badge[] + +""" + source(::BasicPlugin) -> Union{String, Nothing} + +Return the path to a plugin's template file, or `nothing` to indicate no file. + +By default, `nothing` is returned. +""" +source(::BasicPlugin) = nothing + +""" + destination(::BasicPlugin) -> String + +Return the destination, relative to the package root, of a plugin's configuration file. + +This function **must** be implemented. +""" +function destination end + +""" + Badge(hover::AbstractString, image::AbstractString, link::AbstractString) + +Container for Markdown badge data. +Each argument can contain placeholders, +which will be filled in with values from [`combined_view`](@ref). + +## Arguments +- `hover::AbstractString`: Text to appear when the mouse is hovered over the badge. +- `image::AbstractString`: URL to the image to display. +- `link::AbstractString`: URL to go to upon clicking the badge. """ struct Badge hover::String @@ -158,89 +133,132 @@ struct Badge link::String end +Base.string(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" + +# Format a plugin's badges as a list of strings, with all substitutions applied. +function badges(p::Plugin, t::Template, pkg::AbstractString) + bs = badges(p) + bs isa Vector || (bs = [bs]) + return map(b -> render_text(string(b), combined_view(p, t, pkg)), bs) +end + """ - format(b::Badge) -> String + validate(::Plugin, ::Template) + +Perform any required validation for a [`Plugin`](@ref). -Return `badge`'s data formatted as a Markdown string. +It is preferred to do validation here instead of in [`prehook`](@ref), +because this function is called at [`Template`](@ref) construction time, +whereas the prehook is only run at package generation time. """ -format(b::Badge) = "[![$(b.hover)]($(b.image))]($(b.link))" +validate(::Plugin, ::Template) = nothing """ - gen_plugin(p::Plugin, t::Template, pkg_name::AbstractString) -> Vector{String} + prehook(::Plugin, ::Template, pkg_dir::AbstractString) -Generate any files associated with a plugin. +Stage 1 of the package generation process (the "before" stage, in general). +At this point, `pkg_dir` is an empty directory that will eventually contain the package, +and neither the [`hook`](@ref)s nor the [`posthook`](@ref)s have run. -# Arguments -* `p::Plugin`: Plugin whose files are being generated. -* `t::Template`: Template configuration. -* `pkg_name::AbstractString`: Name of the package. +!!! note + `pkg_dir` only stays empty until the first plugin chooses to create a file. + See also: [`priority`](@ref). +""" +prehook(::Plugin, ::Template, ::AbstractString) = nothing -Returns an array of generated file/directory names. """ -gen_plugin(::Plugin, ::Template, ::AbstractString) = String[] + hook(::Plugin, ::Template, pkg_dir::AbstractString) -function gen_plugin(p::GenericPlugin, t::Template, pkg_name::AbstractString) - if p.src === nothing - return String[] - end - text = substitute( - read(p.src, String), - t; - view=merge(Dict("PKGNAME" => pkg_name), p.view), - ) - gen_file(joinpath(t.dir, pkg_name, p.dest), text) - return [p.dest] -end +Stage 2 of the package generation pipeline (the "main" stage, in general). +At this point, the [`prehook`](@ref)s have run, but not the [`posthook`](@ref)s. + +`pkg_dir` is the directory in which the package is being generated +(so `basename(pkg_dir)` is the package name). + +!!! note + You usually shouldn't implement this function for [`BasicPlugin`](@ref)s. + If you do, it should probably `invoke` the generic method + (otherwise, there's not much reason to subtype `BasicPlugin`). +""" +hook(::Plugin, ::Template, ::AbstractString) = nothing + +""" + posthook(::Plugin, ::Template, pkg_dir::AbstractString) +Stage 3 of the package generation pipeline (the "after" stage, in general). +At this point, both the [`prehook`](@ref)s and [`hook`](@ref)s have run. """ - badges(p::Plugin, user::AbstractString, pkg_name::AbstractString) -> Vector{String} +posthook(::Plugin, ::Template, ::AbstractString) = nothing -Generate Markdown badges for the plugin. +function validate(p::T, ::Template) where T <: BasicPlugin + src = source(p) + src === nothing && return + isfile(src) || throw(ArgumentError("$(nameof(T)): The file $src does not exist")) +end -# Arguments -* `p::Plugin`: Plugin whose badges we are generating. -* `user::AbstractString`: Username of the package creator. -* `pkg_name::AbstractString`: Name of the package. +function hook(p::BasicPlugin, t::Template, pkg_dir::AbstractString) + source(p) === nothing && return + pkg = basename(pkg_dir) + path = joinpath(pkg_dir, destination(p)) + text = render_plugin(p, t, pkg) + gen_file(path, text) +end + +function render_plugin(p::BasicPlugin, t::Template, pkg::AbstractString) + return render_file(source(p), combined_view(p, t, pkg), tags(p)) +end -Returns an array of Markdown badges. """ -badges(::Plugin, ::AbstractString, ::AbstractString) = String[] + gen_file(file::AbstractString, text::AbstractString) -function badges(p::GenericPlugin, user::AbstractString, pkg_name::AbstractString) - # Give higher priority to replacements defined in the plugin's view. - view = merge(Dict("USER" => user, "PKGNAME" => pkg_name), p.view) - return map(b -> substitute(format(b), view), p.badges) +Create a new file containing some given text. +Trailing whitespace is removed, and the file will end with a newline. +""" +function gen_file(file::AbstractString, text::AbstractString) + mkpath(dirname(file)) + text = strip(join(map(rstrip, split(text, "\n")), "\n")) * "\n" + write(file, text) end """ - interactive(T::Type{<:Plugin}; file::Union{AbstractString, Nothing}="") -> Plugin - -Interactively create a plugin of type `T`, where `file` is the plugin type's default -config template with a non-standard name (for `MyPlugin`, this is anything but -"myplugin.yml"). -""" -function interactive(T::Type{<:GenericPlugin}; file::Union{AbstractString, Nothing}="") - name = string(nameof(T)) - # By default, we expect the default plugin file template for a plugin called - # "MyPlugin" to be called "myplugin.yml". - fn = file != nothing && isempty(file) ? "$(lowercase(name)).yml" : file - default_config_file = fn == nothing ? fn : joinpath(DEFAULTS_DIR, fn) - - print("$name: Enter the config template filename (\"None\" for no file) ") - if default_config_file == nothing - print("[None]: ") - else - print("[", replace(default_config_file, homedir() => "~"), "]: ") - end - - config_file = readline() - config_file = if uppercase(config_file) == "NONE" - nothing - elseif isempty(config_file) - default_config_file - else - config_file - end - - return T(; config_file=config_file) + render_file(file::AbstractString view::Dict{<:AbstractString}, tags) -> String + +Render a template file with the data in `view`. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, +or `nothing` to use the default delimiters. +""" +function render_file(file::AbstractString, view::Dict{<:AbstractString}, tags) + return render_text(read(file, String), view, tags) end + +""" + render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) -> String + +Render some text with the data in `view`. +`tags` should be a tuple of two strings, which are the opening and closing delimiters, +or `nothing` to use the default delimiters. +""" +function render_text(text::AbstractString, view::Dict{<:AbstractString}, tags=nothing) + return tags === nothing ? render(text, view) : render(text, view; tags=tags) +end + +""" + needs_username(::Plugin) -> Bool + +Determine whether or not a plugin needs a Git hosting service username to function correctly. +If you are implementing a plugin that uses the `user` field of a [`Template`](@ref), +you should implement this function and return `true`. +""" +needs_username(::Plugin) = false + +include(joinpath("plugins", "project_file.jl")) +include(joinpath("plugins", "src_dir.jl")) +include(joinpath("plugins", "tests.jl")) +include(joinpath("plugins", "readme.jl")) +include(joinpath("plugins", "license.jl")) +include(joinpath("plugins", "git.jl")) +include(joinpath("plugins", "develop.jl")) +include(joinpath("plugins", "coverage.jl")) +include(joinpath("plugins", "ci.jl")) +include(joinpath("plugins", "citation.jl")) +include(joinpath("plugins", "documenter.jl")) diff --git a/src/plugins/appveyor.jl b/src/plugins/appveyor.jl deleted file mode 100644 index 7b42767b..00000000 --- a/src/plugins/appveyor.jl +++ /dev/null @@ -1,42 +0,0 @@ -""" - AppVeyor(; config_file::Union{AbstractString, Nothing}="") -> AppVeyor - -Add `AppVeyor` to a template's plugins to add a `.appveyor.yml` configuration file to -generated repositories, and an appropriate badge to the README. - -# Keyword Arguments -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.appveyor.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct AppVeyor <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function AppVeyor(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "appveyor.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - [], - config_file, - ".appveyor.yml", - [ - Badge( - "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl", - ) - ], - Dict{String, Any}(), - ) - end -end diff --git a/src/plugins/ci.jl b/src/plugins/ci.jl new file mode 100644 index 00000000..de18b96d --- /dev/null +++ b/src/plugins/ci.jl @@ -0,0 +1,412 @@ +""" + format_version(v::Union{VersionNumber, AbstractString}) -> String + +Strip everything but the major and minor release from a `VersionNumber`. +Strings are left in their original form. +""" +format_version(v::VersionNumber) = "$(v.major).$(v.minor)" +format_version(v::AbstractString) = string(v) + +const ALLOWED_FAILURES = ["1.3", "nightly"] # TODO: Update this list with new RCs. +const DEFAULT_CI_VERSIONS = map(format_version, [default_version(), VERSION, "nightly"]) +const DEFAULT_CI_VERSIONS_NO_NIGHTLY = map(format_version, [default_version(), VERSION]) +const EXTRA_VERSIONS_DOC = "- `extra_versions::Vector`: Extra Julia versions to test, as strings or `VersionNumber`s." + +""" + GitHubActions(; + file="$(contractuser(default_file("github", "workflows", "ci.yml")))", + destination="ci.yml", + linux=true, + osx=true, + windows=true, + x64=true, + x86=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, + ) + +Integrates your packages with [GitHub Actions](https://github.com/features/actions). + +## Keyword Arguments +- `file::AbstractString`: Template file for the workflow file. +- `destination::AbstractString`: Destination of the worflow file, + relative to `.github/workflows`. +- `linux::Bool`: Whether or not to run builds on Linux. +- `osx::Bool`: Whether or not to run builds on OSX (MacOS). +- `windows::Bool`: Whether or not to run builds on Windows. +- `x64::Bool`: Whether or not to run builds on 64-bit architecture. +- `x86::Bool`: Whether or not to run builds on 32-bit architecture. +- `coverage::Bool`: Whether or not to publish code coverage. + Another code coverage plugin such as [`Codecov`](@ref) must also be included. +$EXTRA_VERSIONS_DOC + +!!! note + If using coverage plugins, don't forget to manually add your API tokens as secrets, + as described [here](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets#creating-encrypted-secrets). + +!!! note + Nightly Julia is not supported. +""" +@with_kw_noshow struct GitHubActions <: BasicPlugin + file::String = default_file("github", "workflows", "ci.yml") + destination::String = "ci.yml" + linux::Bool = true + osx::Bool = true + windows::Bool = true + x64::Bool = true + x86::Bool = false + coverage::Bool = true + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY +end + +source(p::GitHubActions) = p.file +destination(p::GitHubActions) = joinpath(".github", "workflows", p.destination) + +tags(::GitHubActions) = "<<", ">>" + +badges(p::GitHubActions) = Badge( + "Build Status", + "https://github.com/{{{USER}}}/{{{PKG}}}.jl/actions", + "https://github.com/{{{USER}}}/{{{PKG}}}.jl/workflows/CI/badge.svg", +) + +function view(p::GitHubActions, t::Template, pkg::AbstractString) + os = String[] + p.linux && push!(os, "ubuntu-latest") + p.osx && push!(os, "macOS-latest") + p.windows && push!(os, "windows-latest") + arch = filter(a -> getfield(p, Symbol(a)), ["x64", "x86"]) + excludes = Dict{String, String}[] + p.osx && p.x86 && push!(excludes, Dict("E_OS" => "macOS-latest", "E_ARCH" => "x86")) + + return Dict( + "ARCH" => arch, + "EXCLUDES" => excludes, + "HAS_CODECOV" => p.coverage && hasplugin(t, Codecov), + "HAS_COVERALLS" => p.coverage && hasplugin(t, Coveralls), + "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitHubActions}), + "HAS_EXCLUDES" => !isempty(excludes), + "OS" => os, + "PKG" => pkg, + "USER" => t.user, + "VERSIONS" => collect_versions(t, p.extra_versions), + ) +end + +""" + TravisCI(; + file="$(contractuser(default_file("travis.yml")))", + linux=true, + osx=true, + windows=true, + x64=true, + x86=false, + arm64=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) + +Integrates your packages with [Travis CI](https://travis-ci.com). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.travis.yml`. +- `linux::Bool`: Whether or not to run builds on Linux. +- `osx::Bool`: Whether or not to run builds on OSX (MacOS). +- `windows::Bool`: Whether or not to run builds on Windows. +- `x64::Bool`: Whether or not to run builds on 64-bit architecture. +- `x86::Bool`: Whether or not to run builds on 32-bit architecture. +- `arm64::Bool`: Whether or not to run builds on the ARM64 architecture. +- `coverage::Bool`: Whether or not to publish code coverage. + Another code coverage plugin such as [`Codecov`](@ref) must also be included. +$EXTRA_VERSIONS_DOC +""" +@with_kw_noshow struct TravisCI <: BasicPlugin + file::String = default_file("travis.yml") + linux::Bool = true + osx::Bool = true + windows::Bool = true + x64::Bool = true + x86::Bool = false + arm64::Bool = false + coverage::Bool = true + extra_versions::Vector = 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) + os = filter(o -> getfield(p, Symbol(o)), ["linux", "osx", "windows"]) + arch = filter(a -> getfield(p, Symbol(a)), ["x64", "x86", "arm64"]) + versions = collect_versions(t, p.extra_versions) + allow_failures = filter(in(versions), ALLOWED_FAILURES) + + excludes = Dict{String, String}[] + p.x86 && p.osx && push!(excludes, Dict("E_OS" => "osx", "E_ARCH" => "x86")) + if p.arm64 + p.osx && push!(excludes, Dict("E_OS" => "osx", "E_ARCH" => "arm64")) + p.windows && push!(excludes, Dict("E_OS" => "windows", "E_ARCH" => "arm64")) + "nightly" in versions && push!(excludes, Dict("E_JULIA" => "nightly", "E_ARCH" => "arm64")) + end + + return Dict( + "ALLOW_FAILURES" => allow_failures, + "ARCH" => arch, + "EXCLUDES" => excludes, + "HAS_ALLOW_FAILURES" => !isempty(allow_failures), + "HAS_CODECOV" => hasplugin(t, Codecov), + "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), + "HAS_COVERALLS" => hasplugin(t, Coveralls), + "HAS_DOCUMENTER" => hasplugin(t, Documenter{TravisCI}), + "HAS_EXCLUDES" => !isempty(excludes), + "OS" => os, + "PKG" => pkg, + "USER" => t.user, + "VERSION" => format_version(t.julia), + "VERSIONS" => versions, + ) +end + +""" + AppVeyor(; + file="$(contractuser(default_file("appveyor.yml")))", + x86=false, + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) + +Integrates your packages with [AppVeyor](https://appveyor.com) +via [AppVeyor.jl](https://github.com/JuliaCI/Appveyor.jl). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.appveyor.yml`. +- `x86::Bool`: Whether or not to run builds on 32-bit systems, + in addition to the default 64-bit builds. +- `coverage::Bool`: Whether or not to publish code coverage. + [`Codecov`](@ref) must also be included. +$EXTRA_VERSIONS_DOC +""" +@with_kw_noshow struct AppVeyor <: BasicPlugin + file::String = default_file("appveyor.yml") + x86::Bool = false + coverage::Bool = true + extra_versions::Vector = 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", +) + +function view(p::AppVeyor, t::Template, pkg::AbstractString) + platforms = ["x64"] + p.x86 && push!(platforms, "x86") + + versions = collect_versions(t, p.extra_versions) + allow_failures = filter(in(versions), ALLOWED_FAILURES) + + return Dict( + "ALLOW_FAILURES" => allow_failures, + "HAS_ALLOW_FAILURES" => !isempty(allow_failures), + "HAS_CODECOV" => p.coverage && hasplugin(t, Codecov), + "PKG" => pkg, + "PLATFORMS" => platforms, + "USER" => t.user, + "VERSIONS" => versions, + ) +end + +""" + CirrusCI(; + file="$(contractuser(default_file("cirrus.yml")))", + image="freebsd-12-0-release-amd64", + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS, + ) + +Integrates your packages with [Cirrus CI](https://cirrus-ci.org) +via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.cirrus.yml`. +- `image::AbstractString`: The FreeBSD image to be used. +- `coverage::Bool`: Whether or not to publish code coverage. + [`Codecov`](@ref) must also be included. +$EXTRA_VERSIONS_DOC + +!!! note + Code coverage submission from Cirrus CI is not yet supported by + [Coverage.jl](https://github.com/JuliaCI/Coverage.jl). +""" +@with_kw_noshow struct CirrusCI <: BasicPlugin + file::String = default_file("cirrus.yml") + image::String = "freebsd-12-0-release-amd64" + coverage::Bool = true + extra_versions::Vector = 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}}}/{{{PKG}}}.jl.svg", + "https://cirrus-ci.com/github/{{{USER}}}/{{{PKG}}}.jl", +) + +function view(p::CirrusCI, t::Template, pkg::AbstractString) + return Dict( + "HAS_CODECOV" => hasplugin(t, Codecov), + "HAS_COVERALLS" => hasplugin(t, Coveralls), + "HAS_COVERAGE" => p.coverage && hasplugin(t, is_coverage), + "IMAGE" => p.image, + "PKG" => pkg, + "USER" => t.user, + "VERSIONS" => collect_versions(t, p.extra_versions), + ) +end + +""" + GitLabCI(; + file="$(contractuser(default_file("gitlab-ci.yml")))", + coverage=true, + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, + ) + +Integrates your packages with [GitLab CI](https://docs.gitlab.com/ce/ci). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.gitlab-ci.yml`. +- `coverage::Bool`: Whether or not to compute code coverage. +$EXTRA_VERSIONS_DOC + +## GitLab Pages +Documentation can be generated by including a `Documenter{GitLabCI}` plugin. +See [`Documenter`](@ref) for more information. + +!!! note + Nightly Julia is not supported. +""" +@with_kw_noshow struct GitLabCI <: BasicPlugin + file::String = default_file("gitlab-ci.yml") + coverage::Bool = true + # Nightly has no Docker image. + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY +end + +gitignore(p::GitLabCI) = p.coverage ? COVERAGE_GITIGNORE : String[] + +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 + +function view(p::GitLabCI, t::Template, pkg::AbstractString) + return Dict( + "HAS_COVERAGE" => p.coverage, + "HAS_DOCUMENTER" => hasplugin(t, Documenter{GitLabCI}), + "PKG" => pkg, + "USER" => t.user, + "VERSION" => format_version(t.julia), + "VERSIONS" => collect_versions(t, p.extra_versions), + ) +end + +""" + DroneCI(; + file="$(contractuser(default_file("drone.star")))", + amd64=true, + arm=false, + arm64=false, + extra_versions=$DEFAULT_CI_VERSIONS_NO_NIGHTLY, + ) + +Integrates your packages with [Drone CI](https://drone.io). + +## Keyword Arguments +- `file::AbstractString`: Template file for `.drone.star`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, you might want to generate a `.drone.yml` instead of the default Starlark file. +- `amd64::Bool`: Whether or not to run builds on AMD64. +- `arm::Bool`: Whether or not to run builds on ARM (32-bit). +- `arm64::Bool`: Whether or not to run builds on ARM64. +$EXTRA_VERSIONS_DOC + +!!! note + Nightly Julia is not supported. +""" +@with_kw_noshow struct DroneCI <: BasicPlugin + file::String = default_file("drone.star") + destination::String = ".drone.star" + amd64::Bool = true + arm::Bool = false + arm64::Bool = false + extra_versions::Vector = DEFAULT_CI_VERSIONS_NO_NIGHTLY +end + +source(p::DroneCI) = p.file +destination(p::DroneCI) = p.destination + +badges(::DroneCI) = Badge( + "Build Status", + "https://cloud.drone.io/api/badges/{{{USER}}}/{{{PKG}}}.jl/status.svg", + "https://cloud.drone.io/{{{USER}}}/{{{PKG}}}.jl", +) + +function view(p::DroneCI, t::Template, pkg::AbstractString) + arches = String[] + p.amd64 && push!(arches, "amd64") + p.arm && push!(arches, "arm") + p.arm64 && push!(arches, "arm64") + + return Dict( + "ARCHES" => join(map(repr, arches), ", "), + "PKG" => pkg, + "USER" => t.user, + "VERSIONS" => join(map(repr, collect_versions(t, p.extra_versions)), ", "), + ) +end + +""" + collect_versions(t::Template, versions::Vector) -> Vector{String} + +Combine `t`'s Julia version with `versions`, and format them as `major.minor`. +This is useful for creating lists of versions to be included in CI configurations. +""" +function collect_versions(t::Template, versions::Vector) + vs = map(format_version, [t.julia, versions...]) + return sort(unique(vs)) +end + +""" + is_ci(::Plugin) -> Bool + +Determine whether or not a plugin is a CI plugin. +If you are adding a CI plugin, you should implement this function and return `true`. +""" +is_ci(::Plugin) = false +is_ci(::Union{AppVeyor, GitHubActions, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true + +needs_username(::Union{AppVeyor, GitHubActions, TravisCI, CirrusCI, GitLabCI, DroneCI}) = true diff --git a/src/plugins/cirrusci.jl b/src/plugins/cirrusci.jl deleted file mode 100644 index 7daca529..00000000 --- a/src/plugins/cirrusci.jl +++ /dev/null @@ -1,45 +0,0 @@ -""" - CirrusCI(; config_file::Union{AbstractString, Nothing}="") -> CirrusCI - -Add `CirrusCI` to a template's plugins to add a `.cirrus.yml` configuration file to -generated repositories, and an appropriate badge to the README. The default configuration -file supports only FreeBSD builds via [CirrusCI.jl](https://github.com/ararslan/CirrusCI.jl) - -# Keyword Arguments -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.cirrus.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct CirrusCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function CirrusCI(; config_file::Union{AbstractString, Nothing}="") - if config_file !== nothing - config_file = if isempty(config_file) - joinpath(DEFAULTS_DIR, "cirrus.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - return new( - [], - config_file, - ".cirrus.yml", - [ - Badge( - "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{CirrusCI}) = interactive(CirrusCI; file="cirrus.yml") diff --git a/src/plugins/citation.jl b/src/plugins/citation.jl index 761a493c..805d446b 100644 --- a/src/plugins/citation.jl +++ b/src/plugins/citation.jl @@ -1,50 +1,28 @@ """ - Citation(; readme_section::Bool=false) + Citation(; file="$(contractuser(default_file("CITATION.bib")))", readme=false) -Add `Citation` to a template's plugins to add a `CITATION.bib` file to -generated repositories, and an appropriate section in the README. +Creates a `CITATION.bib` file for citing package repositories. -# Keyword Arguments: -* `readme_section::Bool=false`: whether to add a section in the readme pointing to `CITATION.bib`. +## Keyword Arguments +- `file::AbstractString`: Template file for `CITATION.bib`. +- `readme::Bool`: Whether or not to include a section about citing in the README. """ -struct Citation <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{String, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - readme_section::Bool - function Citation(; readme_section::Bool=false) - new( - [], - nothing, - "CITATION.bib", - [], - Dict{String, Any}(), - readme_section, - ) - end +@with_kw_noshow struct Citation <: BasicPlugin + file::String = default_file("CITATION.bib") + readme::Bool = false end -function interactive(::Type{Citation}) - print("Citation: Add a section to README.md mentioning CITATION.bib? [no]: ") - readme = uppercase(readline()) in ["Y", "YES", "TRUE"] - return Citation(; readme_section=readme) -end +tags(::Citation) = "<<", ">>" +source(p::Citation) = p.file +destination(::Citation) = "CITATION.bib" -function gen_plugin(p::Citation, t::Template, pkg_name::AbstractString) - pkg_dir = joinpath(t.dir, pkg_name) - text = """ - @misc{$pkg_name.jl, - \tauthor = {$(t.authors)}, - \ttitle = {{$(pkg_name).jl}}, - \turl = {https://$(t.host)/$(t.user)/$(pkg_name).jl}, - \tversion = {v0.1.0}, - \tyear = {$(year(today()))}, - \tmonth = {$(month(today()))} - } - """ - gen_file(joinpath(pkg_dir, "CITATION.bib"), text) - return ["CITATION.bib"] -end +view(::Citation, t::Template, pkg::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "MONTH" => month(today()), + "PKG" => pkg, + "URL" => "https://$(t.host)/$(t.user)/$pkg.jl", + "YEAR" => year(today()), +) + +needs_username(::Citation) = true diff --git a/src/plugins/codecov.jl b/src/plugins/codecov.jl deleted file mode 100644 index 7865c3d4..00000000 --- a/src/plugins/codecov.jl +++ /dev/null @@ -1,44 +0,0 @@ -""" - Codecov(; config_file::Union{AbstractString, Nothing}=nothing) -> Codecov - -Add `Codecov` to a template's plugins to optionally add a `.codecov.yml` configuration file -to generated repositories, and an appropriate badge to the README. Also updates the -`.gitignore` accordingly. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=nothing`: Path to a custom `.codecov.yml`. - If left unset, no file will be generated. -""" -struct Codecov <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function Codecov(; config_file::Union{AbstractString, Nothing}=nothing) - if config_file != nothing - config_file = if isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], - config_file, - ".codecov.yml", - [ - Badge( - "Codecov", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end -Base.@deprecate_binding CodeCov Codecov - -interactive(::Type{Codecov}) = interactive(Codecov; file=nothing) diff --git a/src/plugins/coverage.jl b/src/plugins/coverage.jl new file mode 100644 index 00000000..50674bbd --- /dev/null +++ b/src/plugins/coverage.jl @@ -0,0 +1,58 @@ +const COVERAGE_GITIGNORE = ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] + +""" + Codecov(; file=nothing) + +Sets up code coverage submission from CI to [Codecov](https://codecov.io). + +## Keyword Arguments +- `file::Union{AbstractString, Nothing}`: Template file for `.codecov.yml`, + or `nothing` to create no file. +""" +@with_kw_noshow struct Codecov <: BasicPlugin + file::Union{String, Nothing} = nothing +end + +source(p::Codecov) = p.file +destination(::Codecov) = ".codecov.yml" + +badges(::Codecov) = Badge( + "Coverage", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl/branch/master/graph/badge.svg", + "https://codecov.io/gh/{{{USER}}}/{{{PKG}}}.jl", +) + +""" + Coveralls(; file=nothing) + +Sets up code coverage submission from CI to [Coveralls](https://coveralls.io). + +## Keyword Arguments +- `file::Union{AbstractString, Nothing}`: Template file for `.coveralls.yml`, + or `nothing` to create no file. +""" +@with_kw_noshow struct Coveralls <: BasicPlugin + file::Union{String, Nothing} = nothing +end + +source(p::Coveralls) = p.file +destination(::Coveralls) = ".coveralls.yml" + +badges(::Coveralls) = Badge( + "Coverage", + "https://coveralls.io/repos/github/{{{USER}}}/{{{PKG}}}.jl/badge.svg?branch=master", + "https://coveralls.io/github/{{{USER}}}/{{{PKG}}}.jl?branch=master", +) + +gitignore(::Union{Codecov, Coveralls}) = COVERAGE_GITIGNORE + +""" + is_coverage(::Plugin) -> Bool + +Determine whether or not a plugin is a coverage plugin. +If you are adding a coverage plugin, you should implement this function and return `true`. +""" +is_coverage(::Plugin) = false +is_coverage(::Union{Codecov, Coveralls}) = true + +needs_username(::Union{Codecov, Coveralls}) = true diff --git a/src/plugins/coveralls.jl b/src/plugins/coveralls.jl deleted file mode 100644 index 8be6392e..00000000 --- a/src/plugins/coveralls.jl +++ /dev/null @@ -1,43 +0,0 @@ -""" - Coveralls(; config_file::Union{AbstractString, Nothing}=nothing) -> Coveralls - -Add `Coveralls` to a template's plugins to optionally add a `.coveralls.yml` configuration -file to generated repositories, and an appropriate badge to the README. Also updates the -`.gitignore` accordingly. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=nothing`: Path to a custom `.coveralls.yml`. - If left unset, no file will be generated. -""" -struct Coveralls <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function Coveralls(; config_file::Union{AbstractString, Nothing}=nothing) - if config_file != nothing - config_file = if isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"], - config_file, - ".coveralls.yml", - [ - Badge( - "Coveralls", - "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{Coveralls}) = interactive(Coveralls; file=nothing) diff --git a/src/plugins/develop.jl b/src/plugins/develop.jl new file mode 100644 index 00000000..835f2717 --- /dev/null +++ b/src/plugins/develop.jl @@ -0,0 +1,13 @@ +""" + Develop() + +Adds generated packages to the current environment by `dev`ing them. +See the Pkg documentation +[here](https://julialang.github.io/Pkg.jl/v1/managing-packages/#Developing-packages-1) +for more details. +""" +struct Develop <: Plugin end + +function posthook(::Develop, ::Template, pkg_dir::AbstractString) + Pkg.develop(PackageSpec(; path=pkg_dir)) +end diff --git a/src/plugins/documenter.jl b/src/plugins/documenter.jl index c8b3195a..227e39df 100644 --- a/src/plugins/documenter.jl +++ b/src/plugins/documenter.jl @@ -1,127 +1,138 @@ -const DOCUMENTER_UUID = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -const STANDARD_KWS = [:modules, :format, :pages, :repo, :sitename, :authors, :assets] +const DOCUMENTER_DEP = PackageSpec(; + name="Documenter", + uuid="e30172f5-a6a5-5a46-863b-614d45cd2de4", +) -""" -Add a `Documenter` subtype to a template's plugins to add support for documentation -generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). - -By default, the plugin generates a minimal index.md and a make.jl file. The make.jl -file contains the Documenter.makedocs command with predefined values for `modules`, -`format`, `pages`, `repo`, `sitename`, and `authors`. - -The subtype is expected to include the following fields: -* `assets::Vector{AbstractString}`, a list of filenames to be included as the `assets` -kwarg to `makedocs` -* `gitignore::Vector{AbstractString}`, a list of files to be added to the `.gitignore` +const DeployStyle = Union{TravisCI, GitHubActions, GitLabCI, Nothing} +const GitHubPagesStyle = Union{TravisCI, GitHubActions} -It may optionally include the field `additional_kwargs::Union{AbstractDict, NamedTuple}` -to allow additional kwargs to be added to `makedocs`. """ -abstract type Documenter <: CustomPlugin end - -function gen_plugin(p::Documenter, t::Template, pkg_name::AbstractString) - path = joinpath(t.dir, pkg_name) - docs_dir = joinpath(path, "docs") - mkpath(docs_dir) - - # Create the documentation project. - proj = Base.current_project() - try - Pkg.activate(docs_dir) - Pkg.add(PackageSpec(; name="Documenter", uuid=DOCUMENTER_UUID)) - finally - proj === nothing ? Pkg.activate() : Pkg.activate(proj) + Documenter{T<:Union{TravisCI, GitLabCI, Nothing}}(; + make_jl="$(contractuser(default_file("docs", "make.jl")))", + index_md="$(contractuser(default_file("docs", "src", "index.md")))", + assets=String[], + canonical_url=make_canonical(T), + makedocs_kwargs=Dict{Symbol, Any}(), + ) + +Sets up documentation generation via [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl). +Documentation deployment depends on `T`, where `T` is some supported CI plugin, +or `Nothing` to only support local documentation builds. + +## Supported Type Parameters +- `GitHubActions`: Deploys documentation to [GitHub Pages](https://pages.github.com) + with the help of [`GitHubActions`](@ref). +- `TravisCI`: Deploys documentation to [GitHub Pages](https://pages.github.com) + with the help of [`TravisCI`](@ref). +- `GitLabCI`: Deploys documentation to [GitLab Pages](https://pages.gitlab.com) + with the help of [`GitLabCI`](@ref). +- `Nothing` (default): Does not set up documentation deployment. + +## Keyword Arguments +- `make_jl::AbstractString`: Template file for `make.jl`. +- `index_md::AbstractString`: Template file for `index.md`. +- `assets::Vector{<:AbstractString}`: Extra assets for the generated site. +- `canonical_url::Union{Function, Nothing}`: A function to generate the site's canonical URL. + The default value will compute GitHub Pages and GitLab Pages URLs + for [`TravisCI`](@ref) and [`GitLabCI`](@ref), respectively. + If set to `nothing`, no canonical URL is set. +- `makedocs_kwargs::Dict{Symbol}`: Extra keyword arguments to be inserted into `makedocs`. + +!!! note + If deploying documentation with Travis CI, don't forget to complete + [the required configuration](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1). +""" +struct Documenter{T<:DeployStyle} <: Plugin + assets::Vector{String} + makedocs_kwargs::Dict{Symbol} + canonical_url::Union{Function, Nothing} + make_jl::String + index_md::String + + # Can't use @with_kw_noshow due to some weird precompilation issues. + function Documenter{T}(; + assets::Vector{<:AbstractString}=String[], + makedocs_kwargs::Dict{Symbol}=Dict{Symbol, Any}(), + canonical_url::Union{Function, Nothing}=make_canonical(T), + make_jl::AbstractString=default_file("docs", "make.jl"), + index_md::AbstractString=default_file("docs", "src", "index.md"), + ) where T <: DeployStyle + return new(assets, makedocs_kwargs, canonical_url, make_jl, index_md) end +end - tab = repeat(" ", 4) - assets_string = if !isempty(p.assets) - mkpath(joinpath(docs_dir, "src", "assets")) - for file in p.assets - cp(file, joinpath(docs_dir, "src", "assets", basename(file))) - end - - # We want something that looks like the following: - # [ - # assets/file1, - # assets/file2, - # ] - s = "[\n" - for asset in p.assets - s *= """$(tab^2)"assets/$(basename(asset))",\n""" - end - s *= "$tab]" - - s - else - "String[]" - end +Documenter(; kwargs...) = Documenter{Nothing}(; kwargs...) + +gitignore(::Documenter) = ["/docs/build/"] + +badges(::Documenter) = Badge[] +badges(::Documenter{<:GitHubPagesStyle}) = [ + Badge( + "Stable", + "https://img.shields.io/badge/docs-stable-blue.svg", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/stable", + ), + Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{{USER}}}.github.io/{{{PKG}}}.jl/dev", + ), +] +badges(::Documenter{GitLabCI}) = Badge( + "Dev", + "https://img.shields.io/badge/docs-dev-blue.svg", + "https://{{{USER}}}.gitlab.io/{{{PKG}}}.jl/dev", +) + +view(p::Documenter, t::Template, pkg::AbstractString) = Dict( + "ASSETS" => map(basename, p.assets), + "AUTHORS" => join(t.authors, ", "), + "CANONICAL" => p.canonical_url === nothing ? nothing : p.canonical_url(t, pkg), + "HAS_ASSETS" => !isempty(p.assets), + "MAKEDOCS_KWARGS" => map(((k, v),) -> k => repr(v), collect(p.makedocs_kwargs)), + "PKG" => pkg, + "REPO" => "$(t.host)/$(t.user)/$pkg.jl", + "USER" => t.user, +) + +function view(p::Documenter{<:GitHubPagesStyle}, t::Template, pkg::AbstractString) + base = invoke(view, Tuple{Documenter, Template, AbstractString}, p, t, pkg) + return merge(base, Dict("HAS_DEPLOY" => true)) +end - kwargs_string = if :additional_kwargs in fieldnames(typeof(p)) && - fieldtype(typeof(p), :additional_kwargs) <: Union{AbstractDict, NamedTuple} - # We want something that looks like the following: - # key1="val1", - # key2="val2", - # - kws = [keys(p.additional_kwargs)...] - valid_keys = filter(k -> !in(Symbol(k), STANDARD_KWS), kws) - if length(p.additional_kwargs) > length(valid_keys) - invalid_keys = filter(k -> Symbol(k) in STANDARD_KWS, kws) - @warn string( - "Ignoring predefined Documenter kwargs ", - join(map(repr, invalid_keys), ", "), - " from additional kwargs" - ) - end - join(map(k -> string(tab, k, "=", repr(p.additional_kwargs[k]), ",\n"), valid_keys)) - else - "" +validate(::Documenter{Nothing}, ::Template) = nothing +function validate(::Documenter{T}, t::Template) where T <: DeployStyle + if !hasplugin(t, T) + name = nameof(T) + s = "Documenter: The $name plugin must be included for docs deployment to be set up" + throw(ArgumentError(s)) end +end - make = """ - using Documenter, $pkg_name - - makedocs(; - modules=[$pkg_name], - format=Documenter.HTML(), - pages=[ - "Home" => "index.md", - ], - repo="https://$(t.host)/$(t.user)/$pkg_name.jl/blob/{commit}{path}#L{line}", - sitename="$pkg_name.jl", - authors="$(t.authors)", - assets=$assets_string, - $kwargs_string) - """ - docs = """ - # $pkg_name.jl - - ```@index - ``` - - ```@autodocs - Modules = [$pkg_name] - ``` - """ +function hook(p::Documenter, t::Template, pkg_dir::AbstractString) + pkg = basename(pkg_dir) + docs_dir = joinpath(pkg_dir, "docs") + # Generate files. + make = render_file(p.make_jl, combined_view(p, t, pkg), tags(p)) + index = render_file(p.index_md, combined_view(p, t, pkg), tags(p)) gen_file(joinpath(docs_dir, "make.jl"), make) - gen_file(joinpath(docs_dir, "src", "index.md"), docs) -end + gen_file(joinpath(docs_dir, "src", "index.md"), index) -function Base.show(io::IO, p::Documenter) - spc = " " - println(io, nameof(typeof(p)), ":") - - n = length(p.assets) - s = n == 1 ? "" : "s" - print(io, spc, "→ $n asset file$s") - if n == 0 - println(io) - else - println(io, ": ", join(map(a -> replace(a, homedir() => "~"), p.assets), ", ")) - end + # Copy over any assets. + assets_dir = joinpath(docs_dir, "src", "assets") + isempty(p.assets) || mkpath(assets_dir) + foreach(a -> cp(a, joinpath(assets_dir, basename(a))), p.assets) - n = length(p.gitignore) - s = n == 1 ? "" : "s" - print(io, "$spc→ $n gitignore entrie$s") - n > 0 && print(io, ": ", join(map(repr, p.gitignore), ", ")) + # Create the documentation project. + with_project(() -> Pkg.add(DOCUMENTER_DEP), docs_dir) end + +github_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).github.io/$pkg.jl" +gitlab_pages_url(t::Template, pkg::AbstractString) = "https://$(t.user).gitlab.io/$pkg.jl" + +make_canonical(::Type{<:GitHubPagesStyle}) = github_pages_url +make_canonical(::Type{GitLabCI}) = gitlab_pages_url +make_canonical(::Type{Nothing}) = nothing + +needs_username(::Documenter) = true diff --git a/src/plugins/droneci.jl b/src/plugins/droneci.jl deleted file mode 100644 index 5ce2027c..00000000 --- a/src/plugins/droneci.jl +++ /dev/null @@ -1,45 +0,0 @@ -""" - 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/src/plugins/git.jl b/src/plugins/git.jl new file mode 100644 index 00000000..250b0741 --- /dev/null +++ b/src/plugins/git.jl @@ -0,0 +1,118 @@ +""" + Git(; ignore=String[], ssh=false, manifest=false, gpgsign=false) + +Creates a Git repository and a `.gitignore` file. + +## Keyword Arguments +- `ignore::Vector{<:AbstractString}`: Patterns to add to the `.gitignore`. + See also: [`gitignore`](@ref). +- `ssh::Bool`: Whether or not to use SSH for the remote. + If left unset, HTTPS is used. +- `manifest::Bool`: Whether or not to commit `Manifest.toml`. +- `gpgsign::Bool`: Whether or not to sign commits with your GPG key. + This option requires that the Git CLI is installed, + and for you to have a GPG key associated with your committer identity. +""" +@with_kw_noshow struct Git <: Plugin + ignore::Vector{String} = String[] + ssh::Bool = false + manifest::Bool = false + gpgsign::Bool = false +end + +# Try to make sure that no files are created after we commit. +priority(::Git, ::typeof(posthook)) = 5 + +Base.:(==)(a::Git, b::Git) = all(map(n -> getfield(a, n) == getfield(b, n), fieldnames(Git))) + +function gitignore(p::Git) + ignore = copy(p.ignore) + p.manifest || push!(ignore, "Manifest.toml") + return ignore +end + +function validate(p::Git, t::Template) + if p.gpgsign && !git_is_installed() + throw(ArgumentError("Git: gpgsign is set but the Git CLI is not installed")) + end + + foreach(("user.name", "user.email")) do k + if isempty(LibGit2.getconfig(k, "")) + throw(ArgumentError("Git: Global Git config is missing required value '$k'")) + end + end +end + +# Set up the Git repository. +function prehook(p::Git, t::Template, pkg_dir::AbstractString) + LibGit2.with(LibGit2.init(pkg_dir)) do repo + commit(p, repo, pkg_dir, "Initial commit") + pkg = basename(pkg_dir) + url = if p.ssh + "git@$(t.host):$(t.user)/$pkg.jl.git" + else + "https://$(t.host)/$(t.user)/$pkg.jl" + end + LibGit2.with(GitRemote(repo, "origin", url)) do remote + LibGit2.add_fetch!(repo, remote, "refs/heads/master") + LibGit2.add_push!(repo, remote, "refs/heads/master") + end + end +end + +# Create the .gitignore. +function hook(p::Git, t::Template, pkg_dir::AbstractString) + ignore = mapreduce(gitignore, vcat, t.plugins) + # Only ignore manifests at the repo root. + p.manifest || "Manifest.toml" in ignore || push!(ignore, "/Manifest.toml") + unique!(sort!(ignore)) + gen_file(joinpath(pkg_dir, ".gitignore"), join(ignore, "\n")) +end + +# Commit the files. +function posthook(p::Git, ::Template, pkg_dir::AbstractString) + # Ensure that the manifest exists if it's going to be committed. + manifest = joinpath(pkg_dir, "Manifest.toml") + if p.manifest && !isfile(manifest) + touch(manifest) + with_project(Pkg.update, pkg_dir) + end + + LibGit2.with(GitRepo(pkg_dir)) do repo + LibGit2.add!(repo, ".") + msg = "Files generated by PkgTemplates" + v = version_of("PkgTemplates") + v === nothing || (msg *= "\n\nPkgTemplates version: $v") + commit(p, repo, pkg_dir, msg) + end +end + +function commit(p::Git, repo::GitRepo, pkg_dir::AbstractString, msg::AbstractString) + if p.gpgsign + run(pipeline(`git -C $pkg_dir commit -S --allow-empty -m $msg`; stdout=devnull)) + else + LibGit2.commit(repo, msg) + end +end + +needs_username(::Git) = true + +function git_is_installed() + return try + run(pipeline(`git --version`; stdout=devnull)) + true + catch + false + end +end + +if isdefined(Pkg, :dependencies) + function version_of(pkg::AbstractString) + for p in values(Pkg.dependencies()) + p.name == pkg && return p.version + end + return nothing + end +else + version_of(pkg::AbstractString) = get(Pkg.installed(), pkg, nothing) +end diff --git a/src/plugins/githubpages.jl b/src/plugins/githubpages.jl deleted file mode 100644 index 10a28a93..00000000 --- a/src/plugins/githubpages.jl +++ /dev/null @@ -1,69 +0,0 @@ -""" - GitHubPages(; assets::Vector{<:AbstractString}=String[]) -> GitHubPages - -Add `GitHubPages` to a template's plugins to add [`Documenter`](@ref) support via GitHub -Pages, including automatic uploading of documentation from [`TravisCI`](@ref). Also -adds appropriate badges to the README, and updates the `.gitignore` accordingly. - -# Keyword Arguments -* `assets::Vector{<:AbstractString}=String[]`: Array of paths to Documenter asset files. - -!!! note - If deploying documentation with Travis CI, don't forget to complete the required - configuration (see - [here](https://juliadocs.github.io/Documenter.jl/stable/man/hosting/#SSH-Deploy-Keys-1)). -""" -struct GitHubPages <: Documenter - gitignore::Vector{String} - assets::Vector{String} - - function GitHubPages(; assets::Vector{<:AbstractString}=String[]) - for file in assets - if !isfile(file) - throw(ArgumentError("Asset file $(abspath(file)) does not exist")) - end - end - # Windows Git recognizes these paths as well. - new(["/docs/build/", "/docs/site/"], abspath.(assets)) - end -end - -function badges(::GitHubPages, user::AbstractString, pkg_name::AbstractString) - return [ - format(Badge( - "Stable", - "https://img.shields.io/badge/docs-stable-blue.svg", - "https://$user.github.io/$pkg_name.jl/stable" - )), - format(Badge( - "Dev", - "https://img.shields.io/badge/docs-dev-blue.svg", - "https://$user.github.io/$pkg_name.jl/dev" - )), - ] -end - -function gen_plugin(p::GitHubPages, t::Template, pkg_name::AbstractString) - invoke(gen_plugin, Tuple{Documenter, Template, AbstractString}, p, t, pkg_name) - - if haskey(t.plugins, TravisCI) - docs_src = joinpath(t.dir, pkg_name, "docs", "src") - open(joinpath(dirname(docs_src), "make.jl"), "a") do file - write( - file, - """ - - deploydocs(; - repo="$(t.host)/$(t.user)/$pkg_name.jl", - ) - """ - ) - end - end - return ["docs/"] -end - -function interactive(::Type{GitHubPages}) - print("GitHubPages: Enter any Documenter asset files (separated by spaces) []: ") - return GitHubPages(; assets=string.(split(readline()))) -end diff --git a/src/plugins/gitlabci.jl b/src/plugins/gitlabci.jl deleted file mode 100644 index 4d2e1a2d..00000000 --- a/src/plugins/gitlabci.jl +++ /dev/null @@ -1,83 +0,0 @@ -""" - GitLabCI(; config_file::Union{AbstractString, Nothing}="", coverage::Bool=true) -> GitLabCI - -Add `GitLabCI` to a template's plugins to add a `.gitlab-ci.yml` configuration file to -generated repositories, and appropriate badge(s) to the README. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.gitlab-ci.yml`. - If `nothing` is supplied, no file will be generated. -* `coverage::Bool=true`: Whether or not GitLab CI's built-in code coverage analysis should - be enabled. -""" -struct GitLabCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function GitLabCI(; config_file::Union{AbstractString, Nothing}="", coverage::Bool=true) - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - badges = [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - ] - if coverage - push!( - badges, - Badge( - "Coverage", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/commits/master", - ), - ) - end - - new( - coverage ? ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] : [], - config_file, - ".gitlab-ci.yml", - badges, - Dict("GITLABCOVERAGE" => coverage), - ) - end -end - -function interactive(::Type{GitLabCI}) - name = "GitLabCI" - kwargs = Dict{Symbol, Any}() - default_config_file = joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - - print("$name: Enter the config template filename (\"None\" for no file) ") - print("[", replace(default_config_file, homedir() => "~"), "]: ") - config_file = readline() - kwargs[:config_file] = if uppercase(config_file) == "NONE" - nothing - elseif isempty(config_file) - default_config_file - else - config_file - end - - print("$name: Enable test coverage analysis? [yes]: ") - coverage = readline() - kwargs[:coverage] = if isempty(coverage) - true - else - !in(uppercase(coverage), ["N", "NO", "FALSE", "NONE"]) - end - - return GitLabCI(; kwargs...) -end diff --git a/src/plugins/gitlabpages.jl b/src/plugins/gitlabpages.jl deleted file mode 100644 index 3f2c0325..00000000 --- a/src/plugins/gitlabpages.jl +++ /dev/null @@ -1,47 +0,0 @@ -""" - GitLabPages(; assets::Vector{<:AbstractString}=String[]) -> GitLabPages - -Add `GitLabPages` to a template's plugins to add [`Documenter`](@ref) support via GitLab -Pages, including automatic uploading of documentation from [`GitLabCI`](@ref). Also -adds appropriate badges to the README, and updates the `.gitignore` accordingly. - -# Keyword Arguments -* `assets::Vector{<:AbstractString}=String[]`: Array of paths to Documenter asset files. -""" -struct GitLabPages <: Documenter - gitignore::Vector{String} - assets::Vector{String} - - function GitLabPages(; assets::Vector{<:AbstractString}=String[]) - for file in assets - if !isfile(file) - throw(ArgumentError("Asset file $(abspath(file)) does not exist")) - end - end - # Windows Git recognizes these paths as well. - new(["/docs/build/", "/docs/site/"], abspath.(assets)) - end -end - -function badges(::GitLabPages, user::AbstractString, pkg_name::AbstractString) - # We are only including a badge for `dev` documentation since versioned documentation - # is not supported in GitLab pages yet. See: - # https://github.com/invenia/PkgTemplates.jl/pull/54 - return [ - format(Badge( - "Dev", - "https://img.shields.io/badge/docs-dev-blue.svg", - "https://$user.gitlab.io/$pkg_name.jl/dev" - )), - ] -end - -function gen_plugin(p::GitLabPages, t::Template, pkg_name::AbstractString) - invoke(gen_plugin, Tuple{Documenter, Template, AbstractString}, p, t, pkg_name) - return ["docs/"] -end - -function interactive(::Type{GitLabPages}) - print("GitLabPages: Enter any Documenter asset files (separated by spaces) []: ") - return GitLabPages(; assets=string.(split(readline()))) -end diff --git a/src/plugins/license.jl b/src/plugins/license.jl new file mode 100644 index 00000000..e88bcbef --- /dev/null +++ b/src/plugins/license.jl @@ -0,0 +1,37 @@ +""" + License(; name="MIT", path=nothing, destination="LICENSE") + +Creates a license file. + +## Keyword Arguments +- `name::AbstractString`: Name of a license supported by PkgTemplates. + Available licenses can be seen + [here](https://github.com/invenia/PkgTemplates.jl/tree/master/templates/licenses). +- `path::Union{AbstractString, Nothing}`: Path to a custom license file. + This keyword takes priority over `name`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, `"LICENSE.md"` might be desired. +""" +struct License <: BasicPlugin + path::String + destination::String +end + +function License(; + name::AbstractString="MIT", + path::Union{AbstractString, Nothing}=nothing, + destination::AbstractString="LICENSE", +) + if path === nothing + path = default_file("licenses", name) + isfile(path) || throw(ArgumentError("License '$(basename(path))' is not available")) + end + return License(path, destination) +end + +source(p::License) = p.path +destination(p::License) = p.destination +view(::License, t::Template, ::AbstractString) = Dict( + "AUTHORS" => join(t.authors, ", "), + "YEAR" => year(today()), +) diff --git a/src/plugins/project_file.jl b/src/plugins/project_file.jl new file mode 100644 index 00000000..0afbd04f --- /dev/null +++ b/src/plugins/project_file.jl @@ -0,0 +1,40 @@ +""" + ProjectFile(; version=v"0.1.0") + +Creates a `Project.toml`. + +## Keyword Arguments +- `version::VersionNumber`: The initial version of created packages. +""" +@with_kw_noshow struct ProjectFile <: Plugin + version::VersionNumber = v"0.1.0" +end + +# Other plugins like Tests will modify this file. +priority(::ProjectFile, ::typeof(hook)) = typemax(Int) - 5 + +function hook(p::ProjectFile, t::Template, pkg_dir::AbstractString) + toml = Dict( + "name" => basename(pkg_dir), + "uuid" => string(uuid4()), + "authors" => t.authors, + "version" => string(p.version), + "compat" => Dict("julia" => compat_version(t.julia)), + ) + open(io -> TOML.print(io, toml), joinpath(pkg_dir, "Project.toml"), "w") +end + +""" + compat_version(v::VersionNumber) -> String + +Format a `VersionNumber` to exclude trailing zero components. +""" +function compat_version(v::VersionNumber) + return if v.patch == 0 && v.minor == 0 + "$(v.major)" + elseif v.patch == 0 + "$(v.major).$(v.minor)" + else + "$(v.major).$(v.minor).$(v.patch)" + end +end diff --git a/src/plugins/readme.jl b/src/plugins/readme.jl new file mode 100644 index 00000000..f5196615 --- /dev/null +++ b/src/plugins/readme.jl @@ -0,0 +1,59 @@ +""" + Readme(; + file="$(contractuser(default_file("README.md")))", + destination="README.md", + inline_badges=false, + ) + +Creates a `README` file that contains badges for other included plugins. + +## Keyword Arguments +- `file::AbstractString`: Template file for the `README`. +- `destination::AbstractString`: File destination, relative to the repository root. + For example, values of `"README"` or `"README.rst"` might be desired. +- `inline_badges::Bool`: Whether or not to put the badges on the same line as the package name. +""" +@with_kw_noshow struct Readme <: BasicPlugin + file::String = default_file("README.md") + destination::String = "README.md" + inline_badges::Bool = false +end + +source(p::Readme) = p.file +destination(p::Readme) = p.destination + +function view(p::Readme, t::Template, pkg::AbstractString) + # Explicitly ordered badges go first. + strings = String[] + done = DataType[] + foreach(badge_order()) do T + if hasplugin(t, T) + append!(strings, badges(getplugin(t, T), t, pkg)) + push!(done, T) + end + end + # And the rest go after, in no particular order. + foreach(setdiff(map(typeof, t.plugins), done)) do T + append!(strings, badges(getplugin(t, T), t, pkg)) + end + + return Dict( + "BADGES" => strings, + "HAS_CITATION" => hasplugin(t, Citation) && getplugin(t, Citation).readme, + "HAS_INLINE_BADGES" => !isempty(strings) && p.inline_badges, + "PKG" => pkg, + ) +end + +badge_order() = [ + Documenter{GitLabCI}, + Documenter{TravisCI}, + GitHubActions, + GitLabCI, + TravisCI, + AppVeyor, + DroneCI, + CirrusCI, + Codecov, + Coveralls, +] diff --git a/src/plugins/src_dir.jl b/src/plugins/src_dir.jl new file mode 100644 index 00000000..be90d198 --- /dev/null +++ b/src/plugins/src_dir.jl @@ -0,0 +1,31 @@ +""" + SrcDir(; file="$(contractuser(default_file("src", "module.jl")))") + +Creates a module entrypoint. + +## Keyword Arguments +- `file::AbstractString`: Template file for `src/.jl`. +""" +@with_kw_noshow mutable struct SrcDir <: BasicPlugin + file::String = default_file("src", "module.jl") + destination::String = "" +end + +Base.:(==)(a::SrcDir, b::SrcDir) = a.file == b.file + +# Don't display the destination field. +function Base.show(io::IO, ::MIME"text/plain", p::SrcDir) + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), "SrcDir:") + print(io, "\n", repeat(' ', indent + 2), "file: ", show_field(p.file)) +end + +source(p::SrcDir) = p.file +destination(p::SrcDir) = p.destination +view(::SrcDir, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +# Update the destination now that we know the package name. +# Kind of hacky, but oh well. +function prehook(p::SrcDir, t::Template, pkg_dir::AbstractString) + p.destination = joinpath("src", basename(pkg_dir) * ".jl") +end diff --git a/src/plugins/tests.jl b/src/plugins/tests.jl new file mode 100644 index 00000000..50a0ecad --- /dev/null +++ b/src/plugins/tests.jl @@ -0,0 +1,63 @@ +const TEST_UUID = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +const TEST_DEP = PackageSpec(; name="Test", uuid=TEST_UUID) + +""" + Tests(; file="$(contractuser(default_file("test", "runtests.jl")))", project=false) + +Sets up testing for packages. + +## Keyword Arguments +- `file::AbstractString`: Template file for `runtests.jl`. +- `project::Bool`: Whether or not to create a new project for tests (`test/Project.toml`). + See [here](https://julialang.github.io/Pkg.jl/v1/creating-packages/#Test-specific-dependencies-in-Julia-1.2-and-above-1) + for more details. + +!!! note + Managing test dependencies with `test/Project.toml` is only supported + in Julia 1.2 and later. +""" +@with_kw_noshow struct Tests <: BasicPlugin + file::String = default_file("test", "runtests.jl") + project::Bool = false +end + +source(p::Tests) = p.file +destination(::Tests) = joinpath("test", "runtests.jl") +view(::Tests, ::Template, pkg::AbstractString) = Dict("PKG" => pkg) + +function validate(p::Tests, t::Template) + invoke(validate, Tuple{BasicPlugin, Template}, p, t) + p.project && t.julia < v"1.2" && @warn string( + "Tests: The project option is set to create a project (supported in Julia 1.2 and later) ", + "but a Julia version older than 1.2 ($(t.julia)) is supported by the template", + ) +end + +function hook(p::Tests, t::Template, pkg_dir::AbstractString) + # Do the normal BasicPlugin behaviour to create the test script. + invoke(hook, Tuple{BasicPlugin, Template, AbstractString}, p, t, pkg_dir) + + # Then set up the test depdendency in the chosen way. + f = p.project ? make_test_project : add_test_dependency + f(pkg_dir) +end + +# Create a new test project. +function make_test_project(pkg_dir::AbstractString) + with_project(() -> Pkg.add(TEST_DEP), joinpath(pkg_dir, "test")) +end + +# Add Test as a test-only dependency. +function add_test_dependency(pkg_dir::AbstractString) + # Add the dependency manually since there's no programmatic way to add to [extras]. + path = joinpath(pkg_dir, "Project.toml") + toml = TOML.parsefile(path) + get!(toml, "extras", Dict())["Test"] = TEST_UUID + get!(toml, "targets", Dict())["test"] = ["Test"] + open(io -> TOML.print(io, toml), path, "w") + + # Generate the manifest by updating the project. + # This also ensures that keys in Project.toml are sorted properly. + touch(joinpath(pkg_dir, "Manifest.toml")) # File must exist to be modified by Pkg. + with_project(Pkg.update, pkg_dir) +end diff --git a/src/plugins/travisci.jl b/src/plugins/travisci.jl deleted file mode 100644 index 2d3eb72e..00000000 --- a/src/plugins/travisci.jl +++ /dev/null @@ -1,44 +0,0 @@ -""" - TravisCI(; config_file::Union{AbstractString, Nothing}="") -> TravisCI - -Add `TravisCI` to a template's plugins to add a `.travis.yml` configuration file to -generated repositories, and an appropriate badge to the README. - -# Keyword Arguments: -* `config_file::Union{AbstractString, Nothing}=""`: Path to a custom `.travis.yml`. - If `nothing` is supplied, no file will be generated. -""" -struct TravisCI <: GenericPlugin - gitignore::Vector{String} - src::Union{String, Nothing} - dest::String - badges::Vector{Badge} - view::Dict{String, Any} - - function TravisCI(; config_file::Union{AbstractString, Nothing}="") - if config_file != nothing - config_file = if isempty(config_file) - config_file = joinpath(DEFAULTS_DIR, "travis.yml") - elseif isfile(config_file) - abspath(config_file) - else - throw(ArgumentError("File $(abspath(config_file)) does not exist")) - end - end - new( - [], - config_file, - ".travis.yml", - [ - Badge( - "Build Status", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl", - ), - ], - Dict{String, Any}(), - ) - end -end - -interactive(::Type{TravisCI}) = interactive(TravisCI; file="travis.yml") diff --git a/src/show.jl b/src/show.jl new file mode 100644 index 00000000..fddad047 --- /dev/null +++ b/src/show.jl @@ -0,0 +1,33 @@ +function Base.show(io::IO, m::MIME"text/plain", t::Template) + println(io, "Template:") + foreach(fieldnames(Template)) do n + n === :plugins || println(io, repeat(' ', 2), n, ": ", show_field(getfield(t, n))) + end + if isempty(t.plugins) + print(io, " plugins: None") + else + print(io, repeat(' ', 2), "plugins:") + foreach(sort(t.plugins; by=string)) do p + println(io) + show(IOContext(io, :indent => 4), m, p) + end + end +end + +function Base.show(io::IO, ::MIME"text/plain", p::T) where T <: Plugin + indent = get(io, :indent, 0) + print(io, repeat(' ', indent), T) + ns = fieldnames(T) + isempty(ns) || print(io, ":") + foreach(ns) do n + println(io) + print(io, repeat(' ', indent + 2), n, ": ", show_field(getfield(p, n))) + end +end + +show_field(x) = repr(x) +if Sys.iswindows() + show_field(x::AbstractString) = replace(repr(contractuser(x)), "\\\\" => "\\") +else + show_field(x::AbstractString) = repr(contractuser(x)) +end diff --git a/src/template.jl b/src/template.jl index d26b371b..e3eac7ba 100644 --- a/src/template.jl +++ b/src/template.jl @@ -1,242 +1,145 @@ +default_plugins() = [ProjectFile(), SrcDir(), Git(), License(), Readme(), Tests()] +default_user() = LibGit2.getconfig("github.user", "") default_version() = VersionNumber(VERSION.major) -""" - Template(; kwargs...) -> Template - -Records common information used to generate a package. If you don't wish to manually -create a template, you can use [`interactive_template`](@ref) instead. - -# Keyword Arguments -* `user::AbstractString=""`: GitHub (or other code hosting service) username. If left - unset, it will take the the global git config's value (`github.user`). If that is not - set, an `ArgumentError` is thrown. **This is case-sensitive for some plugins, so take - care to enter it correctly.** -* `host::AbstractString="github.com"`: URL to the code hosting service where your package - will reside. Note that while hosts other than GitHub won't cause errors, they are not - officially supported and they will cause certain plugins will produce incorrect output. -* `license::AbstractString="MIT"`: Name of the package license. If an empty string is - given, no license is created. [`available_licenses`](@ref) can be used to list all - available licenses, and [`show_license`](@ref) can be used to print out a particular - license's text. -* `authors::Union{AbstractString, Vector{<:AbstractString}}=""`: Names that appear on the - license. Supply a string for one author or an array for multiple. Similarly to `user`, - it will take the value of of the global git config's value if it is left unset. -* `dir::AbstractString=$(replace(Pkg.devdir(), homedir() => "~"))`: Directory in which the - package will go. Relative paths are converted to absolute ones at template creation time. -* `julia_version::VersionNumber=$(default_version())`: Minimum allowed Julia version. -* `ssh::Bool=false`: Whether or not to use SSH for the git remote. If `false` HTTPS will be used. -* `dev::Bool=true`: Whether or not to `Pkg.develop` generated packages. -* `manifest::Bool=false`: Whether or not to commit the `Manifest.toml`. -* `plugins::Vector{<:Plugin}=Plugin[]`: A list of `Plugin`s that the package will include. -""" -struct Template - user::String - host::String - license::String - authors::String - dir::String - julia_version::VersionNumber - ssh::Bool - dev::Bool - manifest::Bool - plugins::Dict{DataType, <:Plugin} - - function Template(; - user::AbstractString="", - host::AbstractString="https://github.com", - license::AbstractString="MIT", - authors::Union{AbstractString, Vector{<:AbstractString}}="", - dir::AbstractString=Pkg.devdir(), - julia_version::VersionNumber=default_version(), - ssh::Bool=false, - dev::Bool=true, - manifest::Bool=false, - plugins::Vector{<:Plugin}=Plugin[], - git::Bool=true, - ) - # Check for required Git options for package generation - # (you can't commit to a repository without them). - git && isempty(LibGit2.getconfig("user.name", "")) && missingopt("user.name") - git && isempty(LibGit2.getconfig("user.email", "")) && missingopt("user.email") - - # If no username was set, look for one in the global git config. - # Note: This is one of a few GitHub specifics (maybe we could use the host value). - if isempty(user) - user = LibGit2.getconfig("github.user", "") - end - if isempty(user) - throw(ArgumentError("No GitHub username found, set one with user=username")) - end - - host = URI(startswith(host, "https://") ? host : "https://$host").host - - if !isempty(license) && !isfile(joinpath(LICENSE_DIR, license)) - throw(ArgumentError("License '$license' is not available")) - end +function default_authors() + name = LibGit2.getconfig("user.name", "") + isempty(name) && return "" + email = LibGit2.getconfig("user.email", "") + return isempty(email) ? name : "$name <$email>" +end - # If no author was set, look for one in the global git config. - if isempty(authors) - authors = LibGit2.getconfig("user.name", "") - email = LibGit2.getconfig("user.email", "") - isempty(email) || (authors *= " <$email>") - elseif authors isa Vector - authors = join(authors, ", ") - end +""" + Template(; kwargs...) - dir = abspath(expanduser(dir)) +A configuration used to generate packages. - 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 +## Keyword Arguments - new(user, host, license, authors, dir, julia_version, ssh, dev, manifest, plugin_dict) - end -end +### User Options +- `user::AbstractString="$(default_user())"`: GitHub (or other code hosting service) username. + The default value comes from the global Git config (`github.user`). + If no value is obtained, many plugins that use this value will not work. +- `authors::Union{AbstractString, Vector{<:AbstractString}}="$(default_authors())"`: Package authors. + Like `user`, it takes its default value from the global Git config + (`user.name` and `user.email`). -function Base.show(io::IO, t::Template) - maybe(s::String) = isempty(s) ? "None" : s - spc = " " +### Package Options +- `dir::AbstractString="$(contractuser(Pkg.devdir()))"`: Directory to place packages in. +- `host::AbstractString="github.com"`: URL to the code hosting service where packages will reside. +- `julia::VersionNumber=$(repr(default_version()))`: Minimum allowed Julia version. - println(io, "Template:") - println(io, spc, "→ User: ", maybe(t.user)) - println(io, spc, "→ Host: ", maybe(t.host)) +### Template Plugins +- `plugins::Vector{<:Plugin}=Plugin[]`: A list of [`Plugin`](@ref)s used by the template. +- `disable_defaults::Vector{DataType}=DataType[]`: Default plugins to disable. + The default plugins are [`ProjectFile`](@ref), [`SrcDir`](@ref), [`Tests`](@ref), + [`Readme`](@ref), [`License`](@ref), and [`Git`](@ref). + To override a default plugin instead of disabling it altogether, supply it via `plugins`. - print(io, spc, "→ License: ") - if isempty(t.license) - println(io, "None") - else - println(io, t.license, " ($(t.authors) ", year(today()), ")") - end +--- - println(io, spc, "→ Package directory: ", replace(maybe(t.dir), homedir() => "~")) - println(io, spc, "→ Minimum Julia version: v", version_floor(t.julia_version)) - println(io, spc, "→ SSH remote: ", t.ssh ? "Yes" : "No") - println(io, spc, "→ Add packages to main environment: ", t.dev ? "Yes" : "No") - println(io, spc, "→ Commit Manifest.toml: ", t.manifest ? "Yes" : "No") - - print(io, spc, "→ Plugins:") - if isempty(t.plugins) - print(io, " None") - else - for plugin in sort(collect(values(t.plugins)); by=string) - println(io) - buf = IOBuffer() - show(buf, plugin) - print(io, spc^2, "• ") - print(io, join(split(String(take!(buf)), "\n"), "\n$(spc^2)")) - end - end -end +To create a package from a `Template`, use the following syntax: -""" - interactive_template(; fast::Bool=false) -> Template +```julia +julia> t = Template(); -Interactively create a [`Template`](@ref). If `fast` is set, defaults will be assumed for -all values except username and plugins. +julia> t("PkgName") +``` """ -function interactive_template(; git::Bool=true, fast::Bool=false) - @info "Default values are shown in [brackets]" - # Getting the leaf types in a separate thread eliminates an awkward wait after - # "Select plugins" is printed. - plugin_types = @async leaves(Plugin) - kwargs = Dict{Symbol, Any}() - - default_user = LibGit2.getconfig("github.user", "") - print("Username [", isempty(default_user) ? "REQUIRED" : default_user, "]: ") - user = readline() - kwargs[:user] = if !isempty(user) - user - elseif !isempty(default_user) - default_user - else - throw(ArgumentError("Username is required")) - end - - kwargs[:host] = if fast || !git - "https://github.com" # If Git isn't enabled, this value never gets used. - else - default_host = "github.com" - print("Code hosting service [$default_host]: ") - host = readline() - isempty(host) ? default_host : host - end - - kwargs[:license] = if fast - "MIT" - else - println("License:") - io = IOBuffer() - available_licenses(io) - licenses = ["" => "", collect(LICENSES)...] - menu = RadioMenu(String["None", split(String(take!(io)), "\n")...]) - # If the user breaks out of the menu with Ctrl-c, the result is -1, the absolute - # value of which correponds to no license. - first(licenses[abs(request(menu))]) - end +struct Template + authors::Vector{String} + dir::String + host::String + julia::VersionNumber + plugins::Vector{<:Plugin} + user::String +end - # We don't need to ask for authors if there is no license, - # because the license is the only place that they matter. - kwargs[:authors] = if fast || isempty(kwargs[:license]) - LibGit2.getconfig("user.name", "") - else - default_authors = LibGit2.getconfig("user.name", "") - default_str = isempty(default_authors) ? "None" : default_authors - print("Package author(s) [$default_str]: ") - authors = readline() - isempty(authors) ? default_authors : authors +Template(; kwargs...) = Template(Val(false); kwargs...) + +# Non-interactive constructor. +function Template(::Val{false}; kwargs...) + kwargs = Dict(kwargs) + + user = getkw!(kwargs, :user) + dir = abspath(expanduser(getkw!(kwargs, :dir))) + host = replace(getkw!(kwargs, :host), r".*://" => "") + julia = getkw!(kwargs, :julia) + + authors = getkw!(kwargs, :authors) + authors isa Vector || (authors = map(strip, split(authors, ","))) + + # User-supplied plugins come first, so that deduping the list will remove the defaults. + plugins = Plugin[] + append!(plugins, getkw!(kwargs, :plugins)) + disabled = getkw!(kwargs, :disable_defaults) + append!(plugins, filter(p -> !(typeof(p) in disabled), default_plugins())) + plugins = sort(unique(typeof, plugins); by=string) + + if isempty(user) + foreach(plugins) do p + if needs_username(p) + T = nameof(typeof(p)) + s = """$T: Git hosting service username is required, set one with keyword `user=""`""" + throw(ArgumentError(s)) + end + end end - kwargs[:dir] = if fast - Pkg.devdir() - else - default_dir = Pkg.devdir() - print("Path to package directory [$default_dir]: ") - dir = readline() - isempty(dir) ? default_dir : dir + if !isempty(kwargs) + @warn "Unrecognized keywords were supplied, see the documentation for help" kwargs end - kwargs[:julia_version] = if fast - VERSION - else - default_julia_version = VERSION - print("Minimum Julia version [", version_floor(default_julia_version), "]: ") - julia_version = readline() - isempty(julia_version) ? default_julia_version : VersionNumber(julia_version) - end + t = Template(authors, dir, host, julia, plugins, user) + foreach(p -> validate(p, t), t.plugins) + return t +end - kwargs[:ssh] = if fast || !git - false - else - print("Set remote to SSH? [no]: ") - uppercase(readline()) in ["Y", "YES", "T", "TRUE"] - end +""" + (::Template)(pkg::AbstractString) - kwargs[:dev] = if fast - true - else - print("Add packages to main environment? [yes]: ") - uppercase(readline()) in ["", "Y", "YES", "T", "TRUE"] +Generate a package named `pkg` from a [`Template`](@ref). +""" +function (t::Template)(pkg::AbstractString) + endswith(pkg, ".jl") && (pkg = pkg[1:end-3]) + pkg_dir = joinpath(t.dir, pkg) + ispath(pkg_dir) && throw(ArgumentError("$pkg_dir already exists")) + mkpath(pkg_dir) + + try + foreach((prehook, hook, posthook)) do h + @info "Running $(nameof(h))s" + foreach(sort(t.plugins; by=p -> priority(p, h), rev=true)) do p + h(p, t, pkg_dir) + end + end + catch + rm(pkg_dir; recursive=true, force=true) + rethrow() end - kwargs[:manifest] = if fast - false - else - print("Commit Manifest.toml? [no]: ") - uppercase(readline()) in ["Y", "YES", "T", "TRUE"] - end + @info "New package is at $pkg_dir" +end - println("Plugins:") - # Only include plugin types which have an `interactive` method. - plugin_types = filter(t -> hasmethod(interactive, (Type{t},)), fetch(plugin_types)) - type_names = map(t -> split(string(t), ".")[end], plugin_types) - menu = MultiSelectMenu(String.(type_names); pagesize=length(type_names)) - selected = collect(request(menu)) - kwargs[:plugins] = Vector{Plugin}(map(interactive, getindex(plugin_types, selected))) +# Does the template have a plugin that satisfies some predicate? +hasplugin(t::Template, f::Function) = any(f, t.plugins) +hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T) - return Template(; git=git, kwargs...) +# Get a plugin by type. +function getplugin(t::Template, ::Type{T}) where T <: Plugin + i = findfirst(p -> p isa T, t.plugins) + return i === nothing ? nothing : t.plugins[i] end -leaves(T::Type)::Vector{DataType} = isconcretetype(T) ? [T] : vcat(leaves.(subtypes(T))...) - -missingopt(name) = @warn "Git config option '$name' missing, package generation will fail unless you supply a GitConfig" +# Get a keyword or a default value. +getkw!(kwargs, k) = pop!(kwargs, k, defaultkw(Template, k)) + +# Default Template keyword values. +defaultkw(::Type{T}, s::Symbol) where T = defaultkw(T, Val(s)) +defaultkw(::Type{Template}, ::Val{:authors}) = default_authors() +defaultkw(::Type{Template}, ::Val{:dir}) = Pkg.devdir() +defaultkw(::Type{Template}, ::Val{:disable_defaults}) = DataType[] +defaultkw(::Type{Template}, ::Val{:host}) = "github.com" +defaultkw(::Type{Template}, ::Val{:julia}) = default_version() +defaultkw(::Type{Template}, ::Val{:plugins}) = Plugin[] +defaultkw(::Type{Template}, ::Val{:user}) = default_user() diff --git a/templates/CITATION.bib b/templates/CITATION.bib new file mode 100644 index 00000000..6579e314 --- /dev/null +++ b/templates/CITATION.bib @@ -0,0 +1,8 @@ +@misc{<<&PKG>>.jl, + author = {<<&AUTHORS>>}, + title = {<<&PKG>>.jl}, + url = {<<&URL>>}, + version = {v0.1.0}, + year = {<<&YEAR>>}, + month = {<<&MONTH>>} +} diff --git a/templates/README.md b/templates/README.md new file mode 100644 index 00000000..980a7bb2 --- /dev/null +++ b/templates/README.md @@ -0,0 +1,13 @@ +# {{{PKG}}}{{#HAS_INLINE_BADGES}} {{#BADGES}}{{{.}}} {{/BADGES}}{{/HAS_INLINE_BADGES}} +{{^HAS_INLINE_BADGES}} + +{{#BADGES}} +{{{.}}} +{{/BADGES}} +{{/HAS_INLINE_BADGES}} +{{#HAS_CITATION}} + +## Citing + +See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). +{{/HAS_CITATION}} diff --git a/templates/appveyor.yml b/templates/appveyor.yml new file mode 100644 index 00000000..4535a46e --- /dev/null +++ b/templates/appveyor.yml @@ -0,0 +1,39 @@ +# Documentation: https://github.com/JuliaCI/Appveyor.jl +environment: + matrix: +{{#VERSIONS}} + - julia_version: {{{.}}} +{{/VERSIONS}} +platform: +{{#PLATFORMS}} + - {{{.}}} +{{/PLATFORMS}} +{{#HAS_ALLOW_FAILURES}} +matrix: + allow_failures: +{{#ALLOW_FAILURES}} + - julia_version: {{{.}}} +{{/ALLOW_FAILURES}} +{{/HAS_ALLOW_FAILURES}} +branches: + only: + - master + - /release-.*/ +notifications: + - provider: Email + on_build_success: false + on_build_failure: false + on_build_status_changed: false +install: + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) +build_script: + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" +test_script: + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" +{{#HAS_CODECOV}} +on_success: + - echo "%JL_CODECOV_SCRIPT%" + - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" +{{/HAS_CODECOV}} diff --git a/templates/cirrus.yml b/templates/cirrus.yml new file mode 100644 index 00000000..8c296cc9 --- /dev/null +++ b/templates/cirrus.yml @@ -0,0 +1,18 @@ +freebsd_instance: + image: {{{IMAGE}}} +task: + name: FreeBSD + env: +{{#VERSIONS}} + JULIA_VERSION: {{{.}}} +{{/VERSIONS}} + install_script: + - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" + build_script: + - cirrusjl build + test_script: + - cirrusjl test +{{#HAS_COVERAGE}} + coverage_script: + - cirrusjl coverage{{#HAS_CODECOV}} codecov{{/HAS_CODECOV}}{{#HAS_COVERALLS}} coveralls{{/HAS_COVERALLS}} +{{/HAS_COVERAGE}} diff --git a/templates/docs/make.jl b/templates/docs/make.jl new file mode 100644 index 00000000..dd0aa69a --- /dev/null +++ b/templates/docs/make.jl @@ -0,0 +1,34 @@ +using {{{PKG}}} +using Documenter + +makedocs(; + modules=[{{{PKG}}}], + authors="{{{AUTHORS}}}", + repo="https://{{{REPO}}}/blob/{commit}{path}#L{line}", + sitename="{{{PKG}}}.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", +{{#CANONICAL}} + canonical="{{{CANONICAL}}}", +{{/CANONICAL}} + assets={{^HAS_ASSETS}}String{{/HAS_ASSETS}}[{{^HAS_ASSETS}}],{{/HAS_ASSETS}} +{{#ASSETS}} + "assets/{{{.}}}", +{{/ASSETS}} +{{#HAS_ASSETS}} + ], +{{/HAS_ASSETS}} + ), + pages=[ + "Home" => "index.md", + ], +{{#MAKEDOCS_KWARGS}} + {{{first}}}={{{second}}}, +{{/MAKEDOCS_KWARGS}} +) +{{#HAS_DEPLOY}} + +deploydocs(; + repo="{{{REPO}}}", +) +{{/HAS_DEPLOY}} diff --git a/templates/docs/src/index.md b/templates/docs/src/index.md new file mode 100644 index 00000000..602f9ac6 --- /dev/null +++ b/templates/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = {{{PKG}}} +``` + +# {{{PKG}}} + +```@index +``` + +```@autodocs +Modules = [{{{PKG}}}] +``` diff --git a/templates/drone.star b/templates/drone.star new file mode 100644 index 00000000..b911765f --- /dev/null +++ b/templates/drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in [{{{ARCHES}}}]: + for julia in [{{{VERSIONS}}}]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/templates/github/workflows/ci.yml b/templates/github/workflows/ci.yml new file mode 100644 index 00000000..d02a57ad --- /dev/null +++ b/templates/github/workflows/ci.yml @@ -0,0 +1,67 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + <<#VERSIONS>> + - '<<&.>>' + <> + os: + <<#OS>> + - <<&.>> + <> + arch: + <<#ARCH>> + - <<&.>> + <> + <<#HAS_EXCLUDES>> + exclude: + <> + <<#EXCLUDES>> + - os: <<&E_OS>> + arch: <<&E_ARCH>> + <<#E_VERSION>> + version: '<<&E_VERSION>>' + <> + <> + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + <<#HAS_CODECOV>> + - uses: julia-actions/julia-uploadcodecov@latest + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + <> + <<#HAS_COVERALLS>> + - uses: julia-actions/julia-uploadcoveralls@latest + env: + COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} + <> + <<#HAS_DOCUMENTER>> + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: '1.0' + - run: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate();' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + <> diff --git a/templates/gitlab-ci.yml b/templates/gitlab-ci.yml new file mode 100644 index 00000000..774b2180 --- /dev/null +++ b/templates/gitlab-ci.yml @@ -0,0 +1,45 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test({{#HAS_COVERAGE}}; coverage=true{{/HAS_COVERAGE}});' +{{#HAS_COVERAGE}} + coverage: &coverage + coverage: /Test coverage (\d+\.\d+%)/ + after_script: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test coverage %.2f%%\n" 100c / t;' +{{/HAS_COVERAGE}} +{{#VERSIONS}} +Julia {{{.}}}: + image: julia:{{{.}}} + <<: *script +{{#HAS_COVERAGE}} + <<: *coverage +{{/HAS_COVERAGE}} +{{/VERSIONS}} +{{#HAS_DOCUMENTER}} +pages: + image: julia:{{{VERSION}}} + stage: deploy + script: + - julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + - mkdir -p public + - mv docs/build public/dev + artifacts: + paths: + - public + only: + - master +{{/HAS_DOCUMENTER}} diff --git a/licenses/ASL b/templates/licenses/ASL similarity index 99% rename from licenses/ASL rename to templates/licenses/ASL index e5aa8110..6f756351 100644 --- a/licenses/ASL +++ b/templates/licenses/ASL @@ -1,4 +1,3 @@ - Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -187,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [year] [fullname] + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/licenses/BSD2 b/templates/licenses/BSD2 similarity index 69% rename from licenses/BSD2 rename to templates/licenses/BSD2 index f2692064..319c6007 100644 --- a/licenses/BSD2 +++ b/templates/licenses/BSD2 @@ -1,15 +1,17 @@ +BSD 2-Clause License +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/templates/licenses/BSD3 b/templates/licenses/BSD3 new file mode 100644 index 00000000..7461e50b --- /dev/null +++ b/templates/licenses/BSD3 @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/templates/licenses/EUPL-1.2+ b/templates/licenses/EUPL-1.2+ new file mode 100644 index 00000000..a74f0443 --- /dev/null +++ b/templates/licenses/EUPL-1.2+ @@ -0,0 +1,274 @@ +European Union Public Licence +V. 1.2 + +EUPL © the European Union 2007, 2016 + +This European Union Public Licence (the ‘EUPL’) applies to the Work (as +defined below) which is provided under the terms of this Licence. Any use of +the Work, other than as authorised under this Licence is prohibited (to the +extent such use is covered by a right of the copyright holder of the Work). + +The Work is provided under the terms of this Licence when the Licensor (as +defined below) has placed the following notice immediately following the +copyright notice for the Work: “Licensed under the EUPL”, or has expressed by +any other means his willingness to license under the EUPL. + +1. Definitions + +In this Licence, the following terms have the following meaning: +— ‘The Licence’: this Licence. +— ‘The Original Work’: the work or software distributed or communicated by the + ‘Licensor under this Licence, available as Source Code and also as + ‘Executable Code as the case may be. +— ‘Derivative Works’: the works or software that could be created by the + ‘Licensee, based upon the Original Work or modifications thereof. This + ‘Licence does not define the extent of modification or dependence on the + ‘Original Work required in order to classify a work as a Derivative Work; + ‘this extent is determined by copyright law applicable in the country + ‘mentioned in Article 15. +— ‘The Work’: the Original Work or its Derivative Works. +— ‘The Source Code’: the human-readable form of the Work which is the most + convenient for people to study and modify. + +— ‘The Executable Code’: any code which has generally been compiled and which + is meant to be interpreted by a computer as a program. +— ‘The Licensor’: the natural or legal person that distributes or communicates + the Work under the Licence. +— ‘Contributor(s)’: any natural or legal person who modifies the Work under + the Licence, or otherwise contributes to the creation of a Derivative Work. +— ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of + the Work under the terms of the Licence. +— ‘Distribution’ or ‘Communication’: any act of selling, giving, lending, + renting, distributing, communicating, transmitting, or otherwise making + available, online or offline, copies of the Work or providing access to its + essential functionalities at the disposal of any other natural or legal + person. + +2. Scope of the rights granted by the Licence + +The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, +sublicensable licence to do the following, for the duration of copyright +vested in the Original Work: + +— use the Work in any circumstance and for all usage, +— reproduce the Work, +— modify the Work, and make Derivative Works based upon the Work, +— communicate to the public, including the right to make available or display + the Work or copies thereof to the public and perform publicly, as the case + may be, the Work, +— distribute the Work or copies thereof, +— lend and rent the Work or copies thereof, +— sublicense rights in the Work or copies thereof. + +Those rights can be exercised on any media, supports and formats, whether now +known or later invented, as far as the applicable law permits so. + +In the countries where moral rights apply, the Licensor waives his right to +exercise his moral right to the extent allowed by law in order to make +effective the licence of the economic rights here above listed. + +The Licensor grants to the Licensee royalty-free, non-exclusive usage rights +to any patents held by the Licensor, to the extent necessary to make use of +the rights granted on the Work under this Licence. + +3. Communication of the Source Code + +The Licensor may provide the Work either in its Source Code form, or as +Executable Code. If the Work is provided as Executable Code, the Licensor +provides in addition a machine-readable copy of the Source Code of the Work +along with each copy of the Work that the Licensor distributes or indicates, +in a notice following the copyright notice attached to the Work, a repository +where the Source Code is easily and freely accessible for as long as the +Licensor continues to distribute or communicate the Work. + +4. Limitations on copyright + +Nothing in this Licence is intended to deprive the Licensee of the benefits +from any exception or limitation to the exclusive rights of the rights owners +in the Work, of the exhaustion of those rights or of other applicable +limitations thereto. + +5. Obligations of the Licensee + +The grant of the rights mentioned above is subject to some restrictions and +obligations imposed on the Licensee. Those obligations are the following: + +Attribution right: The Licensee shall keep intact all copyright, patent or +trademarks notices and all notices that refer to the Licence and to the +disclaimer of warranties. The Licensee must include a copy of such notices and +a copy of the Licence with every copy of the Work he/she distributes or +communicates. The Licensee must cause any Derivative Work to carry prominent +notices stating that the Work has been modified and the date of modification. + +Copyleft clause: If the Licensee distributes or communicates copies of the +Original Works or Derivative Works, this Distribution or Communication will be +done under the terms of this Licence or of a later version of this Licence +unless the Original Work is expressly distributed only under this version of +the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee +(becoming Licensor) cannot offer or impose any additional terms or conditions +on the Work or Derivative Work that alter or restrict the terms of the +Licence. + +Compatibility clause: If the Licensee Distributes or Communicates Derivative +Works or copies thereof based upon both the Work and another work licensed +under a Compatible Licence, this Distribution or Communication can be done +under the terms of this Compatible Licence. For the sake of this clause, +‘Compatible Licence’ refers to the licences listed in the appendix attached to +this Licence. Should the Licensee's obligations under the Compatible Licence +conflict with his/her obligations under this Licence, the obligations of the +Compatible Licence shall prevail. + +Provision of Source Code: When distributing or communicating copies of the +Work, the Licensee will provide a machine-readable copy of the Source Code or +indicate a repository where this Source will be easily and freely available +for as long as the Licensee continues to distribute or communicate the Work. + +Legal Protection: This Licence does not grant permission to use the trade +names, trademarks, service marks, or names of the Licensor, except as required +for reasonable and customary use in describing the origin of the Work and +reproducing the content of the copyright notice. + +6. Chain of Authorship + +The original Licensor warrants that the copyright in the Original Work granted +hereunder is owned by him/her or licensed to him/her and that he/she has the +power and authority to grant the Licence. + +Each Contributor warrants that the copyright in the modifications he/she +brings to the Work are owned by him/her or licensed to him/her and that he/she +has the power and authority to grant the Licence. + +Each time You accept the Licence, the original Licensor and subsequent +Contributors grant You a licence to their contributions to the Work, under the +terms of this Licence. + +7. Disclaimer of Warranty + +The Work is a work in progress, which is continuously improved by numerous +Contributors. It is not a finished work and may therefore contain defects or +‘bugs’ inherent to this type of development. + +For the above reason, the Work is provided under the Licence on an ‘as is’ +basis and without warranties of any kind concerning the Work, including +without limitation merchantability, fitness for a particular purpose, absence +of defects or errors, accuracy, non-infringement of intellectual property +rights other than copyright as stated in Article 6 of this Licence. + +This disclaimer of warranty is an essential part of the Licence and a +condition for the grant of any rights to the Work. + +8. Disclaimer of Liability + +Except in the cases of wilful misconduct or damages directly caused to natural +persons, the Licensor will in no event be liable for any direct or indirect, +material or moral, damages of any kind, arising out of the Licence or of the +use of the Work, including without limitation, damages for loss of goodwill, +work stoppage, computer failure or malfunction, loss of data or any commercial +damage, even if the Licensor has been advised of the possibility of such +damage. However, the Licensor will be liable under statutory product liability +laws as far such laws apply to the Work. + +9. Additional agreements + +While distributing the Work, You may choose to conclude an additional +agreement, defining obligations or services consistent with this Licence. +However, if accepting obligations, You may act only on your own behalf and on +your sole responsibility, not on behalf of the original Licensor or any other +Contributor, and only if You agree to indemnify, defend, and hold each +Contributor harmless for any liability incurred by, or claims asserted against +such Contributor by the fact You have accepted any warranty or additional +liability. + +10. Acceptance of the Licence + +The provisions of this Licence can be accepted by clicking on an icon ‘I +agree’ placed under the bottom of a window displaying the text of this Licence +or by affirming consent in any other similar way, in accordance with the rules +of applicable law. Clicking on that icon indicates your clear and irrevocable +acceptance of this Licence and all of its terms and conditions. + +Similarly, you irrevocably accept this Licence and all of its terms and +conditions by exercising any rights granted to You by Article 2 of this +Licence, such as the use of the Work, the creation by You of a Derivative Work +or the Distribution or Communication by You of the Work or copies thereof. + +11. Information to the public + +In case of any Distribution or Communication of the Work by means of +electronic communication by You (for example, by offering to download the Work +from a remote location) the distribution channel or media (for example, a +website) must at least provide to the public the information requested by the +applicable law regarding the Licensor, the Licence and the way it may be +accessible, concluded, stored and reproduced by the Licensee. + +12. Termination of the Licence + +The Licence and the rights granted hereunder will terminate automatically upon +any breach by the Licensee of the terms of the Licence. Such a termination +will not terminate the licences of any person who has received the Work from +the Licensee under the Licence, provided such persons remain in full +compliance with the Licence. + +13. Miscellaneous + +Without prejudice of Article 9 above, the Licence represents the complete +agreement between the Parties as to the Work. + +If any provision of the Licence is invalid or unenforceable under applicable +law, this will not affect the validity or enforceability of the Licence as a +whole. Such provision will be construed or reformed so as necessary to make it +valid and enforceable. + +The European Commission may publish other linguistic versions or new versions +of this Licence or updated versions of the Appendix, so far this is required +and reasonable, without reducing the scope of the rights granted by the +Licence. New versions of the Licence will be published with a unique version +number. + +All linguistic versions of this Licence, approved by the European Commission, +have identical value. Parties can take advantage of the linguistic version of +their choice. + +14. Jurisdiction + +Without prejudice to specific agreement between parties, +— any litigation resulting from the interpretation of this License, arising + between the European Union institutions, bodies, offices or agencies, as a + Licensor, and any Licensee, will be subject to the jurisdiction of the Court + of Justice of the European Union, as laid down in article 272 of the Treaty + on the Functioning of the European Union, +— any litigation arising between other parties and resulting from the + interpretation of this License, will be subject to the exclusive + jurisdiction of the competent court where the Licensor resides or conducts + its primary business. + +15. Applicable Law + +Without prejudice to specific agreement between parties, +— this Licence shall be governed by the law of the European Union Member State + where the Licensor has his seat, resides or has his registered office, +— this licence shall be governed by Belgian law if the Licensor has no seat, + residence or registered office inside a European Union Member State. + +Appendix + +‘Compatible Licences’ according to Article 5 EUPL are: +— GNU General Public License (GPL) v. 2, v. 3 +— GNU Affero General Public License (AGPL) v. 3 +— Open Software License (OSL) v. 2.1, v. 3.0 +— Eclipse Public License (EPL) v. 1.0 +— CeCILL v. 2.0, v. 2.1 +— Mozilla Public Licence (MPL) v. 2 +— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 +— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for + works other than software +— European Union Public Licence (EUPL) v. 1.1, v. 1.2 +— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or + Strong Reciprocity (LiLiQ-R+) + +— The European Commission may update this Appendix to later versions of the + above licences without producing a new version of the EUPL, as long as they + provide the rights granted in Article 2 of this Licence and protect the + covered Source Code from exclusive appropriation. +— All other changes or additions to this Appendix require the production of a + new EUPL version. diff --git a/licenses/GPL-2.0+ b/templates/licenses/GPL-2.0+ similarity index 84% rename from licenses/GPL-2.0+ rename to templates/licenses/GPL-2.0+ index 1d90c9be..d159169d 100644 --- a/licenses/GPL-2.0+ +++ b/templates/licenses/GPL-2.0+ @@ -1,19 +1,3 @@ - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - GNU GENERAL PUBLIC LICENSE Version 2, June 1991 @@ -294,3 +278,62 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/licenses/GPL-3.0+ b/templates/licenses/GPL-3.0+ similarity index 92% rename from licenses/GPL-3.0+ rename to templates/licenses/GPL-3.0+ index c22be353..f288702d 100644 --- a/licenses/GPL-3.0+ +++ b/templates/licenses/GPL-3.0+ @@ -1,19 +1,7 @@ - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - - GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -631,3 +619,56 @@ Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/licenses/ISC b/templates/licenses/ISC similarity index 92% rename from licenses/ISC rename to templates/licenses/ISC index 07e276db..eeb89fc3 100644 --- a/licenses/ISC +++ b/templates/licenses/ISC @@ -1,3 +1,6 @@ +ISC License + +Copyright (c) {{{YEAR}}}, {{{AUTHORS}}} Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above diff --git a/licenses/LGPL-2.1+ b/templates/licenses/LGPL-2.1+ similarity index 92% rename from licenses/LGPL-2.1+ rename to templates/licenses/LGPL-2.1+ index d391bace..8000a6fa 100644 --- a/licenses/LGPL-2.1+ +++ b/templates/licenses/LGPL-2.1+ @@ -1,19 +1,3 @@ - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU Lesser General Public -License as published by the Free Software Foundation; either -version 2.1 of the License, or (at your option) any later version. - -This library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public -License along with this library; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - - GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 @@ -472,3 +456,49 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/templates/licenses/LGPL-3.0+ b/templates/licenses/LGPL-3.0+ new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/templates/licenses/LGPL-3.0+ @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/licenses/MIT b/templates/licenses/MIT similarity index 95% rename from licenses/MIT rename to templates/licenses/MIT index 6bf41db9..775ba1de 100644 --- a/licenses/MIT +++ b/templates/licenses/MIT @@ -1,3 +1,6 @@ +MIT License + +Copyright (c) {{{YEAR}}} {{{AUTHORS}}} Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/templates/licenses/MPL b/templates/licenses/MPL new file mode 100644 index 00000000..a612ad98 --- /dev/null +++ b/templates/licenses/MPL @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/templates/src/module.jl b/templates/src/module.jl new file mode 100644 index 00000000..f07318fc --- /dev/null +++ b/templates/src/module.jl @@ -0,0 +1,5 @@ +module {{{PKG}}} + +# Write your package code here. + +end diff --git a/templates/test/runtests.jl b/templates/test/runtests.jl new file mode 100644 index 00000000..7cc1ecbe --- /dev/null +++ b/templates/test/runtests.jl @@ -0,0 +1,6 @@ +using {{{PKG}}} +using Test + +@testset "{{{PKG}}}.jl" begin + # Write your tests here. +end diff --git a/templates/travis.yml b/templates/travis.yml new file mode 100644 index 00000000..b6a0172c --- /dev/null +++ b/templates/travis.yml @@ -0,0 +1,64 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: +{{#VERSIONS}} + - {{{.}}} +{{/VERSIONS}} +os: +{{#OS}} + - {{{.}}} +{{/OS}} +arch: +{{#ARCH}} + - {{{.}}} +{{/ARCH}} +jobs: + fast_finish: true +{{#HAS_ALLOW_FAILURES}} + allow_failures: +{{/HAS_ALLOW_FAILURES}} +{{#ALLOW_FAILURES}} + - julia: {{{.}}} +{{/ALLOW_FAILURES}} +{{#HAS_EXCLUDES}} + exclude: +{{/HAS_EXCLUDES}} +{{#EXCLUDES}} + - arch: {{{E_ARCH}}} + {{#E_OS}} + os: {{{E_OS}}} + {{/E_OS}} + {{#E_JULIA}} + julia: {{{E_JULIA}}} + {{/E_JULIA}} +{{/EXCLUDES}} +{{#HAS_DOCUMENTER}} + include: + - stage: Documentation + julia: {{{VERSION}}} + script: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + after_success: skip +{{/HAS_DOCUMENTER}} +{{#HAS_COVERAGE}} +after_success: +{{#HAS_CODECOV}} + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' +{{/HAS_CODECOV}} +{{#HAS_COVERALLS}} + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Coveralls.submit(process_folder());' +{{/HAS_COVERALLS}} +{{/HAS_COVERAGE}} diff --git a/defaults/appveyor.yml b/test/fixtures/AllPlugins/.appveyor.yml similarity index 88% rename from defaults/appveyor.yml rename to test/fixtures/AllPlugins/.appveyor.yml index c9f4dec7..9eee8d14 100644 --- a/defaults/appveyor.yml +++ b/test/fixtures/AllPlugins/.appveyor.yml @@ -1,10 +1,10 @@ # Documentation: https://github.com/JuliaCI/Appveyor.jl environment: matrix: - - julia_version: {{VERSION}} - - julia_version: nightly + - julia_version: 1.0 + - julia_version: 1.2 + - julia_version: nightly platform: - - x86 - x64 matrix: allow_failures: @@ -26,8 +26,6 @@ build_script: test_script: - echo "%JL_TEST_SCRIPT%" - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" -{{#CODECOV}} on_success: - echo "%JL_CODECOV_SCRIPT%" - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" -{{/CODECOV}} diff --git a/defaults/cirrus.yml b/test/fixtures/AllPlugins/.cirrus.yml similarity index 66% rename from defaults/cirrus.yml rename to test/fixtures/AllPlugins/.cirrus.yml index 2b1949ea..a8874cb5 100644 --- a/defaults/cirrus.yml +++ b/test/fixtures/AllPlugins/.cirrus.yml @@ -3,14 +3,14 @@ freebsd_instance: task: name: FreeBSD env: - JULIA_VERSION: {{VERSION}} + JULIA_VERSION: 1.0 + JULIA_VERSION: 1.2 + JULIA_VERSION: nightly install_script: - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" build_script: - cirrusjl build test_script: - cirrusjl test -{{#COVERAGE}} coverage_script: - - cirrusjl coverage{{#CODECOV}} codecov{{/CODECOV}}{{#COVERALLS}} coveralls{{/COVERALLS}} -{{/COVERAGE}} + - cirrusjl coverage codecov coveralls diff --git a/test/fixtures/AllPlugins/.drone.star b/test/fixtures/AllPlugins/.drone.star new file mode 100644 index 00000000..cdfb36eb --- /dev/null +++ b/test/fixtures/AllPlugins/.drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in ["amd64"]: + for julia in ["1.0", "1.2"]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/test/fixtures/AllPlugins/.github/workflows/ci.yml b/test/fixtures/AllPlugins/.github/workflows/ci.yml new file mode 100644 index 00000000..2710c614 --- /dev/null +++ b/test/fixtures/AllPlugins/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + - uses: julia-actions/julia-uploadcodecov@latest + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - uses: julia-actions/julia-uploadcoveralls@latest + env: + COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }} diff --git a/test/fixtures/AllPlugins/.gitignore b/test/fixtures/AllPlugins/.gitignore new file mode 100644 index 00000000..3804c222 --- /dev/null +++ b/test/fixtures/AllPlugins/.gitignore @@ -0,0 +1,5 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +/docs/build/ +Manifest.toml diff --git a/test/fixtures/AllPlugins/.gitlab-ci.yml b/test/fixtures/AllPlugins/.gitlab-ci.yml new file mode 100644 index 00000000..44d9d344 --- /dev/null +++ b/test/fixtures/AllPlugins/.gitlab-ci.yml @@ -0,0 +1,25 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test(; coverage=true);' + coverage: &coverage + coverage: /Test coverage (\d+\.\d+%)/ + after_script: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + c, t = get_summary(process_folder()); + using Printf; + @printf "Test coverage %.2f%%\n" 100c / t;' +Julia 1.0: + image: julia:1.0 + <<: *script + <<: *coverage +Julia 1.2: + image: julia:1.2 + <<: *script + <<: *coverage diff --git a/test/fixtures/AllPlugins/.travis.yml b/test/fixtures/AllPlugins/.travis.yml new file mode 100644 index 00000000..93151129 --- /dev/null +++ b/test/fixtures/AllPlugins/.travis.yml @@ -0,0 +1,29 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.0 + - 1.2 + - nightly +os: + - linux + - osx + - windows +arch: + - x64 +jobs: + fast_finish: true + allow_failures: + - julia: nightly +after_success: + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Codecov.submit(process_folder());' + - julia -e ' + using Pkg; + Pkg.add("Coverage"); + using Coverage; + Coveralls.submit(process_folder());' diff --git a/test/fixtures/AllPlugins/CITATION.bib b/test/fixtures/AllPlugins/CITATION.bib new file mode 100644 index 00000000..b39b28c2 --- /dev/null +++ b/test/fixtures/AllPlugins/CITATION.bib @@ -0,0 +1,8 @@ +@misc{AllPlugins.jl, + author = {tester}, + title = {AllPlugins.jl}, + url = {https://github.com/tester/AllPlugins.jl}, + version = {v0.1.0}, + year = {2019}, + month = {8} +} diff --git a/test/fixtures/AllPlugins/LICENSE b/test/fixtures/AllPlugins/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/AllPlugins/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/AllPlugins/Manifest.toml b/test/fixtures/AllPlugins/Manifest.toml new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/AllPlugins/Manifest.toml @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/AllPlugins/Project.toml b/test/fixtures/AllPlugins/Project.toml new file mode 100644 index 00000000..60e925dd --- /dev/null +++ b/test/fixtures/AllPlugins/Project.toml @@ -0,0 +1,13 @@ +name = "AllPlugins" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/AllPlugins/README.md b/test/fixtures/AllPlugins/README.md new file mode 100644 index 00000000..b2b41aaf --- /dev/null +++ b/test/fixtures/AllPlugins/README.md @@ -0,0 +1,11 @@ +# AllPlugins + +[![Build Status](https://github.com/tester/AllPlugins.jl/actions)](https://github.com/tester/AllPlugins.jl/workflows/CI/badge.svg) +[![Build Status](https://gitlab.com/tester/AllPlugins.jl/badges/master/build.svg)](https://gitlab.com/tester/AllPlugins.jl/pipelines) +[![Coverage](https://gitlab.com/tester/AllPlugins.jl/badges/master/coverage.svg)](https://gitlab.com/tester/AllPlugins.jl/commits/master) +[![Build Status](https://travis-ci.com/tester/AllPlugins.jl.svg?branch=master)](https://travis-ci.com/tester/AllPlugins.jl) +[![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/AllPlugins.jl?svg=true)](https://ci.appveyor.com/project/tester/AllPlugins-jl) +[![Build Status](https://cloud.drone.io/api/badges/tester/AllPlugins.jl/status.svg)](https://cloud.drone.io/tester/AllPlugins.jl) +[![Build Status](https://api.cirrus-ci.com/github/tester/AllPlugins.jl.svg)](https://cirrus-ci.com/github/tester/AllPlugins.jl) +[![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) +[![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) diff --git a/test/fixtures/AllPlugins/docs/Manifest.toml b/test/fixtures/AllPlugins/docs/Manifest.toml new file mode 100644 index 00000000..fe717470 --- /dev/null +++ b/test/fixtures/AllPlugins/docs/Manifest.toml @@ -0,0 +1,89 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "0513f1a8991e9d83255e0140aace0d0fc4486600" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.0" + +[[Documenter]] +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "1b6ae3796f60311e39cd1770566140d2c056e87f" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.23.3" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "ef0af6c8601db18c282d092ccbd2f01f3f0cd70b" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.7" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/fixtures/AllPlugins/docs/Project.toml b/test/fixtures/AllPlugins/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/AllPlugins/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/AllPlugins/docs/make.jl b/test/fixtures/AllPlugins/docs/make.jl new file mode 100644 index 00000000..35c4a8d3 --- /dev/null +++ b/test/fixtures/AllPlugins/docs/make.jl @@ -0,0 +1,16 @@ +using AllPlugins +using Documenter + +makedocs(; + modules=[AllPlugins], + authors="tester", + repo="https://github.com/tester/AllPlugins.jl/blob/{commit}{path}#L{line}", + sitename="AllPlugins.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) diff --git a/test/fixtures/AllPlugins/docs/src/index.md b/test/fixtures/AllPlugins/docs/src/index.md new file mode 100644 index 00000000..b1afe2bb --- /dev/null +++ b/test/fixtures/AllPlugins/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = AllPlugins +``` + +# AllPlugins + +```@index +``` + +```@autodocs +Modules = [AllPlugins] +``` diff --git a/test/fixtures/AllPlugins/src/AllPlugins.jl b/test/fixtures/AllPlugins/src/AllPlugins.jl new file mode 100644 index 00000000..41b2489c --- /dev/null +++ b/test/fixtures/AllPlugins/src/AllPlugins.jl @@ -0,0 +1,5 @@ +module AllPlugins + +# Write your package code here. + +end diff --git a/test/fixtures/AllPlugins/test/runtests.jl b/test/fixtures/AllPlugins/test/runtests.jl new file mode 100644 index 00000000..c12f6d96 --- /dev/null +++ b/test/fixtures/AllPlugins/test/runtests.jl @@ -0,0 +1,6 @@ +using AllPlugins +using Test + +@testset "AllPlugins.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/Basic/.gitignore b/test/fixtures/Basic/.gitignore new file mode 100644 index 00000000..ba39cc53 --- /dev/null +++ b/test/fixtures/Basic/.gitignore @@ -0,0 +1 @@ +Manifest.toml diff --git a/test/fixtures/Basic/LICENSE b/test/fixtures/Basic/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/Basic/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/Basic/Manifest.toml b/test/fixtures/Basic/Manifest.toml new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/Basic/Manifest.toml @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/Basic/Project.toml b/test/fixtures/Basic/Project.toml new file mode 100644 index 00000000..3d5ccb69 --- /dev/null +++ b/test/fixtures/Basic/Project.toml @@ -0,0 +1,13 @@ +name = "Basic" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/Basic/README.md b/test/fixtures/Basic/README.md new file mode 100644 index 00000000..0b51bff1 --- /dev/null +++ b/test/fixtures/Basic/README.md @@ -0,0 +1 @@ +# Basic diff --git a/test/fixtures/Basic/src/Basic.jl b/test/fixtures/Basic/src/Basic.jl new file mode 100644 index 00000000..42332aa3 --- /dev/null +++ b/test/fixtures/Basic/src/Basic.jl @@ -0,0 +1,5 @@ +module Basic + +# Write your package code here. + +end diff --git a/test/fixtures/Basic/test/runtests.jl b/test/fixtures/Basic/test/runtests.jl new file mode 100644 index 00000000..085a7069 --- /dev/null +++ b/test/fixtures/Basic/test/runtests.jl @@ -0,0 +1,6 @@ +using Basic +using Test + +@testset "Basic.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml b/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml new file mode 100644 index 00000000..74a25a26 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/.github/workflows/ci.yml @@ -0,0 +1,42 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - ubuntu-latest + - macOS-latest + - windows-latest + arch: + - x64 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest + docs: + name: Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: '1.0' + - run: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate();' + - run: julia --project=docs docs/make.jl + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/test/fixtures/DocumenterGitHubActions/.gitignore b/test/fixtures/DocumenterGitHubActions/.gitignore new file mode 100644 index 00000000..11b69edd --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/.gitignore @@ -0,0 +1,2 @@ +/docs/build/ +Manifest.toml diff --git a/test/fixtures/DocumenterGitHubActions/LICENSE b/test/fixtures/DocumenterGitHubActions/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/DocumenterGitHubActions/Project.toml b/test/fixtures/DocumenterGitHubActions/Project.toml new file mode 100644 index 00000000..ac61e7d4 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/Project.toml @@ -0,0 +1,13 @@ +name = "DocumenterGitHubActions" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/DocumenterGitHubActions/README.md b/test/fixtures/DocumenterGitHubActions/README.md new file mode 100644 index 00000000..8736688c --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/README.md @@ -0,0 +1,5 @@ +# DocumenterGitHubActions + +[![Build Status](https://github.com/tester/DocumenterGitHubActions.jl/actions)](https://github.com/tester/DocumenterGitHubActions.jl/workflows/CI/badge.svg) +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://tester.github.io/DocumenterGitHubActions.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.github.io/DocumenterGitHubActions.jl/dev) diff --git a/test/fixtures/DocumenterGitHubActions/docs/Project.toml b/test/fixtures/DocumenterGitHubActions/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/DocumenterGitHubActions/docs/make.jl b/test/fixtures/DocumenterGitHubActions/docs/make.jl new file mode 100644 index 00000000..ca4caf37 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/make.jl @@ -0,0 +1,21 @@ +using DocumenterGitHubActions +using Documenter + +makedocs(; + modules=[DocumenterGitHubActions], + authors="tester", + repo="https://github.com/tester/DocumenterGitHubActions.jl/blob/{commit}{path}#L{line}", + sitename="DocumenterGitHubActions.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://tester.github.io/DocumenterGitHubActions.jl", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/tester/DocumenterGitHubActions.jl", +) diff --git a/test/fixtures/DocumenterGitHubActions/docs/src/index.md b/test/fixtures/DocumenterGitHubActions/docs/src/index.md new file mode 100644 index 00000000..f5f18e99 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = DocumenterGitHubActions +``` + +# DocumenterGitHubActions + +```@index +``` + +```@autodocs +Modules = [DocumenterGitHubActions] +``` diff --git a/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl b/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl new file mode 100644 index 00000000..c97d15b9 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/src/DocumenterGitHubActions.jl @@ -0,0 +1,5 @@ +module DocumenterGitHubActions + +# Write your package code here. + +end diff --git a/test/fixtures/DocumenterGitHubActions/test/runtests.jl b/test/fixtures/DocumenterGitHubActions/test/runtests.jl new file mode 100644 index 00000000..16755e08 --- /dev/null +++ b/test/fixtures/DocumenterGitHubActions/test/runtests.jl @@ -0,0 +1,6 @@ +using DocumenterGitHubActions +using Test + +@testset "DocumenterGitHubActions.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/DocumenterTravis/.gitignore b/test/fixtures/DocumenterTravis/.gitignore new file mode 100644 index 00000000..11b69edd --- /dev/null +++ b/test/fixtures/DocumenterTravis/.gitignore @@ -0,0 +1,2 @@ +/docs/build/ +Manifest.toml diff --git a/test/fixtures/DocumenterTravis/.travis.yml b/test/fixtures/DocumenterTravis/.travis.yml new file mode 100644 index 00000000..91da1450 --- /dev/null +++ b/test/fixtures/DocumenterTravis/.travis.yml @@ -0,0 +1,27 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.0 + - 1.2 + - nightly +os: + - linux + - osx + - windows +arch: + - x64 +jobs: + fast_finish: true + allow_failures: + - julia: nightly + include: + - stage: Documentation + julia: 1.0 + script: julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + after_success: skip diff --git a/test/fixtures/DocumenterTravis/LICENSE b/test/fixtures/DocumenterTravis/LICENSE new file mode 100644 index 00000000..b7731085 --- /dev/null +++ b/test/fixtures/DocumenterTravis/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 tester + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/test/fixtures/DocumenterTravis/Project.toml b/test/fixtures/DocumenterTravis/Project.toml new file mode 100644 index 00000000..c1c62704 --- /dev/null +++ b/test/fixtures/DocumenterTravis/Project.toml @@ -0,0 +1,13 @@ +name = "DocumenterTravis" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "0.1.0" + +[compat] +julia = "1" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"] diff --git a/test/fixtures/DocumenterTravis/README.md b/test/fixtures/DocumenterTravis/README.md new file mode 100644 index 00000000..72633eef --- /dev/null +++ b/test/fixtures/DocumenterTravis/README.md @@ -0,0 +1,5 @@ +# DocumenterTravis + +[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://tester.github.io/DocumenterTravis.jl/stable) +[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.github.io/DocumenterTravis.jl/dev) +[![Build Status](https://travis-ci.com/tester/DocumenterTravis.jl.svg?branch=master)](https://travis-ci.com/tester/DocumenterTravis.jl) diff --git a/test/fixtures/DocumenterTravis/docs/Project.toml b/test/fixtures/DocumenterTravis/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/DocumenterTravis/docs/make.jl b/test/fixtures/DocumenterTravis/docs/make.jl new file mode 100644 index 00000000..b2036fb5 --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/make.jl @@ -0,0 +1,21 @@ +using DocumenterTravis +using Documenter + +makedocs(; + modules=[DocumenterTravis], + authors="tester", + repo="https://github.com/tester/DocumenterTravis.jl/blob/{commit}{path}#L{line}", + sitename="DocumenterTravis.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="https://tester.github.io/DocumenterTravis.jl", + assets=String[], + ), + pages=[ + "Home" => "index.md", + ], +) + +deploydocs(; + repo="github.com/tester/DocumenterTravis.jl", +) diff --git a/test/fixtures/DocumenterTravis/docs/src/index.md b/test/fixtures/DocumenterTravis/docs/src/index.md new file mode 100644 index 00000000..78a8bd7b --- /dev/null +++ b/test/fixtures/DocumenterTravis/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = DocumenterTravis +``` + +# DocumenterTravis + +```@index +``` + +```@autodocs +Modules = [DocumenterTravis] +``` diff --git a/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl b/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl new file mode 100644 index 00000000..4bf20935 --- /dev/null +++ b/test/fixtures/DocumenterTravis/src/DocumenterTravis.jl @@ -0,0 +1,5 @@ +module DocumenterTravis + +# Write your package code here. + +end diff --git a/test/fixtures/DocumenterTravis/test/runtests.jl b/test/fixtures/DocumenterTravis/test/runtests.jl new file mode 100644 index 00000000..99fd8ed0 --- /dev/null +++ b/test/fixtures/DocumenterTravis/test/runtests.jl @@ -0,0 +1,6 @@ +using DocumenterTravis +using Test + +@testset "DocumenterTravis.jl" begin + # Write your tests here. +end diff --git a/.appveyor.yml b/test/fixtures/WackyOptions/.appveyor.yml similarity index 77% rename from .appveyor.yml rename to test/fixtures/WackyOptions/.appveyor.yml index 11ec9322..5f56bb54 100644 --- a/.appveyor.yml +++ b/test/fixtures/WackyOptions/.appveyor.yml @@ -1,14 +1,18 @@ +# Documentation: https://github.com/JuliaCI/Appveyor.jl environment: matrix: - - julia_version: 0.7 - - julia_version: 1.0 - - julia_version: nightly + - julia_version: 1.2 + - julia_version: 1.3 platform: - - x86 - x64 + - x86 matrix: allow_failures: - - julia_version: nightly + - julia_version: 1.3 +branches: + only: + - master + - /release-.*/ notifications: - provider: Email on_build_success: false diff --git a/test/fixtures/WackyOptions/.cirrus.yml b/test/fixtures/WackyOptions/.cirrus.yml new file mode 100644 index 00000000..3c3ac8df --- /dev/null +++ b/test/fixtures/WackyOptions/.cirrus.yml @@ -0,0 +1,13 @@ +freebsd_instance: + image: freebsd-123 +task: + name: FreeBSD + env: + JULIA_VERSION: 1.1 + JULIA_VERSION: 1.2 + install_script: + - sh -c "$(fetch https://raw.githubusercontent.com/ararslan/CirrusCI.jl/master/bin/install.sh -o -)" + build_script: + - cirrusjl build + test_script: + - cirrusjl test diff --git a/test/fixtures/WackyOptions/.codecov.yml b/test/fixtures/WackyOptions/.codecov.yml new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/.codecov.yml @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/.coveralls.yml b/test/fixtures/WackyOptions/.coveralls.yml new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/.coveralls.yml @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/.drone.star b/test/fixtures/WackyOptions/.drone.star new file mode 100644 index 00000000..25ce6311 --- /dev/null +++ b/test/fixtures/WackyOptions/.drone.star @@ -0,0 +1,27 @@ +def main(ctx): + pipelines = [] + for arch in ["arm", "arm64"]: + for julia in ["1.1", "1.2"]: + pipelines.append(pipeline(arch, julia)) + return pipelines + +def pipeline(arch, julia): + return { + "kind": "pipeline", + "type": "docker", + "name": "Julia %s - %s" % (julia, arch), + "platform": { + "os": "linux", + "arch": arch, + }, + "steps": [ + { + "name": "test", + "image": "julia:%s" % julia, + "commands": [ + "julia -e 'using InteractiveUtils; versioninfo()'", + "julia --project=@. -e 'using Pkg; Pkg.instantiate(); Pkg.build(); Pkg.test();'", + ], + }, + ], + } diff --git a/test/fixtures/WackyOptions/.github/workflows/ci.yml b/test/fixtures/WackyOptions/.github/workflows/ci.yml new file mode 100644 index 00000000..ff776ce9 --- /dev/null +++ b/test/fixtures/WackyOptions/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + version: + - '1.0' + - '1.2' + os: + - macOS-latest + - windows-latest + arch: + - x64 + - x86 + exclude: + - os: macOS-latest + arch: x86 + steps: + - uses: actions/checkout@v1 + - uses: julia-actions/setup-julia@latest + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: julia-actions/julia-buildpkg@latest + - uses: julia-actions/julia-runtest@latest diff --git a/test/fixtures/WackyOptions/.gitignore b/test/fixtures/WackyOptions/.gitignore new file mode 100644 index 00000000..739bc26e --- /dev/null +++ b/test/fixtures/WackyOptions/.gitignore @@ -0,0 +1,7 @@ +*.jl.*.cov +*.jl.cov +*.jl.mem +/docs/build/ +a +b +c diff --git a/test/fixtures/WackyOptions/.gitlab-ci.yml b/test/fixtures/WackyOptions/.gitlab-ci.yml new file mode 100644 index 00000000..88c61198 --- /dev/null +++ b/test/fixtures/WackyOptions/.gitlab-ci.yml @@ -0,0 +1,29 @@ +.definitions: + script: &script + script: + - julia --project=@. -e ' + using Pkg; + Pkg.build(); + Pkg.test();' +Julia 0.6: + image: julia:0.6 + <<: *script +Julia 1.2: + image: julia:1.2 + <<: *script +pages: + image: julia:1.2 + stage: deploy + script: + - julia --project=docs -e ' + using Pkg; + Pkg.develop(PackageSpec(; path=pwd())); + Pkg.instantiate(); + include("docs/make.jl");' + - mkdir -p public + - mv docs/build public/dev + artifacts: + paths: + - public + only: + - master diff --git a/test/fixtures/WackyOptions/.travis.yml b/test/fixtures/WackyOptions/.travis.yml new file mode 100644 index 00000000..1b2d1ee1 --- /dev/null +++ b/test/fixtures/WackyOptions/.travis.yml @@ -0,0 +1,21 @@ +# Documentation: http://docs.travis-ci.com/user/languages/julia +language: julia +notifications: + email: false +julia: + - 1.1 + - 1.2 +os: + - linux + - osx +arch: + - x64 + - x86 + - arm64 +jobs: + fast_finish: true + exclude: + - arch: x86 + os: osx + - arch: arm64 + os: osx diff --git a/test/fixtures/WackyOptions/CITATION.bib b/test/fixtures/WackyOptions/CITATION.bib new file mode 100644 index 00000000..2395a73d --- /dev/null +++ b/test/fixtures/WackyOptions/CITATION.bib @@ -0,0 +1,8 @@ +@misc{WackyOptions.jl, + author = {tester}, + title = {WackyOptions.jl}, + url = {https://github.com/tester/WackyOptions.jl}, + version = {v0.1.0}, + year = {2019}, + month = {8} +} diff --git a/test/fixtures/WackyOptions/LICENSE b/test/fixtures/WackyOptions/LICENSE new file mode 100644 index 00000000..a677137b --- /dev/null +++ b/test/fixtures/WackyOptions/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2019, tester + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/test/fixtures/WackyOptions/Manifest.toml b/test/fixtures/WackyOptions/Manifest.toml new file mode 100644 index 00000000..f45eecff --- /dev/null +++ b/test/fixtures/WackyOptions/Manifest.toml @@ -0,0 +1,2 @@ +# This file is machine-generated - editing it directly is not advised + diff --git a/test/fixtures/WackyOptions/Project.toml b/test/fixtures/WackyOptions/Project.toml new file mode 100644 index 00000000..c1ac4eea --- /dev/null +++ b/test/fixtures/WackyOptions/Project.toml @@ -0,0 +1,7 @@ +name = "WackyOptions" +uuid = "5b7e9947-ddc0-4b3f-9b55-0d8042f74170" +authors = ["tester"] +version = "1.0.0" + +[compat] +julia = "1.2" diff --git a/test/fixtures/WackyOptions/README.md b/test/fixtures/WackyOptions/README.md new file mode 100644 index 00000000..9a9d4aae --- /dev/null +++ b/test/fixtures/WackyOptions/README.md @@ -0,0 +1,5 @@ +# WackyOptions [![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://tester.gitlab.io/WackyOptions.jl/dev) [![Build Status](https://github.com/tester/WackyOptions.jl/actions)](https://github.com/tester/WackyOptions.jl/workflows/CI/badge.svg) [![Build Status](https://gitlab.com/tester/WackyOptions.jl/badges/master/build.svg)](https://gitlab.com/tester/WackyOptions.jl/pipelines) [![Build Status](https://travis-ci.com/tester/WackyOptions.jl.svg?branch=master)](https://travis-ci.com/tester/WackyOptions.jl) [![Build Status](https://ci.appveyor.com/api/projects/status/github/tester/WackyOptions.jl?svg=true)](https://ci.appveyor.com/project/tester/WackyOptions-jl) [![Build Status](https://cloud.drone.io/api/badges/tester/WackyOptions.jl/status.svg)](https://cloud.drone.io/tester/WackyOptions.jl) [![Build Status](https://api.cirrus-ci.com/github/tester/WackyOptions.jl.svg)](https://cirrus-ci.com/github/tester/WackyOptions.jl) [![Coverage](https://codecov.io/gh//.jl/branch/master/graph/badge.svg)](https://codecov.io/gh//.jl) [![Coverage](https://coveralls.io/repos/github//.jl/badge.svg?branch=master)](https://coveralls.io/github//.jl?branch=master) + +## Citing + +See [`CITATION.bib`](CITATION.bib) for the relevant reference(s). diff --git a/test/fixtures/WackyOptions/docs/Manifest.toml b/test/fixtures/WackyOptions/docs/Manifest.toml new file mode 100644 index 00000000..286113bb --- /dev/null +++ b/test/fixtures/WackyOptions/docs/Manifest.toml @@ -0,0 +1,89 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[DocStringExtensions]] +deps = ["LibGit2", "Markdown", "Pkg", "Test"] +git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.8.1" + +[[Documenter]] +deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "d45c163c7a3ae293c15361acc52882c0f853f97c" +uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" +version = "0.23.4" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.0" + +[[LibGit2]] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[Parsers]] +deps = ["Dates", "Test"] +git-tree-sha1 = "c56ecb484f286639f161e712b8311f5ab77e8d32" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "0.3.8" + +[[Pkg]] +deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/fixtures/WackyOptions/docs/Project.toml b/test/fixtures/WackyOptions/docs/Project.toml new file mode 100644 index 00000000..dfa65cd1 --- /dev/null +++ b/test/fixtures/WackyOptions/docs/Project.toml @@ -0,0 +1,2 @@ +[deps] +Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" diff --git a/test/fixtures/WackyOptions/docs/make.jl b/test/fixtures/WackyOptions/docs/make.jl new file mode 100644 index 00000000..888f0a07 --- /dev/null +++ b/test/fixtures/WackyOptions/docs/make.jl @@ -0,0 +1,21 @@ +using WackyOptions +using Documenter + +makedocs(; + modules=[WackyOptions], + authors="tester", + repo="https://github.com/tester/WackyOptions.jl/blob/{commit}{path}#L{line}", + sitename="WackyOptions.jl", + format=Documenter.HTML(; + prettyurls=get(ENV, "CI", "false") == "true", + canonical="http://example.com", + assets=[ + "assets/static.txt", + ], + ), + pages=[ + "Home" => "index.md", + ], + bar="baz", + foo="bar", +) diff --git a/test/fixtures/WackyOptions/docs/src/assets/static.txt b/test/fixtures/WackyOptions/docs/src/assets/static.txt new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/WackyOptions/docs/src/assets/static.txt @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/fixtures/WackyOptions/docs/src/index.md b/test/fixtures/WackyOptions/docs/src/index.md new file mode 100644 index 00000000..bd295dfd --- /dev/null +++ b/test/fixtures/WackyOptions/docs/src/index.md @@ -0,0 +1,12 @@ +```@meta +CurrentModule = WackyOptions +``` + +# WackyOptions + +```@index +``` + +```@autodocs +Modules = [WackyOptions] +``` diff --git a/test/fixtures/WackyOptions/src/WackyOptions.jl b/test/fixtures/WackyOptions/src/WackyOptions.jl new file mode 100644 index 00000000..08841a1f --- /dev/null +++ b/test/fixtures/WackyOptions/src/WackyOptions.jl @@ -0,0 +1,5 @@ +module WackyOptions + +# Write your package code here. + +end diff --git a/test/fixtures/WackyOptions/test/Manifest.toml b/test/fixtures/WackyOptions/test/Manifest.toml new file mode 100644 index 00000000..ac58105f --- /dev/null +++ b/test/fixtures/WackyOptions/test/Manifest.toml @@ -0,0 +1,33 @@ +# This file is machine-generated - editing it directly is not advised + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[Test]] +deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/fixtures/WackyOptions/test/Project.toml b/test/fixtures/WackyOptions/test/Project.toml new file mode 100644 index 00000000..0c363327 --- /dev/null +++ b/test/fixtures/WackyOptions/test/Project.toml @@ -0,0 +1,2 @@ +[deps] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/fixtures/WackyOptions/test/runtests.jl b/test/fixtures/WackyOptions/test/runtests.jl new file mode 100644 index 00000000..730cd5aa --- /dev/null +++ b/test/fixtures/WackyOptions/test/runtests.jl @@ -0,0 +1,6 @@ +using WackyOptions +using Test + +@testset "WackyOptions.jl" begin + # Write your tests here. +end diff --git a/test/fixtures/static.txt b/test/fixtures/static.txt new file mode 100644 index 00000000..7846e37f --- /dev/null +++ b/test/fixtures/static.txt @@ -0,0 +1 @@ +DO NOT CHANGE THE CONTENTS OF THIS FILE! diff --git a/test/git.jl b/test/git.jl new file mode 100644 index 00000000..25ac3192 --- /dev/null +++ b/test/git.jl @@ -0,0 +1,51 @@ +@testset "Git repositories" begin + @testset "Does not create Git repo" begin + t = tpl(; disable_defaults=[Git]) + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + @test !isdir(joinpath(pkg_dir, ".git")) + end + end + + @testset "Creates Git repo" begin + t = tpl(; plugins=[Git()]) + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + @test isdir(joinpath(pkg_dir, ".git")) + end + end + + @testset "With HTTPS" begin + t = tpl(; plugins=[Git(; ssh=false)]) + with_pkg(t) do pkg + LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo + remote = LibGit2.get(GitRemote, repo, "origin") + @test startswith(LibGit2.url(remote), "https://") + end + end + end + + @testset "With SSH" begin + t = tpl(; plugins=[Git(; ssh=true)]) + with_pkg(t) do pkg + LibGit2.with(GitRepo(joinpath(t.dir, pkg))) do repo + remote = LibGit2.get(GitRemote, repo, "origin") + @test startswith(LibGit2.url(remote), "git@") + end + end + end + + @testset "Adds version to commit message" begin + # We're careful to avoid a Pkg.update as it triggers Cassette#130. + t = tpl(; disable_defaults=[Tests], plugins=[Git()]) + mock(PT.version_of => _p -> v"1.2.3") do _i + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + LibGit2.with(GitRepo(pkg_dir)) do repo + commit = GitCommit(repo, "HEAD") + @test occursin("PkgTemplates version: 1.2.3", LibGit2.message(commit)) + end + end + end + end +end diff --git a/test/gitconfig b/test/gitconfig deleted file mode 100644 index 8675f326..00000000 --- a/test/gitconfig +++ /dev/null @@ -1,3 +0,0 @@ -[user] - name = Travis - email = travis@c.i diff --git a/test/interactive/interactive.jl b/test/interactive/interactive.jl deleted file mode 100644 index f04e8f6c..00000000 --- a/test/interactive/interactive.jl +++ /dev/null @@ -1,68 +0,0 @@ -@testset "Interactive mode" begin - @testset "Template creation" begin - write(stdin.buffer, "$me\n\n\r\n\n\n\n\nd") - t = interactive_template() - @test t.user == me - @test t.host == "github.com" - @test isempty(t.license) - @test t.authors == LibGit2.getconfig("user.name", "") - @test t.dir == default_dir - @test t.julia_version == VERSION - @test !t.ssh - @test t.dev - @test !t.manifest - @test isempty(t.plugins) - - if isempty(LibGit2.getconfig("github.user", "")) - write(stdin.buffer, "\n") - @test_throws ArgumentError t = interactive_template() - end - - down = '\x1b' * "[B" # Down array key. - write(stdin.buffer, "$me\ngitlab.com\n$down\r$me\n$test_file\n0.5\nyes\nno\nyes\n$down\r$down\rd\n\n") - t = interactive_template() - @test t.user == me - @test t.host == "gitlab.com" - # Not sure if the order the licenses are displayed in is consistent. - @test !isempty(t.license) - @test t.authors == me - @test t.dir == abspath(test_file) - @test t.julia_version == v"0.5.0" - @test t.ssh - @test !t.dev - @test t.manifest - # Like above, not sure which plugins this will generate. - @test length(t.plugins) == 2 - - write(stdin.buffer, "$me\nd") - t = interactive_template(; fast=true) - @test t.user == me - @test t.host == "github.com" - @test t.license == "MIT" - @test t.authors == LibGit2.getconfig("user.name", "") - @test t.dir == default_dir - @test t.julia_version == VERSION - @test !t.ssh - @test !t.manifest - @test isempty(t.plugins) - println() - - # Host and SSH aren't prompted for when git is disabled. - write(stdin.buffer, "$me\n\n\r\n\n\n\nd") - t = interactive_template(; git=false) - @test t.host == "github.com" - @test !t.ssh - println() - end - - @testset "Package generation" begin - write(stdin.buffer, "$me\n\n\r\n\n\n\n\n\n\n\nd") - generate_interactive(test_pkg; gitconfig=gitconfig) - @test isdir(joinpath(default_dir, test_pkg)) - rm(joinpath(default_dir, test_pkg); force=true, recursive=true) - end - - @testset "Plugins" begin - include("plugins.jl") - end -end diff --git a/test/interactive/plugins.jl b/test/interactive/plugins.jl deleted file mode 100644 index 3c8760d0..00000000 --- a/test/interactive/plugins.jl +++ /dev/null @@ -1,90 +0,0 @@ -# These tests are to be skipped in OSX builds, see ./interactive.jl for more info. - -@testset "TravisCI" begin - write(stdin.buffer, "\n") - p = interactive(TravisCI) - @test p.src == joinpath(DEFAULTS_DIR, "travis.yml") - write(stdin.buffer, "$test_file\n") - p = interactive(TravisCI) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(TravisCI) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(TravisCI) - println() -end - -@testset "AppVeyor" begin - write(stdin.buffer, "\n") - p = interactive(AppVeyor) - @test p.src == joinpath(DEFAULTS_DIR, "appveyor.yml") - write(stdin.buffer, "$test_file\n") - p = interactive(AppVeyor) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(AppVeyor) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(AppVeyor) - println() -end - -@testset "GitLabCI" begin - write(stdin.buffer, "\n\n") - p = interactive(GitLabCI) - @test p.src == joinpath(DEFAULTS_DIR, "gitlab-ci.yml") - @test p.view == Dict("GITLABCOVERAGE" => true) - write(stdin.buffer, "$test_file\nno\n") - p = interactive(GitLabCI) - @test p.src == test_file - @test p.view == Dict("GITLABCOVERAGE" => false) - write(stdin.buffer, "none\n\n") - p = interactive(GitLabCI) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n\n") - @test_throws ArgumentError interactive(GitLabCI) - println() -end - -@testset "Codecov" begin - write(stdin.buffer, "\n") - p = interactive(Codecov) - @test p.src === nothing - write(stdin.buffer, "$test_file\n") - p = interactive(Codecov) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(Codecov) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(Codecov) - println() -end - -@testset "Coveralls" begin - write(stdin.buffer, "\n") - p = interactive(Coveralls) - @test p.src === nothing - write(stdin.buffer, "$test_file\n") - p = interactive(Coveralls) - @test p.src == test_file - write(stdin.buffer, "none\n") - p = interactive(Coveralls) - @test p.src === nothing - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(Coveralls) - println() -end - -@testset "GitHubPages" begin - write(stdin.buffer, "\n") - p = interactive(GitHubPages) - @test isempty(p.assets) - write(stdin.buffer, "$test_file\n") - p = interactive(GitHubPages) - @test p.assets == [test_file] - write(stdin.buffer, "$fake_path\n") - @test_throws ArgumentError interactive(GitHubPages) - println() -end diff --git a/test/plugin.jl b/test/plugin.jl new file mode 100644 index 00000000..975dea3a --- /dev/null +++ b/test/plugin.jl @@ -0,0 +1,37 @@ +# Don't move this line from the top, please. {{X}} {{Y}} {{Z}} + +struct BasicTest <: PT.BasicPlugin end + +PT.gitignore(::BasicTest) = ["a", "aa", "aaa"] +PT.source(::BasicTest) = @__FILE__ +PT.destination(::BasicTest) = "foo.txt" +PT.badges(::BasicTest) = PT.Badge("{{X}}", "{{Y}}", "{{Z}}") +PT.view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 0, "Y" => 2) +PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" => 3) + +@testset "Plugins" begin + @testset "BasicPlugin" begin + p = BasicTest() + t = tpl(; plugins=[p]) + + # The X from user_view should override the X from view. + s = PT.render_plugin(p, t, "") + @test occursin("1 2 3", first(split(s, "\n"))) + + with_pkg(t) do pkg + pkg_dir = joinpath(t.dir, pkg) + badge = string(PT.Badge("1", "2", "3")) + @test occursin("a\naa\naaa", read(joinpath(pkg_dir, ".gitignore"), String)) + @test occursin(badge, read(joinpath(pkg_dir, "README.md"), String)) + @test read(joinpath(pkg_dir, "foo.txt"), String) == s + end + end + + @testset "Tests Project.toml warning on Julia < 1.2" begin + p = Tests(; project=true) + @test_logs (:warn, r"The project option is set") tpl(; julia=v"1", plugins=[p]) + @test_logs (:warn, r"The project option is set") tpl(; julia=v"1.1", plugins=[p]) + @test_logs tpl(; julia=v"1.2", plugins=[p]) + @test_logs tpl(; julia=v"1.3", plugins=[p]) + end +end diff --git a/test/plugins/appveyor.jl b/test/plugins/appveyor.jl deleted file mode 100644 index de81e727..00000000 --- a/test/plugins/appveyor.jl +++ /dev/null @@ -1,57 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "AppVeyor" begin - @testset "Plugin creation" begin - p = AppVeyor() - @test isempty(p.gitignore) - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "appveyor.yml") - @test p.dest == ".appveyor.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://ci.appveyor.com/api/projects/status/github/{{USER}}/{{PKGNAME}}.jl?svg=true", - "https://ci.appveyor.com/project/{{USER}}/{{PKGNAME}}-jl", - ), - ] - @test isempty(p.view) - p = AppVeyor(; config_file=nothing) - @test p.src === nothing - p = AppVeyor(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError AppVeyor(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = AppVeyor() - @test badges(p, me, test_pkg) == ["[![Build Status](https://ci.appveyor.com/api/projects/status/github/$me/$test_pkg.jl?svg=true)](https://ci.appveyor.com/project/$me/$test_pkg-jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no post-test step. - p = AppVeyor() - @test gen_plugin(p, t, test_pkg) == [".appveyor.yml"] - @test isfile(joinpath(pkg_dir, ".appveyor.yml")) - appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) - @test !occursin("on_success", appveyor) - @test !occursin("%JL_CODECOV_SCRIPT%", appveyor) - rm(joinpath(pkg_dir, ".appveyor.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - appveyor = read(joinpath(pkg_dir, ".appveyor.yml"), String) - @test occursin("on_success", appveyor) - @test occursin("%JL_CODECOV_SCRIPT%", appveyor) - rm(joinpath(pkg_dir, ".appveyor.yml")) - - # TODO: Add Coveralls tests when AppVeyor.jl supports it. - - p = AppVeyor(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".appveyor.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/cirrusci.jl b/test/plugins/cirrusci.jl deleted file mode 100644 index 9efc1eb7..00000000 --- a/test/plugins/cirrusci.jl +++ /dev/null @@ -1,54 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "CirrusCI" begin - @testset "Plugin creation" begin - p = CirrusCI() - @test isempty(p.gitignore) - @test p.src == joinpath(DEFAULTS_DIR, "cirrus.yml") - @test p.dest == ".cirrus.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://api.cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl.svg", - "https://cirrus-ci.com/github/{{USER}}/{{PKGNAME}}.jl", - ), - ] - @test isempty(p.view) - p = CirrusCI(; config_file=nothing) - @test p.src === nothing - p = CirrusCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError CirrusCI(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = CirrusCI() - @test badges(p, me, test_pkg) == ["[![Build Status](https://api.cirrus-ci.com/github/$me/$test_pkg.jl.svg)](https://cirrus-ci.com/github/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no coverage step. - p = CirrusCI() - @test gen_plugin(p, t, test_pkg) == [".cirrus.yml"] - @test isfile(joinpath(pkg_dir, ".cirrus.yml")) - cirrus = read(joinpath(pkg_dir, ".cirrus.yml"), String) - @test !occursin("coverage_script", cirrus) - rm(joinpath(pkg_dir, ".cirrus.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - cirrus = read(joinpath(pkg_dir, ".cirrus.yml"), String) - @test occursin("coverage_script", cirrus) - @test occursin("cirrusjl coverage", cirrus) - rm(joinpath(pkg_dir, ".cirrus.yml")) - - p = CirrusCI(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".cirrus.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/citation.jl b/test/plugins/citation.jl deleted file mode 100644 index 888660f7..00000000 --- a/test/plugins/citation.jl +++ /dev/null @@ -1,48 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "CITATION" begin - @testset "Plugin creation" begin - p = Citation() - @test isempty(p.gitignore) - @test p.dest == "CITATION.bib" - @test isempty(p.badges) - @test isempty(p.view) - @test !p.readme_section - p = Citation(; readme_section=true) - @test p.readme_section - end - - @testset "File generation" begin - p = Citation() - @test gen_plugin(p, t, test_pkg) == ["CITATION.bib"] - @test isfile(joinpath(pkg_dir, "CITATION.bib")) - citation = read(joinpath(pkg_dir, "CITATION.bib"), String) - - @test occursin("@misc", citation) - @test occursin("$(t.authors)", citation) - @test occursin("v0.1.0", citation) - end - - @testset "Readme untouched" begin - p = Citation(; readme_section=false) - t.plugins[Citation] = p - isdir(pkg_dir) && rm(pkg_dir; recursive=true) - generate(test_pkg, t, git=false) - readme = read(joinpath(pkg_dir, "README.md"), String) - @test !occursin("## Citing", readme) - @test !occursin("CITATION.bib", readme) - end - - @testset "Readme modification" begin - p = Citation(; readme_section=true) - t.plugins[Citation] = p - isdir(pkg_dir) && rm(pkg_dir; recursive=true) - generate(test_pkg, t, git=false) - readme = read(joinpath(pkg_dir, "README.md"), String) - @test occursin("## Citing", readme) - @test occursin("CITATION.bib", readme) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/codecov.jl b/test/plugins/codecov.jl deleted file mode 100644 index b7648d8d..00000000 --- a/test/plugins/codecov.jl +++ /dev/null @@ -1,41 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "Codecov" begin - @testset "Plugin creation" begin - p = Codecov() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src === nothing - @test p.dest == ".codecov.yml" - @test p.badges == [ - Badge( - "Codecov", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl/branch/master/graph/badge.svg", - "https://codecov.io/gh/{{USER}}/{{PKGNAME}}.jl", - ) - ] - @test isempty(p.view) - p = Codecov(; config_file=nothing) - @test p.src === nothing - p = Codecov(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError Codecov(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = Codecov() - @test badges(p, me, test_pkg) == ["[![Codecov](https://codecov.io/gh/$me/$test_pkg.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - p = Codecov() - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".codecov.yml")) - - p = Codecov(; config_file=test_file) - @test gen_plugin(p, t, test_pkg) == [".codecov.yml"] - @test isfile(joinpath(pkg_dir, ".codecov.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/coveralls.jl b/test/plugins/coveralls.jl deleted file mode 100644 index f74e2197..00000000 --- a/test/plugins/coveralls.jl +++ /dev/null @@ -1,40 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "Coveralls" begin - @testset "Plugin creation" begin - p = Coveralls() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src === nothing - @test p.dest == ".coveralls.yml" - @test p.badges == [ - Badge( - "Coveralls", - "https://coveralls.io/repos/github/{{USER}}/{{PKGNAME}}.jl/badge.svg?branch=master", - "https://coveralls.io/github/{{USER}}/{{PKGNAME}}.jl?branch=master", - ) - ] - @test isempty(p.view) - p = Coveralls(; config_file=nothing) - @test p.src === nothing - p = Coveralls(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError Coveralls(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = Coveralls() - @test badges(p, me, test_pkg) == ["[![Coveralls](https://coveralls.io/repos/github/$me/$test_pkg.jl/badge.svg?branch=master)](https://coveralls.io/github/$me/$test_pkg.jl?branch=master)"] - end - - @testset "File generation" begin - p = Coveralls() - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".coveralls.yml")) - p = Coveralls(; config_file=test_file) - @test gen_plugin(p, t, test_pkg) == [".coveralls.yml"] - @test isfile(joinpath(pkg_dir, ".coveralls.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/droneci.jl b/test/plugins/droneci.jl deleted file mode 100644 index 5b7fc6f1..00000000 --- a/test/plugins/droneci.jl +++ /dev/null @@ -1,41 +0,0 @@ -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) diff --git a/test/plugins/githubpages.jl b/test/plugins/githubpages.jl deleted file mode 100644 index 7ea563fb..00000000 --- a/test/plugins/githubpages.jl +++ /dev/null @@ -1,68 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitHubPages" begin - @testset "Plugin creation" begin - p = GitHubPages() - @test p.gitignore == ["/docs/build/", "/docs/site/"] - @test isempty(p.assets) - p = GitHubPages(; assets=[test_file]) - @test p.assets == [test_file] - @test_throws ArgumentError GitHubPages(; assets=[fake_path]) - end - - @testset "Badge generation" begin - p = GitHubPages() - @test badges(p, me, test_pkg) == [ - "[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://$me.github.io/$test_pkg.jl/stable)" - "[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://$me.github.io/$test_pkg.jl/dev)" - ] - end - - @testset "File generation" begin - p = GitHubPages() - @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")) - @test occursin("assets=String[]", make) - @test !occursin("deploydocs", make) - @test isdir(joinpath(pkg_dir, "docs", "src")) - @test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) - index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md")) - @test occursin("autodocs", index) - rm(joinpath(pkg_dir, "docs"); recursive=true) - p = GitHubPages(; assets=[test_file]) - @test gen_plugin(p, t, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - # Check the formatting of the assets list. - @test occursin( - strip(""" - assets=[ - "assets/$(basename(test_file))", - ] - """), - make, - ) - @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, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("deploydocs", make) - rm(joinpath(pkg_dir, "docs"); recursive=true) - end - - @testset "Package generation with GitHubPages plugin" begin - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir, plugins=[GitHubPages()]) - generate(test_pkg, t; gitconfig=gitconfig) - - # Check that the gh-pages branch exists. - repo = LibGit2.GitRepo(joinpath(t.dir, test_pkg)) - branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) - @test in("gh-pages", branches) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/gitlabci.jl b/test/plugins/gitlabci.jl deleted file mode 100644 index e5561564..00000000 --- a/test/plugins/gitlabci.jl +++ /dev/null @@ -1,69 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitLabCI" begin - @testset "Plugin creation" begin - p = GitLabCI() - @test p.gitignore == ["*.jl.cov", "*.jl.*.cov", "*.jl.mem"] - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "gitlab-ci.yml") - @test p.dest == ".gitlab-ci.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - Badge( - "Coverage", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/coverage.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/commits/master", - ), - ] - @test p.view == Dict("GITLABCOVERAGE" => true) - p = GitLabCI(; config_file=nothing) - @test p.src === nothing - p = GitLabCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError GitLabCI(; config_file=fake_path) - p = GitLabCI(; coverage=false) - @test p.badges == [ - Badge( - "Build Status", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/badges/master/build.svg", - "https://gitlab.com/{{USER}}/{{PKGNAME}}.jl/pipelines", - ), - ] - @test p.view == Dict("GITLABCOVERAGE" => false) - end - - @testset "Badge generation" begin - p = GitLabCI() - @test badges(p, me, test_pkg) == [ - "[![Build Status](https://gitlab.com/$me/$test_pkg.jl/badges/master/build.svg)](https://gitlab.com/$me/$test_pkg.jl/pipelines)", - "[![Coverage](https://gitlab.com/$me/$test_pkg.jl/badges/master/coverage.svg)](https://gitlab.com/$me/$test_pkg.jl/commits/master)", - ] - end - - @testset "File generation" begin - p = GitLabCI() - @test gen_plugin(p, t, test_pkg) == [".gitlab-ci.yml"] - @test isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) - gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) - # The default plugin should enable the coverage step. - @test occursin("using Coverage", gitlab) - rm(joinpath(pkg_dir, ".gitlab-ci.yml")) - - p = GitLabCI(; coverage=false) - gen_plugin(p, t, test_pkg) - gitlab = read(joinpath(pkg_dir, ".gitlab-ci.yml"), String) - # If coverage is false, there should be no coverage step. - @test !occursin("using Coverage", gitlab) - rm(joinpath(pkg_dir, ".gitlab-ci.yml")) - p = GitLabCI(; config_file=nothing) - - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".gitlab-ci.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/gitlabpages.jl b/test/plugins/gitlabpages.jl deleted file mode 100644 index 299206d5..00000000 --- a/test/plugins/gitlabpages.jl +++ /dev/null @@ -1,60 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "GitLabPages" begin - @testset "Plugin creation" begin - p = GitLabPages() - @test p.gitignore == ["/docs/build/", "/docs/site/"] - @test isempty(p.assets) - p = GitLabPages(; assets=[test_file]) - @test p.assets == [test_file] - @test_throws ArgumentError GitLabPages(; assets=[fake_path]) - end - - @testset "Badge generation" begin - p = GitLabPages() - @test badges(p, me, test_pkg) == [ - "[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://$me.gitlab.io/$test_pkg.jl/dev)" - ] - end - - @testset "File generation" begin - p = GitLabPages() - @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")) - @test occursin("assets=String[]", make) - @test !occursin("deploydocs", make) - @test isdir(joinpath(pkg_dir, "docs", "src")) - @test isfile(joinpath(pkg_dir, "docs", "src", "index.md")) - index = readchomp(joinpath(pkg_dir, "docs", "src", "index.md")) - @test occursin("autodocs", index) - rm(joinpath(pkg_dir, "docs"); recursive=true) - p = GitLabPages(; assets=[test_file]) - @test gen_plugin(p, t, test_pkg) == ["docs/"] - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - # Check the formatting of the assets list. - @test occursin( - strip(""" - assets=[ - "assets/$(basename(test_file))", - ] - """), - make, - ) - @test isfile(joinpath(pkg_dir, "docs", "src", "assets", basename(test_file))) - rm(joinpath(pkg_dir, "docs"); recursive=true) - end - - @testset "Package generation with GitLabPages plugin" begin - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir, plugins=[GitLabCI(), GitLabPages()]) - generate(test_pkg, t; gitconfig=gitconfig) - - gitlab = read(joinpath(t.dir, test_pkg, ".gitlab-ci.yml"), String) - @test occursin("pages:", gitlab) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/plugins/travisci.jl b/test/plugins/travisci.jl deleted file mode 100644 index 20d1fbb8..00000000 --- a/test/plugins/travisci.jl +++ /dev/null @@ -1,82 +0,0 @@ -t = Template(; user=me) -pkg_dir = joinpath(t.dir, test_pkg) - -@testset "TravisCI" begin - @testset "Plugin creation" begin - p = TravisCI() - @test isempty(p.gitignore) - @test p.src == joinpath(PkgTemplates.DEFAULTS_DIR, "travis.yml") - @test p.dest == ".travis.yml" - @test p.badges == [ - Badge( - "Build Status", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl.svg?branch=master", - "https://travis-ci.com/{{USER}}/{{PKGNAME}}.jl", - ), - ] - @test isempty(p.view) - p = TravisCI(; config_file=nothing) - @test p.src === nothing - p = TravisCI(; config_file=test_file) - @test p.src == test_file - @test_throws ArgumentError TravisCI(; config_file=fake_path) - end - - @testset "Badge generation" begin - p = TravisCI() - @test badges(p, me, test_pkg) == ["[![Build Status](https://travis-ci.com/$me/$test_pkg.jl.svg?branch=master)](https://travis-ci.com/$me/$test_pkg.jl)"] - end - - @testset "File generation" begin - # Without a coverage plugin in the template, there should be no post-test step. - p = TravisCI() - @test gen_plugin(p, t, test_pkg) == [".travis.yml"] - @test isfile(joinpath(pkg_dir, ".travis.yml")) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - - @test !occursin("after_success", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # Generating the plugin with Codecov in the template should create a post-test step. - t.plugins[Codecov] = Codecov() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Codecov) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # Coveralls should do the same. - t.plugins[Coveralls] = Coveralls() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, Coveralls) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("Coveralls.submit", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("stage: Documentation", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - # With a Documenter plugin, there should be a docs deployment step. - t.plugins[GitHubPages] = GitHubPages() - gen_plugin(p, t, test_pkg) - delete!(t.plugins, GitHubPages) - travis = read(joinpath(pkg_dir, ".travis.yml"), String) - @test occursin("after_success", travis) - @test occursin("stage: Documentation", travis) - @test !occursin("Codecov.submit", travis) - @test !occursin("Coveralls.submit", travis) - rm(joinpath(pkg_dir, ".travis.yml")) - - p = TravisCI(; config_file=nothing) - @test isempty(gen_plugin(p, t, test_pkg)) - @test !isfile(joinpath(pkg_dir, ".travis.yml")) - end -end - -rm(pkg_dir; recursive=true) diff --git a/test/reference.jl b/test/reference.jl new file mode 100644 index 00000000..6618693d --- /dev/null +++ b/test/reference.jl @@ -0,0 +1,72 @@ +const STATIC_FILE = joinpath(@__DIR__, "fixtures", "static.txt") + +PT.user_view(::Citation, ::Template, ::AbstractString) = Dict("MONTH" => 8, "YEAR" => 2019) +PT.user_view(::License, ::Template, ::AbstractString) = Dict("YEAR" => 2019) + +function test_all(pkg::AbstractString; kwargs...) + t = tpl(; kwargs...) + with_pkg(t, pkg) do pkg + pkg_dir = joinpath(t.dir, pkg) + foreach(readlines(`git -C $pkg_dir ls-files`)) do f + reference = joinpath(@__DIR__, "fixtures", pkg, f) + observed = read(joinpath(pkg_dir, f), String) + @test_reference reference observed + end + end +end + +@testset "Reference tests" begin + @testset "Default package" begin + test_all("Basic"; authors=USER) + end + + @testset "All plugins" begin + test_all("AllPlugins"; authors=USER, plugins=[ + AppVeyor(), CirrusCI(), Citation(), Codecov(), Coveralls(), Develop(), + Documenter(), DroneCI(), GitHubActions(), GitLabCI(), TravisCI(), + ]) + end + + @testset "Documenter (TravisCI)" begin + test_all("DocumenterTravis"; authors=USER, plugins=[ + Documenter{TravisCI}(), TravisCI(), + ]) + end + + @testset "Documenter (GitHubActions)" begin + test_all("DocumenterGitHubActions"; authors=USER, plugins=[ + Documenter{GitHubActions}(), GitHubActions(), + ]) + end + + + @testset "Wacky options" begin + test_all("WackyOptions"; authors=USER, julia=v"1.2", plugins=[ + AppVeyor(; x86=true, coverage=true, extra_versions=[v"1.3"]), + CirrusCI(; image="freebsd-123", coverage=false, extra_versions=["1.1"]), + Citation(; readme=true), + Codecov(; file=STATIC_FILE), + Coveralls(; file=STATIC_FILE), + Documenter{GitLabCI}( + assets=[STATIC_FILE], + makedocs_kwargs=Dict(:foo => "bar", :bar => "baz"), + canonical_url=(_t, _pkg) -> "http://example.com", + ), + DroneCI(; amd64=false, arm=true, arm64=true, extra_versions=["1.1"]), + Git(; ignore=["a", "b", "c"], manifest=true), + GitHubActions(; x86=true, linux=false, coverage=false), + GitLabCI(; coverage=false, extra_versions=[v"0.6"]), + License(; name="ISC"), + ProjectFile(; version=v"1"), + Readme(; inline_badges=true), + Tests(; project=true), + TravisCI(; + coverage=false, + windows=false, + x86=true, + arm64=true, + extra_versions=["1.1"], + ), + ]) + end +end diff --git a/test/runtests.jl b/test/runtests.jl index d3234388..aab362f6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,20 +1,65 @@ +using Base.Filesystem: contractuser, path_separator + +using LibGit2: LibGit2, GitCommit, GitRemote, GitRepo +using Pkg: Pkg +using Random: Random, randstring +using Test: @test, @testset, @test_logs, @test_throws + +using ReferenceTests: @test_reference +using SimpleMock: mock +using Suppressor: @suppress + using PkgTemplates -using Test -using Dates -using LibGit2 -using Pkg - -import PkgTemplates: badges, version_floor, substitute, read_license, gen_file, gen_readme, - gen_tests, gen_license, gen_gitignore, gen_plugin, show_license, LICENSES, - LICENSE_DIR, Plugin, GenericPlugin, CustomPlugin, Badge, format, interactive, - DEFAULTS_DIR, Documenter - -mktempdir() do temp_dir - mkdir(joinpath(temp_dir, "dev")) - pushfirst!(DEPOT_PATH, temp_dir) - cd(temp_dir) do +const PT = PkgTemplates + +const USER = "tester" + +Random.seed!(1) + +# Creata a template that won't error because of a missing username. +tpl(; kwargs...) = Template(; user=USER, kwargs...) + +# Generate a random package name. +pkgname() = titlecase(randstring('A':'Z', 16)) + +# Create a randomly named package with a template, and delete it afterwards. +function with_pkg(f::Function, t::Template, pkg::AbstractString=pkgname()) + @suppress t(pkg) + try + f(pkg) + finally + # On 1.4, this sometimes won't work, but the error is that the package isn't installed. + # We're going to delete the package directory anyways, so just ignore any errors. + PT.version_of(pkg) === nothing || try @suppress Pkg.rm(pkg) catch; end + rm(joinpath(t.dir, pkg); recursive=true, force=true) + end +end + +mktempdir() do dir + Pkg.activate(dir) + pushfirst!(DEPOT_PATH, dir) + try @testset "PkgTemplates.jl" begin - include("tests.jl") + include("template.jl") + include("plugin.jl") + include("show.jl") + + if PT.git_is_installed() + include("git.jl") + + # Quite a bit of output depends on the Julia version, + # and the test fixtures are made with Julia 1.2. + # TODO: Keep this on the latest stable Julia version. + if VERSION.major == 1 && VERSION.minor == 2 + include("reference.jl") + else + @info "Skipping reference tests" julia=VERSION + end + else + @info "Git is not installed, skipping Git and reference tests" + end end + finally + popfirst!(DEPOT_PATH) end end diff --git a/test/show.jl b/test/show.jl new file mode 100644 index 00000000..688e7bb1 --- /dev/null +++ b/test/show.jl @@ -0,0 +1,62 @@ +const TEMPLATES_DIR = contractuser(PT.TEMPLATES_DIR) +const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses") + +@testset "Show methods" begin + @testset "Plugins" begin + expected = """ + Readme: + file: "$(joinpath(TEMPLATES_DIR, "README.md"))" + destination: "README.md" + inline_badges: false + """ + @test sprint(show, MIME("text/plain"), Readme()) == rstrip(expected) + end + + @testset "Template" begin + expected = """ + Template: + authors: ["Chris de Graaf "] + dir: "~/.local/share/julia/dev" + host: "github.com" + julia: v"1.0.0" + user: "$USER" + plugins: + """ + expected = """ + Template: + authors: ["$USER"] + dir: "$(contractuser(Pkg.devdir()))" + host: "github.com" + julia: v"1.0.0" + user: "$USER" + plugins: + Git: + ignore: String[] + ssh: false + manifest: false + gpgsign: false + License: + path: "$(joinpath(LICENSES_DIR, "MIT"))" + destination: "LICENSE" + ProjectFile: + version: v"0.1.0" + Readme: + file: "$(joinpath(TEMPLATES_DIR, "README.md"))" + destination: "README.md" + inline_badges: false + SrcDir: + file: "$(joinpath(TEMPLATES_DIR, "src", "module.jl"))" + Tests: + file: "$(joinpath(TEMPLATES_DIR, "test", "runtests.jl"))" + project: false + """ + @test sprint(show, MIME("text/plain"), tpl(; authors=USER)) == rstrip(expected) + end + + @testset "show as serialization" begin + # Equality is not implemented for Template, so check the string form. + t1 = tpl() + t2 = eval(Meta.parse(sprint(show, t1))) + @test sprint(show, t1) == sprint(show, t2) + end +end diff --git a/test/template.jl b/test/template.jl new file mode 100644 index 00000000..aaa1f445 --- /dev/null +++ b/test/template.jl @@ -0,0 +1,90 @@ +@testset "Template" begin + @testset "Template constructor" begin + @testset "user" begin + mock(PT.default_user => () -> "") do _du + @test_throws ArgumentError Template() + @test isempty(Template(; disable_defaults=[Git]).user) + end + mock(PT.default_user => () -> "username") do _du + @test Template().user == "username" + end + end + + @testset "authors" begin + @test tpl(; authors=["a"]).authors == ["a"] + @test tpl(; authors="a").authors == ["a"] + @test tpl(; authors="a,b").authors == ["a", "b"] + @test tpl(; authors="a, b").authors == ["a", "b"] + end + + @testset "host" begin + @test tpl(; host="https://foo.com").host == "foo.com" + end + + @testset "dir" begin + @test tpl(; dir="/foo/bar").dir == joinpath(path_separator, "foo", "bar") + @test tpl(; dir="foo").dir == abspath("foo") + @test tpl(; dir="~/foo").dir == abspath(expanduser("~/foo")) + end + + @testset "plugins / disabled_defaults" begin + function test_plugins(plugins, expected, disabled=DataType[]) + t = tpl(; plugins=plugins, disable_defaults=disabled) + @test all(map(==, sort(t.plugins; by=string), sort(expected; by=string))) + end + + defaults = PT.default_plugins() + test_plugins([], defaults) + test_plugins([Citation()], union(defaults, [Citation()])) + # Overriding a default plugin. + default_g = defaults[findfirst(p -> p isa Git, defaults)] + g = Git(; ssh=true) + test_plugins([g], union(setdiff(defaults, [default_g]), [g])) + # Disabling a default plugin. + test_plugins([], setdiff(defaults, [default_g]), [Git]) + end + + @testset "Unsupported keywords warning" begin + @test_logs tpl() + @test_logs (:warn, r"Unrecognized keywords were supplied") tpl(; x=1, y=2) + end + end + + @testset "hasplugin" begin + t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()]) + @test PT.hasplugin(t, typeof(first(PT.default_plugins()))) + @test PT.hasplugin(t, Documenter) + @test PT.hasplugin(t, PT.is_ci) + @test PT.hasplugin(t, _ -> true) + @test !PT.hasplugin(t, _ -> false) + @test !PT.hasplugin(t, Citation) + end + + @testset "validate" begin + foreach((GitHubActions, TravisCI, GitLabCI)) do T + @test_throws ArgumentError tpl(; plugins=[Documenter{T}()]) + end + mock(LibGit2.getconfig => (_k, _d) -> "") do _gc + @test_throws ArgumentError tpl(; plugins=[Git()]) + end + end +end + +@testset "Package generation errors" begin + mktempdir() do dir + t = tpl(; dir=dirname(dir)) + @test_throws ArgumentError t(basename(dir)) + end + + mktemp() do f, _io + t = tpl(; dir=dirname(f)) + @test_throws ArgumentError t(basename(f)) + end + + t = tpl() + pkg = pkgname() + mock(LibGit2.init => dir -> (@test isdir(dir); error())) do _init + @test_throws ErrorException @suppress t(pkg) + end + @test !isdir(joinpath(t.dir, pkg)) +end diff --git a/test/tests.jl b/test/tests.jl deleted file mode 100644 index 198e0f10..00000000 --- a/test/tests.jl +++ /dev/null @@ -1,493 +0,0 @@ -# A dummy GenericPlugin subtype. -struct Foo <: GenericPlugin - gitignore::Vector{AbstractString} - src::Union{AbstractString, Nothing} - dest::AbstractString - badges::Vector{Badge} - view::Dict{String, Any} - function Foo(; config_file=test_file) - new([], @__FILE__, config_file, [Badge("foo", "bar", "baz")], Dict{String, Any}()) - end -end -# A dummy CustomPlugin subtype. -struct Bar <: CustomPlugin end -# A dummy Plugin subtype. -struct Baz <: Plugin end -# A Documenter with extra kwargs -struct Qux <: Documenter - assets::Vector{AbstractString} - additional_kwargs::Union{AbstractDict, NamedTuple} -end - -# Various options to be passed into templates. -const me = "christopher-dG" -const test_pkg = "TestPkg" -const fake_path = "/dev/null/this/file/does/not/exist" -const test_file = tempname() -const default_dir = Pkg.devdir() -const gitconfig = GitConfig(joinpath(@__DIR__, "gitconfig")) -const template_text = """ - PKGNAME: {{PKGNAME}} - VERSION: {{VERSION}}} - {{#DOCUMENTER}}Documenter{{/DOCUMENTER}} - {{#CODECOV}}Codecov{{/CODECOV}} - {{#COVERALLS}}Coveralls{{/COVERALLS}} - {{#AFTER}}After{{/AFTER}} - {{#OTHER}}Other{{/OTHER}} - """ -write(test_file, template_text) - -@testset "Template creation" begin - # Checking default field assignments. - t = Template(; authors="foo", user=me) - @test t.user == me - @test t.license == "MIT" - @test t.authors == "foo" - @test t.dir == default_dir - @test t.julia_version == PkgTemplates.default_version() - @test !t.ssh - @test !t.manifest - @test isempty(t.plugins) - - # Checking non-default field assignments. - - t = Template(; user=me, license="") - @test t.license == "" - - t = Template(; user=me, license="MPL") - @test t.license == "MPL" - - t = Template(; user=me, authors="Some Guy") - @test t.authors == "Some Guy" - # Vectors of authors should be comma-joined. - t = Template(; user=me, authors=["Guy", "Gal"]) - @test t.authors == "Guy, Gal" - - t = Template(; user=me, dir=test_file) - @test t.dir == abspath(test_file) - if Sys.isunix() # ~ means temporary file on Windows, not $HOME. - # '~' should be replaced by home dir. - t = Template(; user=me, dir="~/$(basename(test_file))") - @test t.dir == joinpath(homedir(), basename(test_file)) - end - - t = Template(; user=me, julia_version=v"0.1.2") - @test t.julia_version == v"0.1.2" - - t = Template(; user=me, ssh=true) - @test t.ssh - - t = Template(; user=me, manifest=true) - @test t.manifest - - # The template should contain whatever plugins you give it. - t = Template(; - user=me, - plugins = [GitHubPages(), TravisCI(), AppVeyor(), Codecov(), Coveralls()], - ) - @test Set(keys(t.plugins)) == Set(map(typeof, values(t.plugins))) == Set( - [GitHubPages, TravisCI, AppVeyor, Codecov, Coveralls] - ) - - # Duplicate plugins should warn. - @test_logs (:warn, r"duplicates") match_mode=:any t = Template(; - user=me, - plugins=[TravisCI(), TravisCI()], - ) - - # If github.user is configured, use that as a default. - if isempty(LibGit2.getconfig("github.user", "")) - @test_throws ArgumentError Template() - else - t = Template() - @test t.user == LibGit2.getconfig("github.user", "") - end - @test_throws ArgumentError Template(; user=me, license="FakeLicense") -end - -@testset "Show methods" begin - pkg_dir = replace(default_dir, homedir() => "~") - ver = PkgTemplates.version_floor(PkgTemplates.default_version()) - buf = IOBuffer() - t = Template(; user=me, authors="foo") - show(buf, t) - text = String(take!(buf)) - expected = """ - Template: - → User: $me - → Host: github.com - → License: MIT (foo $(year(today()))) - → Package directory: $pkg_dir - → Minimum Julia version: v$ver - → SSH remote: No - → Add packages to main environment: Yes - → Commit Manifest.toml: No - → Plugins: None - """ - @test text == rstrip(expected) - t = Template( - user=me, - license="", - ssh=true, - manifest=true, - plugins=[ - TravisCI(), - Codecov(), - GitHubPages(), - ], - ) - show(buf, t) - text = String(take!(buf)) - expected = """ - Template: - → User: $me - → Host: github.com - → License: None - → Package directory: $pkg_dir - → Minimum Julia version: v$ver - → SSH remote: Yes - → Add packages to main environment: Yes - → Commit Manifest.toml: Yes - → Plugins: - • Codecov: - → Config file: None - → 3 gitignore entries: "*.jl.cov", "*.jl.*.cov", "*.jl.mem" - • GitHubPages: - → 0 asset files - → 2 gitignore entries: "/docs/build/", "/docs/site/" - • TravisCI: - → Config file: Default - → 0 gitignore entries - """ - @test text == rstrip(expected) -end - -@testset "File generation" begin - t = Template(; - user=me, - license="MPL", - plugins=[Coveralls(), TravisCI(), Codecov(), GitHubPages(), AppVeyor()], - ) - temp_dir = mktempdir() - pkg_dir = joinpath(temp_dir, test_pkg) - - temp_file = tempname() - gen_file(temp_file, "Hello, world") - @test isfile(temp_file) - @test read(temp_file, String) == "Hello, world\n" - rm(temp_file) - - # Test the README generation. - @test gen_readme(pkg_dir, t) == ["README.md"] - @test isfile(joinpath(pkg_dir, "README.md")) - readme = readchomp(joinpath(pkg_dir, "README.md")) - rm(joinpath(pkg_dir, "README.md")) - @test occursin("# $test_pkg", readme) - for p in values(t.plugins) - @test occursin(join(badges(p, t.user, test_pkg), "\n"), readme) - end - # Check the order of the badges. - @test something(findfirst("github.io", readme)).start < - something(findfirst("travis", readme)).start < - something(findfirst("appveyor", readme)).start < - something(findfirst("codecov", readme)).start < - something(findfirst("coveralls", readme)).start - # Plugins with badges but not in BADGE_ORDER should appear at the far right side. - t.plugins[Foo] = Foo() - gen_readme(pkg_dir, t) - readme = readchomp(joinpath(pkg_dir, "README.md")) - rm(joinpath(pkg_dir, "README.md")) - @test findfirst("coveralls", readme).start < findfirst("baz", readme).start - - # Test the gitignore generation. - @test gen_gitignore(pkg_dir, t) == [".gitignore"] - @test isfile(joinpath(pkg_dir, ".gitignore")) - gitignore = read(joinpath(pkg_dir, ".gitignore"), String) - rm(joinpath(pkg_dir, ".gitignore")) - @test occursin(".DS_Store", gitignore) - @test occursin("Manifest.toml", gitignore) - for p in values(t.plugins) - for entry in p.gitignore - @test occursin(entry, gitignore) - end - end - t = Template(; user=me, manifest=true) - @test gen_gitignore(pkg_dir, t) == [".gitignore", "Manifest.toml"] - gitignore = read(joinpath(pkg_dir, ".gitignore"), String) - @test !occursin("Manifest.toml", gitignore) - rm(joinpath(pkg_dir, ".gitignore")) - - # Test the license generation. - @test gen_license(pkg_dir, t) == ["LICENSE"] - @test isfile(joinpath(pkg_dir, "LICENSE")) - license = readchomp(joinpath(pkg_dir, "LICENSE")) - rm(joinpath(pkg_dir, "LICENSE")) - @test occursin(t.authors, license) - @test occursin(read_license(t.license), license) - - # Test the test generation. - @test gen_tests(pkg_dir, t) == ["test/"] - @test isfile(joinpath(pkg_dir, "Project.toml")) - project = read(joinpath(pkg_dir, "Project.toml"), String) - @test occursin("[extras]\nTest = ", project) - @test isdir(joinpath(pkg_dir, "test")) - @test isfile(joinpath(pkg_dir, "test", "runtests.jl")) - @test isfile(joinpath(pkg_dir, "Manifest.toml")) - runtests = read(joinpath(pkg_dir, "test", "runtests.jl"), String) - rm(joinpath(pkg_dir, "test"); recursive=true) - @test occursin("using $test_pkg", runtests) - @test occursin("using Test", runtests) - manifest = read(joinpath(pkg_dir, "Manifest.toml"), String) - @test !occursin("[[Test]]", manifest) - - rm(temp_dir; recursive=true) -end - -@testset "Package generation" begin - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - pkg_dir = joinpath(default_dir, test_pkg) - - # Check that the expected files all exist. - @test isfile(joinpath(pkg_dir, "LICENSE")) - @test isfile(joinpath(pkg_dir, "README.md")) - @test isfile(joinpath(pkg_dir, ".gitignore")) - @test isdir(joinpath(pkg_dir, "src")) - @test isfile(joinpath(pkg_dir, "src", "$test_pkg.jl")) - @test isfile(joinpath(pkg_dir, "Project.toml")) - @test isdir(joinpath(pkg_dir, "test")) - @test isfile(joinpath(pkg_dir, "test", "runtests.jl")) - @test isfile(joinpath(pkg_dir, "Manifest.toml")) - # Check the configured remote and branches. - # Note: This test will fail on your system if you've configured Git - # to replace all HTTPS URLs with SSH. - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - branches = map(b -> LibGit2.shortname(first(b)), LibGit2.GitBranchIter(repo)) - @test LibGit2.url(remote) == "https://github.com/$me/$test_pkg.jl" - @test branches == ["master"] - @test !LibGit2.isdirty(repo) - # Check for the [compat] section. - project = read(joinpath(pkg_dir, "Project.toml"), String) - @test occursin("[compat]", project) - @test occursin("julia = " * PkgTemplates.repr_version(t.julia_version), project) - rm(pkg_dir; recursive=true) - - # Check that the remote is an SSH URL when we want it to be. - t = Template(; user=me, ssh=true) - generate(t, test_pkg; gitconfig=gitconfig) # Test the reversed-arguments method here. - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - @test LibGit2.url(remote) == "git@github.com:$me/$test_pkg.jl.git" - rm(pkg_dir; recursive=true) - - # Check that the remote is set correctly for non-default hosts. - t = Template(; user=me, host="gitlab.com") - generate(test_pkg, t; gitconfig=gitconfig) - repo = LibGit2.GitRepo(pkg_dir) - remote = LibGit2.get(LibGit2.GitRemote, repo, "origin") - @test LibGit2.url(remote) == "https://gitlab.com/$me/$test_pkg.jl" - rm(pkg_dir; recursive=true) - - # Check that the package ends up in the right directory. - temp_dir = mktempdir() - t = Template(; user=me, dir=temp_dir) - generate(test_pkg, t; gitconfig=gitconfig) - @test isdir(joinpath(temp_dir, test_pkg)) - rm(temp_dir; recursive=true) - - # Check that the Manifest.toml is not commited by default. - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - @test occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String)) - # I'm not sure this is the "right" way to do this. - repo = GitRepo(pkg_dir) - idx = LibGit2.GitIndex(repo) - @test findall("Manifest.toml", idx) === nothing - rm(pkg_dir; recursive=true) - - # And that it is when you tell it to be. - t = Template(; user=me, manifest=true) - generate(test_pkg, t; gitconfig=gitconfig) - @test !occursin("Manifest.toml", read(joinpath(pkg_dir, ".gitignore"), String)) - # I'm not sure this is the "right" way to do this. - repo = GitRepo(pkg_dir) - idx = LibGit2.GitIndex(repo) - @test findall("Manifest.toml", idx) !== nothing - rm(pkg_dir; recursive=true) - - # Check that the created package ends up developed in the current environment. - temp_dir = mktempdir() - Pkg.activate(temp_dir) - t = Template(; user=me) - generate(test_pkg, t; gitconfig=gitconfig) - @test haskey(Pkg.installed(), test_pkg) - rm(pkg_dir; recursive=true) - Pkg.activate() - rm(temp_dir; recursive=true) -end - -@testset "Git-less template creation" begin - if isempty(LibGit2.getconfig("user.name", "")) - @test_logs Template(; user=me, git=false) - end -end - -@testset "Git-less package generation" begin - t = Template(; user=me) - generate(test_pkg, t; git=false) - @test !ispath(joinpath(t.dir, ".git")) - @test !isfile(joinpath(t.dir, ".gitignore")) -end - -@testset "Version floor" begin - @test version_floor(v"1.0.0") == "1.0" - @test version_floor(v"1.0.1") == "1.0" - @test version_floor(v"1.0.1-pre") == "1.0" - @test version_floor(v"1.0.0-pre") == "1.0-" -end - -@testset "Mustache substitution" begin - view = Dict{String, Any}() - text = substitute(template_text, view) - @test !occursin("PKGNAME: $test_pkg", text) - @test !occursin("Documenter", text) - @test !occursin("Codecov", text) - @test !occursin("Coveralls", text) - @test !occursin("After", text) - @test !occursin("Other", text) - view["PKGNAME"] = test_pkg - view["OTHER"] = true - text = substitute(template_text, view) - @test occursin("PKGNAME: $test_pkg", text) - @test occursin("Other", text) - - t = Template(; user=me) - view["OTHER"] = false - - text = substitute(template_text, t; view=view) - @test occursin("PKGNAME: $test_pkg", text) - @test occursin("VERSION: $(t.julia_version.major).$(t.julia_version.minor)", text) - @test !occursin("Documenter", text) - @test !occursin("After", text) - @test !occursin("Other", text) - - t.plugins[GitHubPages] = GitHubPages() - text = substitute(template_text, t; view=view) - @test occursin("Documenter", text) - @test occursin("After", text) - empty!(t.plugins) - - t.plugins[Codecov] = Codecov() - text = substitute(template_text, t; view=view) - @test occursin("Codecov", text) - @test occursin("After", text) - empty!(t.plugins) - - t.plugins[Coveralls] = Coveralls() - text = substitute(template_text, t; view=view) - @test occursin("Coveralls", text) - @test occursin("After", text) - empty!(t.plugins) - - view["OTHER"] = true - text = substitute(template_text, t; view=view) - @test occursin("Other", text) -end - -@testset "License display" begin - io = IOBuffer() - available_licenses(io) - licenses = String(take!(io)) - show_license(io, "MIT") - mit = String(take!(io)) - - # Check that all licenses are included in the display. - for (short, long) in LICENSES - @test occursin("$short: $long", licenses) - end - @test strip(mit) == strip(read_license("MIT")) - @test strip(read_license("MIT")) == strip(read(joinpath(LICENSE_DIR, "MIT"), String)) - @test_throws ArgumentError read_license(fake_path) - - # Check that all licenses included with the package are displayed. - for license in readdir(LICENSE_DIR) - @test haskey(LICENSES, license) - end - # Check that all licenses displayed are included with the package. - @test length(readdir(LICENSE_DIR)) == length(LICENSES) -end - -@testset "Plugins" begin - t = Template(; user=me) - pkg_dir = joinpath(t.dir, test_pkg) - - # Check badge constructor and formatting. - badge = Badge("A", "B", "C") - @test badge.hover == "A" - @test badge.image == "B" - @test badge.link == "C" - @test format(badge) == "[![A](B)](C)" - - p = Bar() - @test isempty(badges(p, me, test_pkg)) - @test isempty(gen_plugin(p, t, test_pkg)) - - p = Baz() - @test isempty(badges(p, me, test_pkg)) - @test isempty(gen_plugin(p, t, test_pkg)) - - include(joinpath("plugins", "travisci.jl")) - include(joinpath("plugins", "appveyor.jl")) - include(joinpath("plugins", "gitlabci.jl")) - include(joinpath("plugins", "cirrusci.jl")) - include(joinpath("plugins", "droneci.jl")) - include(joinpath("plugins", "codecov.jl")) - include(joinpath("plugins", "coveralls.jl")) - include(joinpath("plugins", "githubpages.jl")) - include(joinpath("plugins", "gitlabpages.jl")) - include(joinpath("plugins", "citation.jl")) -end - -@testset "Documenter add kwargs" begin - t = Template(; user=me) - pkg_dir = joinpath(t.dir, test_pkg) - - function check_kwargs(kwargs, warn_str) - p = Qux([], kwargs) - @test_logs (:warn, warn_str) gen_plugin(p, t, test_pkg) - - make = readchomp(joinpath(pkg_dir, "docs", "make.jl")) - @test occursin("\n stringarg=\"string\",\n", make) - @test occursin("\n strict=true,\n", make) - @test occursin("\n checkdocs=:none,\n", make) - - @test !occursin("format=:markdown", make) - @test occursin("format=Documenter.HTML()", make) - rm(pkg_dir; recursive=true) - end - # Test with string kwargs - kwargs = Dict("checkdocs" => :none, - "strict" => true, - "format" => :markdown, - "stringarg" => "string", - ) - warn_str = "Ignoring predefined Documenter kwargs \"format\" from additional kwargs" - check_kwargs(kwargs, warn_str) - - kwargs = Dict(:checkdocs => :none, - :strict => true, - :format => :markdown, - :stringarg => "string", - ) - warn_str = "Ignoring predefined Documenter kwargs :format from additional kwargs" - check_kwargs(kwargs, warn_str) - - kwargs = (checkdocs = :none, strict = true, format = :markdown, stringarg = "string") - warn_str = "Ignoring predefined Documenter kwargs :format from additional kwargs" - check_kwargs(kwargs, warn_str) -end - -include(joinpath("interactive", "interactive.jl")) - -rm(test_file)