Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buildkite logger #1255

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AutoBuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,8 @@ function _package_is_registered(registry_url::AbstractString,
end

is_yggdrasil() = get(ENV, "YGGDRASIL", "false") == "true"
# Use an Azure Pipelines environment variable to get the current commit hash
yggdrasil_head() = get(ENV, "BUILD_SOURCEVERSION", "")
# Use a Buildkite environment variable to get the current commit hash
yggdrasil_head() = get(ENV, "BUILDKITE_COMMIT", "")

function register_jll(name, build_version, dependencies, julia_compat;
deploy_repo="JuliaBinaryWrappers/$(name)_jll.jl",
Expand Down
2 changes: 2 additions & 0 deletions src/BinaryBuilder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ function __init__()
# If we're running on Azure, enable azure logging:
if !isempty(get(ENV, "AZP_TOKEN", ""))
enable_azure_logging()
elseif parse(Bool, get(ENV, "BUILDKITE", "false"))
enable_buildkite_logging()
end
end

Expand Down
37 changes: 37 additions & 0 deletions src/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,40 @@ function enable_azure_logging()
AzureSinkLogger(),
))
end

struct BuildkiteLogger <: Logging.AbstractLogger
end

function annotate(annotation; context="default", style="info", append=true)
@assert style in ("success", "info", "warning", "error")
append = append ? `--append` : ``
cmd = `buildkite-agent annotate --style $(style) --context $(context) $(append)`
open(cmd, stdout, write=true) do io
write(io, annotation)
end
end

function Logging.handle_message(logger::BuildkiteLogger, args...; kwargs...)
#Make it a named tuple for easier working
log = LoggingExtras.handle_message_args(args...)

# Buildkite calls it `style` not level`, and `warning` not `warn`:
log[:level]
stylemap = Dict(Logging.Error => "error", Logging.Warn => "warning")
style = stylemap[log[:level]]

# TODO pretty rendering of properties
annotate(log.message; context="BinaryBuilder", style)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should markdown format the message. At least add a \n

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the context should be.

return nothing
end
Logging.shouldlog(::BuildkiteLogger, arg...) = true
Logging.min_enabled_level(::BuildkiteLogger) = Logging.Warn
Logging.catch_exceptions(::BuildkiteLogger) = true

function enable_buildkite_logging()
# Tee-in BuildkiteLogger so that `@warn` and `@error` are printed out nicely
global_logger(TeeLogger(
global_logger(),
BuildkiteLogger(),
))
end