Support the full range of TagBot options

TODO: Fix the `show` tests.
This commit is contained in:
Chris de Graaf 2020-02-15 00:22:28 +07:00
parent ba14f890e2
commit 5e4b91ce97
No known key found for this signature in database
GPG Key ID: 150FFDD9B0073C7B
8 changed files with 151 additions and 23 deletions

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,18 @@
const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates")) const TEMPLATES_DIR = normpath(joinpath(@__DIR__, "..", "templates"))
const DEFAULT_PRIORITY = 1000 const DEFAULT_PRIORITY = 1000
"""
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

@ -1,25 +1,79 @@
""" """
TagBot(; destination="TagBot.yml", registry=nothing, dispatch=false) TagBot(;
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, - `destination::AbstractString`: Destination of the workflow file, relative to `.github/workflows`.
relative to `.github/workflows`. - `cron::AbstractString`: Cron expression for the schedule interval.
- `registry::Union{AbstractString, Nothing}`: Custom registry, in the format `owner/repo`. - `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

@ -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

@ -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

@ -76,7 +76,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

@ -41,9 +41,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: \${{ secrets.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