Merge pull request #138 from invenia/cdg/tb

Various updates for GitHub Actions
This commit is contained in:
Chris de Graaf 2020-03-04 01:19:18 +07:00 committed by GitHub
commit 21617c56f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 210 additions and 41 deletions

View File

@ -76,8 +76,8 @@ To understand how they're implemented, let's look at simplified versions of two
```julia ```julia
@with_kw_noshow struct Documenter <: Plugin @with_kw_noshow struct Documenter <: Plugin
make_jl::String = default_file("docs", "make.jl") <- "Path to make.jl template" make_jl::String = default_file("docs", "make.jl")
index_md::String = default_file("docs", "src", "index.md") <- "Path to index.md template" index_md::String = default_file("docs", "src", "index.md")
end end
gitignore(::Documenter) = ["/docs/build/"] gitignore(::Documenter) = ["/docs/build/"]

View File

@ -41,6 +41,7 @@ Readme
License License
Git Git
TagBot TagBot
Secret
``` ```
### Continuous Integration (CI) ### Continuous Integration (CI)

View File

@ -27,6 +27,7 @@ export
License, License,
ProjectFile, ProjectFile,
Readme, Readme,
Secret,
SrcDir, SrcDir,
TagBot, TagBot,
Tests, Tests,

View File

@ -1,6 +1,22 @@
const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates"))
const DEFAULT_PRIORITY = 1000 const DEFAULT_PRIORITY = 1000
function Base.:(==)(a::T, b::T) where T <: Plugin
return all(n -> getfield(a, n) == getfield(b, n), fieldnames(T))
end
"""
Secret(name::AbstractString)
Represents a GitHub repository secret.
When converted to a string, yields `\${{ secrets.<name> }}`.
"""
struct Secret
name::String
end
Base.print(io::IO, s::Secret) = print(io, "\${{ secrets.$(s.name) }}")
""" """
A simple plugin that, in general, creates a single file. A simple plugin that, in general, creates a single file.
""" """

View File

