From 5baa28324d0e97682f6db9ab49b4f83f3221ad32 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Sat, 13 Feb 2021 13:21:13 -0800 Subject: [PATCH 1/4] Update Codecov upload API to v4 --- src/codecovio.jl | 15 ++++++++++----- test/runtests.jl | 4 ++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/codecovio.jl b/src/codecovio.jl index a28496d..aedabd9 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -224,10 +224,15 @@ module Codecov @debug "Codecov.io API URL:\n" * mask_token(uri_str) if !dry_run - heads = Dict("Content-Type" => "application/json") - data = to_json(fcs) - req = HTTP.post(uri_str; body = JSON.json(data), headers = heads) - @debug "Result of submission:" * mask_token(String(req)) + # Tell Codecov we have an upload for them + response = HTTP.post(uri_str; headers=Dict("Accept" => "text/plain")) + # Get the temporary URL to use for uploading to S3 + s3url = split(String(response.body), '\n')[2] + # Upload to S3 + request = HTTP.put(s3url; body=json(to_json(fcs)), + header=Dict("Content-Type" => "application/json", + "x-amz-storage-class" => "REDUCED_REDUNDANCY")) + @debug "Result of submission:" * mask_token(String(request)) end end @@ -252,7 +257,7 @@ module Codecov error("the codecov_url should not end with a /, given url $(repr(codecov_url))") end - codecov_url_path = get(kwargs, :codecov_url_path, "/upload/v2") + codecov_url_path = get(kwargs, :codecov_url_path, "/upload/v4") if isempty(codecov_url_path) || codecov_url_path[1] != '/' || codecov_url_path[end] == '/' error("the codecov_url_path should begin with, but not end with, a /, given url $(repr(codecov_url_path))") end diff --git a/test/runtests.jl b/test/runtests.jl index 1b4ede7..7a8cd17 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -430,9 +430,9 @@ withenv( # in the case above, the token is at the end. Let's test explicitly, # that this also works if the token occurs earlier in the url - url = "https://enterprise-codecov-1.com/upload/v2?token=token_name_1&build=t_job_num" + url = "https://enterprise-codecov-1.com/upload/v4?token=token_name_1&build=t_job_num" masked = Coverage.Codecov.mask_token(url) - @test masked == "https://enterprise-codecov-1.com/upload/v2?token=&build=t_job_num" + @test masked == "https://enterprise-codecov-1.com/upload/v4?token=&build=t_job_num" end From 9c2e0921853d015eca3e8ad69942dea0de868d5b Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Fri, 26 Feb 2021 14:00:50 -0800 Subject: [PATCH 2/4] Make Jamesonier thanks bud Co-authored-by: Jameson Nash --- src/codecovio.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/codecovio.jl b/src/codecovio.jl index aedabd9..2c170d8 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -227,7 +227,11 @@ module Codecov # Tell Codecov we have an upload for them response = HTTP.post(uri_str; headers=Dict("Accept" => "text/plain")) # Get the temporary URL to use for uploading to S3 - s3url = split(String(response.body), '\n')[2] + repr = String(response) + s3url = get(split(String(response.body), '\n'), 2, "") + repr = chomp(replace(repr, s3url => "")) + @debug "Result of submission:" * repr + startswith(s3url, "https://") || error("Invalid codecov response: $s3url") # Upload to S3 request = HTTP.put(s3url; body=json(to_json(fcs)), header=Dict("Content-Type" => "application/json", From d3c682a7f22809df549453790ceeb099496dd731 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sun, 13 Jun 2021 16:43:31 -0400 Subject: [PATCH 3/4] Don't try submit to S3 if we are using the "black hole" server --- .github/workflows/CI.yml | 3 +++ Project.toml | 3 ++- src/codecovio.jl | 17 +++++++++++------ test/runtests.jl | 15 ++++++++++++++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0ade010..5587324 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -40,10 +40,13 @@ jobs: arch: ${{ matrix.arch }} - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 + env: + JULIA_COVERAGE_BLACK_HOLE_SERVER_URL_PUT: https://httpbingo.julialang.org/put # submit coverage data to a black hole server, and collect new coverage data on that - run: julia --color=yes --project=. --code-coverage=user etc/travis-coverage.jl working-directory: ${{ github.workspace }} env: + JULIA_COVERAGE_IS_BLACK_HOLE_SERVER: true COVERALLS_TOKEN: token COVERALLS_URL: https://httpbingo.julialang.org/post CODECOV_URL: https://httpbingo.julialang.org diff --git a/Project.toml b/Project.toml index a655fb5..9bae0a9 100644 --- a/Project.toml +++ b/Project.toml @@ -18,7 +18,8 @@ MbedTLS = "0.6, 0.7, 1" julia = "1" [extras] +CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Test"] +test = ["CoverageTools", "Test"] diff --git a/src/codecovio.jl b/src/codecovio.jl index 2c170d8..a8a8d50 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -223,6 +223,7 @@ module Codecov @info "Submitting data to Codecov..." @debug "Codecov.io API URL:\n" * mask_token(uri_str) + is_black_hole_server = parse(Bool, strip(get(ENV, "JULIA_COVERAGE_IS_BLACK_HOLE_SERVER", "false")))::Bool if !dry_run # Tell Codecov we have an upload for them response = HTTP.post(uri_str; headers=Dict("Accept" => "text/plain")) @@ -231,15 +232,19 @@ module Codecov s3url = get(split(String(response.body), '\n'), 2, "") repr = chomp(replace(repr, s3url => "")) @debug "Result of submission:" * repr - startswith(s3url, "https://") || error("Invalid codecov response: $s3url") - # Upload to S3 - request = HTTP.put(s3url; body=json(to_json(fcs)), - header=Dict("Content-Type" => "application/json", - "x-amz-storage-class" => "REDUCED_REDUNDANCY")) - @debug "Result of submission:" * mask_token(String(request)) + !is_black_hole_server && upload_to_s3(; s3url=s3url, fcs=fcs) end end + function upload_to_s3(; s3url, fcs) + startswith(s3url, "https://") || error("Invalid codecov response: $s3url") + # Upload to S3 + request = HTTP.put(s3url; body=json(to_json(fcs)), + header=Dict("Content-Type" => "application/json", + "x-amz-storage-class" => "REDUCED_REDUNDANCY")) + @debug "Result of submission:" * mask_token(String(request)) + end + function construct_uri_string(kwargs::Dict) url = get(ENV, "CODECOV_URL", "") isempty(url) || (kwargs = set_defaults(kwargs, codecov_url = url)) diff --git a/test/runtests.jl b/test/runtests.jl index 7a8cd17..86129c4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -6,6 +6,8 @@ using Coverage, Test, LibGit2 +import CoverageTools + @testset "Coverage" begin # set up base system ENV vars for testing withenv( @@ -433,8 +435,19 @@ withenv( url = "https://enterprise-codecov-1.com/upload/v4?token=token_name_1&build=t_job_num" masked = Coverage.Codecov.mask_token(url) @test masked == "https://enterprise-codecov-1.com/upload/v4?token=&build=t_job_num" + + @testset "Run the `Coverage.Codecov.upload_to_s3` function against the \"black hole\" server" begin + black_hole_server = get( + ENV, + "JULIA_COVERAGE_BLACK_HOLE_SERVER_URL_PUT", + "https://httpbingo.julialang.org/put", + ) + s3url = black_hole_server + fcs = Vector{CoverageTools.FileCoverage}(undef, 0) + Coverage.Codecov.upload_to_s3(; s3url=s3url, fcs=fcs) + end end - + @testset "coveralls" begin # NOTE: this only returns actual content if this package is devved. From 0b0e47e40d7dd3006a445490bf3e4fcb6bcd5030 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Sun, 13 Jun 2021 17:53:50 -0400 Subject: [PATCH 4/4] Bump the minor version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 9bae0a9..9b00fbe 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Coverage" uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037" authors = ["Iain Dunning ", "contributors"] -version = "1.2.2" +version = "1.3.0" [deps] CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997"