Skip to content

Commit

Permalink
Logger: Use a relative path to the workspace instead of an absolute p…
Browse files Browse the repository at this point in the history
…ath for `file` (#15)

* set IOContext, replace newlines

* oops, we were already escaping

* tweak path

* color breaks things

* Allow logging without the `GITHUB_WORKSPACE` env var

* fix tests

* fix other test
  • Loading branch information
ericphanson authored Sep 27, 2021
1 parent b27403f commit 6a67147
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/GitHubActions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ function Logging.handle_message(
location=nothing, kwargs...,
)
file, line = something(location, (file, line))

workspace = get(ENV, "GITHUB_WORKSPACE", nothing)
if workspace !== nothing
# In order for inline annotations to work correctly:
file = relpath(file, workspace)
end
message = string(msg)
for (k, v) in kwargs
result = sprint(Logging.showvalue, v)
Expand Down
12 changes: 10 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ const GHA = GitHubActions
end
end

rx(level) = Regex("^::$level file=$(@__FILE__),line=\\d+::a")
function rx(level)
workspace = get(ENV, "GITHUB_WORKSPACE", nothing)
file = @__FILE__
if workspace !== nothing
file = relpath(file, workspace)
end
return Regex("^::$level file=$(file),line=\\d+::a")
end

with_logger(GitHubActionsLogger()) do
@test match(rx("debug"), (@capture_out @debug "a")) !== nothing
@test match(rx("warning"), (@capture_out @warn "a")) !== nothing
Expand All @@ -94,7 +102,7 @@ const GHA = GitHubActions
@test (@capture_out @info "a" b=1 c=2 d=Text("e\nf")) == "a\n b = 1\n c = 2\n d = \n e\n f\n"
@test endswith((@capture_out @warn "a" b=1 c=2), "::a%0A b = 1%0A c = 2\n")

expected = "::warning file=bar,line=1::foo\n"
expected = "::warning file=test/bar,line=1::foo\n"
@test (@capture_out @warn "foo" location=("bar", 1)) == expected
end
end

0 comments on commit 6a67147

Please sign in to comment.