@ -2,6 +2,7 @@
CompatHelper(; CompatHelper(;
file="$(contractuser(default_file("github", "workflows", "CompatHelper.yml")))", file="$(contractuser(default_file("github", "workflows", "CompatHelper.yml")))",
destination="CompatHelper.yml", destination="CompatHelper.yml",
cron="0 0 * * *",
) )
Integrates your packages with [CompatHelper](https://github.com/bcbi/CompatHelper.jl) via GitHub Actions. Integrates your packages with [CompatHelper](https://github.com/bcbi/CompatHelper.jl) via GitHub Actions.
@ -10,10 +11,12 @@ Integrates your packages with [CompatHelper](https://github.com/bcbi/CompatHelpe
- `file::AbstractString`: Template file for the workflow file. - `file::AbstractString`: Template file for the workflow file.
- `destination::AbstractString`: Destination of the workflow file, - `destination::AbstractString`: Destination of the workflow file,
relative to `.github/workflows`. relative to `.github/workflows`.
- `cron::AbstractString`: Cron expression for the schedule interval.
""" """
@with_kw_noshow struct CompatHelper <: BasicPlugin @with_kw_noshow struct CompatHelper <: BasicPlugin
file::String = default_file("github", "workflows", "CompatHelper.yml") file::String = default_file("github", "workflows", "CompatHelper.yml")
destination::String = "CompatHelper.yml" destination::String = "CompatHelper.yml"
cron::String = "0 0 * * *"
end end
source(p::CompatHelper) = p.file source(p::CompatHelper) = p.file
@ -21,5 +24,6 @@ destination(p::CompatHelper) = joinpath(".github", "workflows", p.destination)
tags(::CompatHelper) = "<<", ">>" tags(::CompatHelper) = "<<", ">>"
view(p::CompatHelper, t::Template, ::AbstractString) = Dict( view(p::CompatHelper, t::Template, ::AbstractString) = Dict(
"VERSION" => format_version(max(v"1.2", t.julia)), "CRON" => p.cron,
"VERSION" => format_version(max(v"1.3", t.julia)),
) )

View File

@ -1,25 +1,81 @@
""" """
TagBot(; destination="TagBot.yml", registry=nothing, dispatch=false) TagBot(;
file="$(contractuser(default_file("github", "workflows", "TagBot.yml")))",
destination="TagBot.yml",
cron="0 * * * *",
token=Secret("GITHUB_TOKEN"),
ssh=nothing,
ssh_password=nothing,
changelog=nothing,
changelog_ignore=nothing,
gpg=nothing,
gpg_password=nothing,
registry=nothing,
branches=nothing,
dispatch=nothing,
dispatch_delay=nothing,
)
Adds GitHub release support via [TagBot](https://github.com/JuliaRegistries/TagBot). Adds GitHub release support via [TagBot](https://github.com/JuliaRegistries/TagBot).
## Keyword Arguments ## Keyword Arguments
- `destination::AbstractString`: Destination of the workflow file, - `file::AbstractString`: Template file for the workflow file.
relative to `.github/workflows`. - `destination::AbstractString`: Destination of the workflow file, relative to `.github/workflows`.
- `registry::Union{AbstractString, Nothing}`: Custom registry, in the format `owner/repo`. - `cron::AbstractString`: Cron expression for the schedule interval.
- `token::Secret`: Name of the token secret to use.
- `ssh::Secret`: Name of the SSH private key secret to use.
- `ssh_password::Secret`: Name of the SSH key password secret to use.
- `changelog::AbstractString`: Custom changelog template.
- `changelog_ignore::Vector{<:AbstractString}`: Issue/pull request labels to ignore in the changelog.
- `gpg::Secret`: Name of the GPG private key secret to use.
- `gpg_password::Secret`: Name of the GPG private key password secret to use.
- `registry::AbstractString`: Custom registry, in the format `owner/repo`.
- `branches::Bool`: Whether not to enable the `branches` option.
- `dispatch::Bool`: Whether or not to enable the `dispatch` option. - `dispatch::Bool`: Whether or not to enable the `dispatch` option.
- `dispatch_delay::Int`: Number of minutes to delay for dispatch events.
""" """
@with_kw_noshow struct TagBot <: BasicPlugin @with_kw_noshow struct TagBot <: BasicPlugin
file::String = default_file("github", "workflows", "TagBot.yml")
destination::String = "TagBot.yml" destination::String = "TagBot.yml"
cron::String = "0 * * * *"
token::Secret = Secret("GITHUB_TOKEN")
ssh::Union{Secret, Nothing} = nothing
ssh_password::Union{Secret, Nothing} = nothing
changelog::Union{String, Nothing} = nothing
changelog_ignore::Union{Vector{String}, Nothing} = nothing
gpg::Union{Secret, Nothing} = nothing
gpg_password::Union{Secret, Nothing} = nothing
registry::Union{String, Nothing} = nothing registry::Union{String, Nothing} = nothing
dispatch::Bool = false branches::Union{Bool, Nothing} = nothing
dispatch::Union{Bool, Nothing} = nothing
dispatch_delay::Union{Int, Nothing} = nothing
end end
source(::TagBot) = default_file("github", "workflows", "TagBot.yml") source(p::TagBot) = p.file
destination(p::TagBot) = joinpath(".github", "workflows", p.destination) destination(p::TagBot) = joinpath(".github", "workflows", p.destination)
tags(::TagBot) = "<<", ">>"
view(p::TagBot, ::Template, ::AbstractString) = Dict( function view(p::TagBot, ::Template, ::AbstractString)
"HAS_DISPATCH" => p.dispatch, changelog = if p.changelog === nothing
nothing
else
# This magic number aligns the text block just right.
lines = map(line -> rstrip(repeat(' ', 12) * line), split(p.changelog, "\n"))
"|\n" * join(lines, "\n")
end
ignore = p.changelog_ignore === nothing ? nothing : join(p.changelog_ignore, ", ")
return Dict(
"BRANCHES" => p.branches === nothing ? nothing : string(p.branches),
"CHANGELOG" => changelog,
"CHANGELOG_IGNORE" => ignore,
"CRON" => p.cron,
"DISPATCH" => p.dispatch === nothing ? nothing : string(p.dispatch),
"DISPATCH_DELAY" => p.dispatch_delay,
"GPG" => p.gpg,
"GPG_PASSWORD" => p.gpg_password,
"REGISTRY" => p.registry, "REGISTRY" => p.registry,
"SSH" => p.ssh,
"SSH_PASSWORD" => p.ssh_password,
"TOKEN" => p.token,
) )
end

View File

@ -130,6 +130,15 @@ function (t::Template)(pkg::AbstractString)
@info "New package is at $pkg_dir" @info "New package is at $pkg_dir"
end end
function Base.:(==)(a::Template, b::Template)
return a.authors == b.authors &&
a.dir == b.dir &&
a.host == b.host &&
a.julia == b.julia &&
a.user == b.user &&
all(map(==, a.plugins, b.plugins))
end
# Does the template have a plugin that satisfies some predicate? # Does the template have a plugin that satisfies some predicate?
hasplugin(t::Template, f::Function) = any(f, t.plugins) hasplugin(t::Template, f::Function) = any(f, t.plugins)
hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T) hasplugin(t::Template, ::Type{T}) where T <: Plugin = hasplugin(t, p -> p isa T)

View File

@ -1,7 +1,7 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: <<&CRON>>
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -1,17 +1,41 @@
name: TagBot name: TagBot
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: {{{CRON}}}
jobs: jobs:
TagBot: TagBot:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: JuliaRegistries/TagBot@v1 - uses: JuliaRegistries/TagBot@v1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: {{{TOKEN}}}
<<#REGISTRY>> {{#SSH}}
registry: <<&REGISTRY>> ssh: {{{SSH}}}
<</REGISTRY>> {{/SSH}}
<<#HAS_DISPATCH>> {{#SSH_PASSWORD}}
dispatch: true ssh_password: {{{SSH_PASSWORD}}}
<</HAS_DISPATCH>> {{/SSH_PASSWORD}}
{{#CHANGELOG}}
changelog: {{{CHANGELOG}}}
{{/CHANGELOG}}
{{#CHANGELOG_IGNORE}}
changelog_ignore: {{{CHANGELOG_IGNORE}}}
{{/CHANGELOG_IGNORE}}
{{#GPG}}
gpg: {{{GPG}}}
{{/GPG}}
{{#GPG_PASSWORD}}
gpg_password: {{{GPG_PASSWORD}}}
{{/GPG_PASSWORD}}
{{#REGISTRY}}
registry: {{{REGISTRY}}}
{{/REGISTRY}}
{{#BRANCHES}}
branches: {{{BRANCHES}}}
{{/BRANCHES}}
{{#DISPATCH}}
dispatch: {{{DISPATCH}}}
{{/DISPATCH}}
{{#DISPATCH_DELAY}}
dispatch_delay: {{{DISPATCH_DELAY}}}
{{/DISPATCH_DELAY}}

View File

@ -65,4 +65,5 @@ jobs:
- run: julia --project=docs docs/make.jl - run: julia --project=docs docs/make.jl
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
<</HAS_DOCUMENTER>> <</HAS_DOCUMENTER>>

View File

@ -1,14 +1,14 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 * * *
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: julia-actions/setup-julia@latest - uses: julia-actions/setup-julia@latest
with: with:
version: 1.2 version: 1.3
- name: Pkg.add("CompatHelper") - name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main() - name: CompatHelper.main()

View File

@ -1,14 +1,14 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 * * *
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: julia-actions/setup-julia@latest - uses: julia-actions/setup-julia@latest
with: with:
version: 1.2 version: 1.3
- name: Pkg.add("CompatHelper") - name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main() - name: CompatHelper.main()

View File

@ -1,14 +1,14 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 * * *
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: julia-actions/setup-julia@latest - uses: julia-actions/setup-julia@latest
with: with:
version: 1.2 version: 1.3
- name: Pkg.add("CompatHelper") - name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main() - name: CompatHelper.main()

View File

@ -42,3 +42,4 @@ jobs:
- run: julia --project=docs docs/make.jl - run: julia --project=docs docs/make.jl
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

View File

@ -1,14 +1,14 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 * * *
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: julia-actions/setup-julia@latest - uses: julia-actions/setup-julia@latest
with: with:
version: 1.2 version: 1.3
- name: Pkg.add("CompatHelper") - name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main() - name: CompatHelper.main()

View File

@ -1,14 +1,14 @@
name: CompatHelper name: CompatHelper
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 */3 * *
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: julia-actions/setup-julia@latest - uses: julia-actions/setup-julia@latest
with: with:
version: 1.2 version: 1.3
- name: Pkg.add("CompatHelper") - name: Pkg.add("CompatHelper")
run: julia -e 'using Pkg; Pkg.add("CompatHelper")' run: julia -e 'using Pkg; Pkg.add("CompatHelper")'
- name: CompatHelper.main() - name: CompatHelper.main()

View File

@ -1,13 +1,25 @@
name: TagBot name: TagBot
on: on:
schedule: schedule:
- cron: 0 * * * * - cron: 0 0 */3 * *
jobs: jobs:
TagBot: TagBot:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: JuliaRegistries/TagBot@v1 - uses: JuliaRegistries/TagBot@v1
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.MYTOKEN }}
ssh: ${{ secrets.SSHKEY }}
ssh_password: ${{ secrets.SSHPASS }}
changelog: |
Line 1
Line 2
Line 4
changelog_ignore: foo, bar
gpg: ${{ secrets.GPGKEY }}
gpg_password: ${{ secrets.GPGPASS }}
registry: Foo/Bar registry: Foo/Bar
branches: false
dispatch: true dispatch: true
dispatch_delay: 20

View File

@ -1,6 +1,9 @@
# Don't move this line from the top, please. {{X}} {{Y}} {{Z}} # Don't move this line from the top, please. {{X}} {{Y}} {{Z}}
struct BasicTest <: PT.BasicPlugin end struct BasicTest <: PT.BasicPlugin
a::String
b::Bool
end
PT.gitignore(::BasicTest) = ["a", "aa", "aaa"] PT.gitignore(::BasicTest) = ["a", "aa", "aaa"]
PT.source(::BasicTest) = @__FILE__ PT.source(::BasicTest) = @__FILE__
@ -11,7 +14,7 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" =>
@testset "Plugins" begin @testset "Plugins" begin
@testset "BasicPlugin" begin @testset "BasicPlugin" begin
p = BasicTest() p = BasicTest("foo", true)
t = tpl(; plugins=[p]) t = tpl(; plugins=[p])
# The X from user_view should override the X from view. # The X from user_view should override the X from view.
@ -34,4 +37,12 @@ PT.user_view(::BasicTest, ::Template, ::AbstractString) = Dict("X" => 1, "Z" =>
@test_logs tpl(; julia=v"1.2", plugins=[p]) @test_logs tpl(; julia=v"1.2", plugins=[p])
@test_logs tpl(; julia=v"1.3", plugins=[p]) @test_logs tpl(; julia=v"1.3", plugins=[p])
end end
@testset "Equality" begin
a = BasicTest("foo", true)
b = BasicTest("foo", true)
@test a == b
c = BasicTest("foo", false)
@test a != c
end
end end

View File

@ -63,6 +63,7 @@ end
CirrusCI(; image="freebsd-123", coverage=false, extra_versions=["1.1"]), CirrusCI(; image="freebsd-123", coverage=false, extra_versions=["1.1"]),
Citation(; readme=true), Citation(; readme=true),
Codecov(; file=STATIC_FILE), Codecov(; file=STATIC_FILE),
CompatHelper(; cron="0 0 */3 * *"),
Coveralls(; file=STATIC_FILE), Coveralls(; file=STATIC_FILE),
Documenter{GitLabCI}( Documenter{GitLabCI}(
assets=[STATIC_FILE], assets=[STATIC_FILE],
@ -76,7 +77,20 @@ end
License(; name="ISC"), License(; name="ISC"),
ProjectFile(; version=v"1"), ProjectFile(; version=v"1"),
Readme(; inline_badges=true), Readme(; inline_badges=true),
TagBot(; registry="Foo/Bar", dispatch=true), TagBot(;
cron="0 0 */3 * *",
token=Secret("MYTOKEN"),
ssh=Secret("SSHKEY"),
ssh_password=Secret("SSHPASS"),
changelog="Line 1\nLine 2\n\nLine 4",
changelog_ignore=["foo", "bar"],
gpg=Secret("GPGKEY"),
gpg_password=Secret("GPGPASS"),
registry="Foo/Bar",
branches=false,
dispatch=true,
dispatch_delay=20,
),
Tests(; project=true), Tests(; project=true),
TravisCI(; TravisCI(;
coverage=false, coverage=false,

View File

@ -24,6 +24,7 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses")
CompatHelper: CompatHelper:
file: "$(joinpath(TEMPLATES_DIR, "github", "workflows", "CompatHelper.yml"))" file: "$(joinpath(TEMPLATES_DIR, "github", "workflows", "CompatHelper.yml"))"
destination: "CompatHelper.yml" destination: "CompatHelper.yml"
cron: "0 0 * * *"
Git: Git:
ignore: String[] ignore: String[]
ssh: false ssh: false
@ -41,9 +42,20 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses")
SrcDir: SrcDir:
file: "$(joinpath(TEMPLATES_DIR, "src", "module.jl"))" file: "$(joinpath(TEMPLATES_DIR, "src", "module.jl"))"
TagBot: TagBot:
file: "$(joinpath(TEMPLATES_DIR, "github", "workflows", "TagBot.yml"))"
destination: "TagBot.yml" destination: "TagBot.yml"
cron: "0 * * * *"
token: Secret("GITHUB_TOKEN")
ssh: nothing
ssh_password: nothing
changelog: nothing
changelog_ignore: nothing
gpg: nothing
gpg_password: nothing
registry: nothing registry: nothing
dispatch: false branches: nothing
dispatch: nothing
dispatch_delay: nothing
Tests: Tests:
file: "$(joinpath(TEMPLATES_DIR, "test", "runtests.jl"))" file: "$(joinpath(TEMPLATES_DIR, "test", "runtests.jl"))"
project: false project: false
@ -52,9 +64,8 @@ const LICENSES_DIR = joinpath(TEMPLATES_DIR, "licenses")
end end
@testset "show as serialization" begin @testset "show as serialization" begin
# Equality is not implemented for Template, so check the string form.
t1 = tpl() t1 = tpl()
t2 = eval(Meta.parse(sprint(show, t1))) t2 = eval(Meta.parse(sprint(show, t1)))
@test sprint(show, t1) == sprint(show, t2) @test t1 == t2
end end
end end

View File

@ -50,6 +50,14 @@
end end
end end
@testset "Equality" begin
a = tpl()
b = tpl()
@test a == b
c = tpl(julia=v"0.3")
@test a != c
end
@testset "hasplugin" begin @testset "hasplugin" begin
t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()]) t = tpl(; plugins=[TravisCI(), Documenter{TravisCI}()])
@test PT.hasplugin(t, typeof(first(PT.default_plugins()))) @test PT.hasplugin(t, typeof(first(PT.default_plugins())))