diff --git a/src/AutoBuild.jl b/src/AutoBuild.jl index 3f7dafc78..004bbfe10 100644 --- a/src/AutoBuild.jl +++ b/src/AutoBuild.jl @@ -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", diff --git a/src/BinaryBuilder.jl b/src/BinaryBuilder.jl index a9ba95662..6a880def1 100644 --- a/src/BinaryBuilder.jl +++ b/src/BinaryBuilder.jl @@ -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 diff --git a/src/Logging.jl b/src/Logging.jl index 5d19a9372..8713610ff 100644 --- a/src/Logging.jl +++ b/src/Logging.jl @@ -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) + 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