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

updates for v1.5, etc. #289

Merged
merged 8 commits into from
Nov 17, 2020
Merged
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
25 changes: 16 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ os:
- windows

arch:
- x64
- x86
- amd64
- i386

julia:
- "1.0"
- "1.4"
- "1" # Latest stable release (currently "1.5")
- nightly

Expand All @@ -26,11 +25,18 @@ jobs:
allow_failures:
- julia: nightly

# Test 32-bit only on Linux
exclude:
- arch: x86
# Test 32-bit only on Linux
- arch: i386
os: osx
- arch: x86
- arch: i386
os: windows
# Test fewer versions too
- julia: "1.0"
os: osx
- julia: nightly
os: osx
- julia: "1.0"
os: windows

notifications:
Expand All @@ -39,8 +45,9 @@ notifications:

script:
- julia --color=yes --check-bounds=yes etc/travis-test.jl
- export COVERALLS_PARALLEL=true
# submit coverage data, and collect new coverage data on that
- julia --color=yes --code-coverage=user etc/travis-coverage.jl
# submit coverage data to a black hole server with a fake job-id,
# and collect new coverage data on that
- COVERALLS_URL=https://httpbingo.julialang.org/post
julia --color=yes --code-coverage=user etc/travis-coverage.jl
# submit coverage data *again*, this time without code coverage
- julia --color=yes etc/travis-coverage.jl
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,6 @@ When using Coverage.jl locally, over time a lot of `.cov` files can accumulate.
- C:\projects\julia\bin\julia -e "using Pkg; Pkg.add(\"Coverage\"); using Coverage; Coveralls.submit(process_folder())"
```

4. If you are uploading from multiple jobs, you'll need to tell Coveralls to merge the results after all CI jobs have completed. See https://docs.coveralls.io/parallel-build-webhook for general instructions.

For Travis, this can be achieved by adding the following to `.travis.yml`:

env:
global:
- COVERALLS_PARALLEL=true
notifications:
webhooks: https://coveralls.io/webhook
Copy link
Member

Choose a reason for hiding this comment

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

I am surprised this is not necessary anymore. They still mention it on https://github.com/marketplace/actions/coveralls-github-action and https://docs.coveralls.io/parallel-build-webhook, and it was absolutely vital when I last played with it -- but that was some time ago; so if that's what you found empirically, let's do it... Coveralls documentation sucks in general, so I am not completely surprised it might not reflect reality anymore :-).

I'll soon need to dig into this again for another project (where Travis cut our legs, so we moved to GitHub Actions, and that broke Coveralls integration), I'll keep this in mind, might simplify things there!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I noticed that even old builds now are showing up correctly without this flag. But the only effect it was now having here was to prevent any builds from showing up (it was unable to process the webhook now, I'm guessing perhaps due to the deprecation of travis-ci.org)

lemurheavy/coveralls-public#1461 (comment)

Copy link
Member

Choose a reason for hiding this comment

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

@vtjnash looking at e.g. #288 there are now four coveralls comments there. I vaguely recall from way back that this was caused by the "parallel" support not being activated -- but it's been some time, so I might totally misremember!

Copy link
Member Author

Choose a reason for hiding this comment

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

It used to be disabled entirely, but I'm not sure why it'd be 4 and not 8 (the number of builds) or 1 (the top comment has 5 rolling edits as the parallel builds finished)

Copy link
Member

Choose a reason for hiding this comment

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

Top comment was created, then edited 5 times; plus 3 more comments; means a total of 1+5+3=9 results reported. The Travis build has 9 jobs. So what I think happens is that whenever one of the jobs ends, Coveralls adds or updates an issue comment. Why it didn't just put all updates in one comment, I can only guess at; most likely a race condition, but w/o being able to see the precise timestamps when each comment was made/updated, it's hard to say...



## A note for advanced users

Coverage tracking in Julia is not yet quite perfect. One problem is that (at
Expand Down
58 changes: 30 additions & 28 deletions src/codecovio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,14 @@ module Codecov
kwargs provides default values to insert into args_array, only if they are
not already specified in args_array.
"""
function set_defaults(args_array; kwargs...)
defined_names = keys(args_array)
is_args_array = Pair{Symbol, Any}[]
is_args_array = append!(is_args_array, args_array)
function set_defaults(args_array::Dict; kwargs...)
args_array = copy(args_array)
for kwarg in kwargs
if !(kwarg[1] in defined_names)
push!(is_args_array, kwarg)
if !haskey(args_array, kwarg[1])
push!(args_array, kwarg)
end
end
return is_args_array
return args_array
end

"""
Expand All @@ -66,11 +64,12 @@ module Codecov
on TravisCI or AppVeyor. If running locally, use `submit_local`.
"""
function submit(fcs::Vector{FileCoverage}; kwargs...)
submit_generic(fcs; add_ci_to_kwargs(;kwargs...)...)
submit_generic(fcs, add_ci_to_kwargs(; kwargs...))
end


function add_ci_to_kwargs(;kwargs...)
add_ci_to_kwargs(; kwargs...) = add_ci_to_kwargs(Dict{Symbol,Any}(kwargs))
function add_ci_to_kwargs(kwargs::Dict)
if lowercase(get(ENV, "APPVEYOR", "false")) == "true"
appveyor_pr = get(ENV, "APPVEYOR_PULL_REQUEST_NUMBER", "")
appveyor_job = join(
Expand Down Expand Up @@ -161,10 +160,11 @@ module Codecov
`token` keyword argument or the `CODECOV_TOKEN` environment variable.
"""
function submit_local(fcs::Vector{FileCoverage}, dir::AbstractString=pwd(); kwargs...)
submit_generic(fcs; add_local_to_kwargs(dir; kwargs...)...)
submit_generic(fcs, add_local_to_kwargs(dir; kwargs...))
end

function add_local_to_kwargs(dir; kwargs...)
add_local_to_kwargs(dir; kwargs...) = add_local_to_kwargs(dir, Dict{Symbol,Any}(kwargs))
function add_local_to_kwargs(dir, kwargs::Dict)
LibGit2.with(LibGit2.GitRepoExt(dir)) do repo
LibGit2.with(LibGit2.head(repo)) do headref
branch_name = LibGit2.shortname(headref) # this function returns a String
Expand Down Expand Up @@ -199,7 +199,9 @@ module Codecov
The `dry_run` keyword can be used to prevent the http request from
being generated.
"""
function submit_generic(fcs::Vector{FileCoverage}; kwargs...)
submit_generic(fcs::Vector{FileCoverage}; kwargs...) =
submit_generic(fcs, Dict{Symbol,Any}(kwargs))
function submit_generic(fcs::Vector{FileCoverage}, kwargs::Dict)
@assert length(kwargs) > 0
dry_run = get(kwargs, :dry_run, false)
if haskey(kwargs, :verbose)
Expand All @@ -209,7 +211,8 @@ module Codecov
else
verbose = false
end
uri_str = construct_uri_string(;kwargs...)

uri_str = construct_uri_string(kwargs)

verbose && @info "Submitting data to Codecov..."
verbose && @debug "Codecov.io API URL:\n" * mask_token(uri_str)
Expand All @@ -222,25 +225,24 @@ module Codecov
end
end

function construct_uri_string(;kwargs...)
if haskey(ENV, "CODECOV_URL")
kwargs = set_defaults(kwargs, codecov_url = ENV["CODECOV_URL"])
end
function construct_uri_string(kwargs::Dict)
url = get(ENV, "CODECOV_URL", "")
isempty(url) || (kwargs = set_defaults(kwargs, codecov_url = url))

if haskey(ENV, "CODECOV_TOKEN")
kwargs = set_defaults(kwargs, token = ENV["CODECOV_TOKEN"])
end
token = get(ENV, "CODECOV_TOKEN", "")
isempty(token) || (kwargs = set_defaults(kwargs, token = token))

codecov_url = "https://codecov.io"
for (k,v) in kwargs
if k == :codecov_url
codecov_url = v
end
end
@assert codecov_url[end] != "/" "the codecov_url should not end with a /, given url $(codecov_url)"
flags = get(ENV, "CODECOV_FLAGS", "")
isempty(flags) || (kwargs = set_defaults(kwargs; flags = flags))

name = get(ENV, "CODECOV_NAME", "")
isempty(name) || (kwargs = set_defaults(kwargs; name = name))

codecov_url = get(kwargs, :codecov_url, "https://codecov.io")
codecov_url[end] == "/" && error("the codecov_url should not end with a /, given url $(repr(codecov_url))")

uri_str = "$(codecov_url)/upload/v2?"
for (k,v) in kwargs
for (k, v) in kwargs
# add all except a few special key/value pairs to the URL
# (:verbose is there for backwards compatibility with versions
# of this code that treated it in a special way)
Expand Down
50 changes: 41 additions & 9 deletions src/coveralls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,19 @@ module Coveralls

# to_json
# Convert a FileCoverage instance to its Coveralls JSON representation
to_json(fc::FileCoverage) = Dict("name" => fc.filename,
"source_digest" => digest(MD_MD5, fc.source, "secret"),
"coverage" => fc.coverage)
function to_json(fc::FileCoverage)
name = Sys.iswindows() ? replace(fc.filename, '\\' => '/') : fc.filename
return Dict("name" => name,
"source_digest" => digest(MD_MD5, fc.source, "secret"),
"coverage" => fc.coverage)
end

# Format the body argument to HTTP.post
makebody(data::Dict) =
Dict("json_file" => HTTP.Multipart("json_file", IOBuffer(JSON.json(data)),
"application/json"))
function makebody(data::Dict)
iodata = IOBuffer(JSON.json(data))
json_file = HTTP.Multipart("json_file", iodata, "application/json")
return Dict("json_file" => json_file)
end

"""
submit(fcs::Vector{FileCoverage}; kwargs...)
Expand All @@ -68,18 +73,21 @@ module Coveralls
post_request(data, verbose)
end

function prepare_request(fcs::Vector{FileCoverage}, local_env, git_info=query_git_info)
function prepare_request(fcs::Vector{FileCoverage}, local_env::Bool, git_info=query_git_info)
data = Dict{String,Any}("source_files" => map(to_json, fcs))

if local_env
# Attempt to parse git info via git_info, unless the user explicitly disables it by setting git_info to nothing
data["service_name"] = "local"
data["git"] = parse_git_info(git_info)
elseif lowercase(get(ENV, "APPVEYOR", "false")) == "true"
data["service_job_id"] = ENV["APPVEYOR_JOB_ID"]
data["service_job_number"] = ENV["APPVEYOR_BUILD_NUMBER"]
data["service_job_id"] = ENV["APPVEYOR_BUILD_ID"]
data["service_name"] = "appveyor"
appveyor_pr = get(ENV, "APPVEYOR_PULL_REQUEST_NUMBER", "")
isempty(appveyor_pr) || (data["service_pull_request"] = appveyor_pr)
elseif lowercase(get(ENV, "TRAVIS", "false")) == "true"
data["service_number"] = ENV["TRAVIS_BUILD_NUMBER"]
data["service_job_id"] = ENV["TRAVIS_JOB_ID"]
data["service_name"] = "travis-ci"
travis_pr = get(ENV, "TRAVIS_PULL_REQUEST", "")
Expand All @@ -94,8 +102,31 @@ module Coveralls
data["git"]["branch"] = split(ENV["GIT_BRANCH"], "/")[2]
end
elseif haskey(ENV, "GITHUB_ACTION")
data["service_name"] = "github"
data["git"] = parse_git_info(git_info)
else
data["git"] = parse_git_info(git_info)
end

service_name = get(ENV, "COVERALLS_SERVICE_NAME", "")
isempty(service_name) || (data["service_name"] = service_name)

service_number = get(ENV, "COVERALLS_SERVICE_NUMBER", "")
isempty(service_number) || (data["service_number"] = service_number)

service_job_number = get(ENV, "COVERALLS_SERVICE_JOB_NUMBER", "")
isempty(service_job_number) || (data["service_job_number"] = service_job_number)

jobid = get(ENV, "COVERALLS_SERVICE_JOB_ID", "")
isempty(jobid) || (data["service_job_id"] = jobid)

flag_name = get(ENV, "COVERALLS_FLAG_NAME", "")
isempty(flag_name) || (data["flag_name"] = flag_name)

ci_pr = get(ENV, "COVERALLS_PULL_REQUEST", "")
isempty(ci_pr) || (data["service_pull_request"] = ci_pr)

if !haskey(data, "service_name")
error("No compatible CI platform detected")
end

Expand Down Expand Up @@ -187,7 +218,8 @@ module Coveralls
# posts the actual request given the data
function post_request(data, verbose)
verbose && @info "Submitting data to Coveralls..."
req = HTTP.post("https://coveralls.io/api/v1/jobs", HTTP.Form(makebody(data)))
coveralls_url = get(ENV, "COVERALLS_URL", "https://coveralls.io/api/v1/jobs")
req = HTTP.post(coveralls_url, HTTP.Form(makebody(data)))
verbose && @debug "Result of submission:\n" * String(req.body)
nothing
end
Expand Down
Loading