Skip to content

Commit

Permalink
Don't try submit to S3 if we are using the "black hole" server
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge committed Jun 13, 2021
1 parent d973431 commit bc27ab7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
17 changes: 11 additions & 6 deletions src/codecovio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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))
Expand Down
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

using Coverage, Test, LibGit2

import CoverageTools

@testset "Coverage" begin
# set up base system ENV vars for testing
withenv(
Expand Down Expand Up @@ -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=<HIDDEN>&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.
Expand Down

0 comments on commit bc27ab7

Please sign in to comment.