From 804eec9bc6dde6387f5e0c1e1fab547201f6360d Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 21 Nov 2019 10:10:51 -0500 Subject: [PATCH 1/2] Update runtests.jl --- test/runtests.jl | 137 ++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6e30bf9..0bfc876 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -154,44 +154,48 @@ end end end -@testset "codecovio.jl" begin - # these methods are only used for testing the token generation for local repos - # and CI whilst not breaking the current API - construct_uri_string_local(dir=pwd(); kwargs...) = Coverage.Codecov.construct_uri_string( - ;Coverage.Codecov.add_local_to_kwargs(dir; kwargs...)...) - - construct_uri_string_ci(;kwargs...) = Coverage.Codecov.construct_uri_string( - ;Coverage.Codecov.add_ci_to_kwargs(;kwargs...)...) - - # empty file coverage for testing - fcs = FileCoverage[] - - # set up base system ENV vars for testing - withenv( - "CODECOV_URL" => nothing, - "CODECOV_TOKEN" => nothing, - "TRAVIS" => nothing, - "TRAVIS_BRANCH" => nothing, - "TRAVIS_COMMIT" => nothing, - "TRAVIS_PULL_REQUEST" => nothing, - "TRAVIS_JOB_ID" => nothing, - "TRAVIS_REPO_SLUG" => nothing, - "TRAVIS_JOB_NUMBER" => nothing, - "APPVEYOR" => nothing, - "APPVEYOR_PULL_REQUEST_NUMBER" => nothing, - "APPVEYOR_ACCOUNT_NAME" => nothing, - "APPVEYOR_PROJECT_SLUG" => nothing, - "APPVEYOR_BUILD_VERSION" => nothing, - "APPVEYOR_REPO_BRANCH" => nothing, - "APPVEYOR_REPO_COMMIT" => nothing, - "APPVEYOR_REPO_NAME" => nothing, - "APPVEYOR_JOB_ID" => nothing, - ) do - # test local submission process (but only if we are in a git repo) +# set up base system ENV vars for testing +withenv( + "COVERALLS_TOKEN" => "token_name_1", + "CODECOV_URL" => nothing, + "CODECOV_TOKEN" => nothing, + "TRAVIS" => nothing, + "TRAVIS_BRANCH" => nothing, + "TRAVIS_COMMIT" => nothing, + "TRAVIS_PULL_REQUEST" => nothing, + "TRAVIS_JOB_ID" => nothing, + "TRAVIS_REPO_SLUG" => nothing, + "TRAVIS_JOB_NUMBER" => nothing, + "APPVEYOR" => nothing, + "APPVEYOR_PULL_REQUEST_NUMBER" => nothing, + "APPVEYOR_ACCOUNT_NAME" => nothing, + "APPVEYOR_PROJECT_SLUG" => nothing, + "APPVEYOR_BUILD_VERSION" => nothing, + "APPVEYOR_REPO_BRANCH" => nothing, + "APPVEYOR_REPO_COMMIT" => nothing, + "APPVEYOR_REPO_NAME" => nothing, + "APPVEYOR_JOB_ID" => nothing, + "JENKINS" => nothing, + "BUILD_ID" => nothing, + "CI_PULL_REQUEST" => nothing, + "GIT_BRANCH" => nothing + ) do + + @testset "codecovio.jl" begin + # these methods are only used for testing the token generation for local repos + # and CI whilst not breaking the current API + construct_uri_string_local(dir=pwd(); kwargs...) = Coverage.Codecov.construct_uri_string( + ;Coverage.Codecov.add_local_to_kwargs(dir; kwargs...)...) + + construct_uri_string_ci(;kwargs...) = Coverage.Codecov.construct_uri_string( + ;Coverage.Codecov.add_ci_to_kwargs(;kwargs...)...) + + # empty file coverage for testing + fcs = FileCoverage[] + # test local submission process (but only if we are in a git repo) _dotgit = joinpath(dirname(@__DIR__), ".git") - if isdir(_dotgit) || isfile(_dotgit) LibGit2.with(LibGit2.GitRepoExt(pwd())) do repo # default values @@ -550,37 +554,26 @@ end masked = Coverage.Codecov.mask_token(url) @test masked == "https://enterprise-codecov-1.com/upload/v2?token=&build=t_job_num" end -end - - -@testset "coveralls" begin - # NOTE: this only returns actual content if this package is devved. - # Hence the test is basically on this function returning something - # (rather than erroring) - git = Coverage.Coveralls.query_git_info() - @test git["remotes"][1]["name"] == "origin" - @test haskey(git["remotes"][1], "url") - - # for testing submit_***() - fcs = FileCoverage[] - - # an error should be raised if there is no coveralls token set - withenv("COVERALLS_TOKEN" => nothing, - "REPO_TOKEN" => nothing, # this is deprecrated, use COVERALLS_TOKEN - "APPVEYOR" => "true", # use APPVEYOR as an example to make the test reach the repo token check - "APPVEYOR_JOB_ID" => "my_job_id") do - @test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false) - end - - withenv("COVERALLS_TOKEN" => "token_name_1", - "APPVEYOR" => nothing, - "APPVEYOR_JOB_ID" => nothing, - "TRAVIS" => nothing, - "TRAVIS_JOB_ID" => nothing, - "JENKINS" => nothing, - "BUILD_ID" => nothing, - "CI_PULL_REQUEST" => nothing, - "GIT_BRANCH" => nothing) do + + + @testset "coveralls" begin + # NOTE: this only returns actual content if this package is devved. + # Hence the test is basically on this function returning something + # (rather than erroring) + git = Coverage.Coveralls.query_git_info() + @test git["remotes"][1]["name"] == "origin" + @test haskey(git["remotes"][1], "url") + + # for testing submit_***() + fcs = FileCoverage[] + + # an error should be raised if there is no coveralls token set + withenv("COVERALLS_TOKEN" => nothing, + "REPO_TOKEN" => nothing, # this is deprecrated, use COVERALLS_TOKEN + "APPVEYOR" => "true", # use APPVEYOR as an example to make the test reach the repo token check + "APPVEYOR_JOB_ID" => "my_job_id") do + @test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false) + end # test error if not local and no CI platform can be detected from ENV @test_throws ErrorException Coverage.Coveralls.prepare_request(fcs, false) @@ -593,24 +586,31 @@ end @test isempty(request["source_files"]) @test haskey(request, "git") @test request["git"]["remotes"][1]["name"] == "origin" + @test !haskey(request, "service_job_id") + @test !haskey(request, "service_name") + @test !haskey(request, "service_pull_request") end # test APPVEYOR withenv("APPVEYOR" => "true", + "APPVEYOR_PULL_REQUEST_NUMBER" => "t_pr", "APPVEYOR_JOB_ID" => "my_job_id") do request = Coverage.Coveralls.prepare_request(fcs, false) @test request["repo_token"] == "token_name_1" @test request["service_job_id"] == "my_job_id" @test request["service_name"] == "appveyor" + @test request["service_pull_request"] == "t_pr" end # test Travis withenv("TRAVIS" => "true", - "TRAVIS_JOB_ID" => "my_job_id") do + "TRAVIS_JOB_ID" => "my_job_id", + "TRAVIS_PULL_REQUEST" => "t_pr") do request = Coverage.Coveralls.prepare_request(fcs, false) @test request["repo_token"] == "token_name_1" @test request["service_job_id"] == "my_job_id" @test request["service_name"] == "travis-ci" + @test request["service_pull_request"] == "t_pr" end # test Jenkins @@ -622,6 +622,7 @@ end @test request["repo_token"] == "token_name_1" @test request["service_job_id"] == "my_job_id" @test request["service_name"] == "jenkins-ci" + @test !haskey(request, "service_pull_request") withenv("CI_PULL_REQUEST" => "false", "GIT_BRANCH" => "my_remote/my_branch") do @@ -643,7 +644,7 @@ end # or directly a dict request = Coverage.Coveralls.prepare_request(fcs, false, Dict("test" => "test")) @test haskey(request, "git") - end + end end end From cd552553f15faa4c28cc14d0bd9a61143464295e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 21 Nov 2019 10:14:48 -0500 Subject: [PATCH 2/2] Update coveralls.jl --- src/coveralls.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/coveralls.jl b/src/coveralls.jl index 177898e..2083402 100644 --- a/src/coveralls.jl +++ b/src/coveralls.jl @@ -76,9 +76,13 @@ module Coveralls elseif lowercase(get(ENV, "APPVEYOR", "false")) == "true" data["service_job_id"] = ENV["APPVEYOR_JOB_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_job_id"] = ENV["TRAVIS_JOB_ID"] data["service_name"] = "travis-ci" + travis_pr = get(ENV, "TRAVIS_PULL_REQUEST", "") + isempty(travis_pr) || (data["service_pull_request"] = travis_pr) elseif lowercase(get(ENV, "JENKINS", "false")) == "true" data["service_job_id"] = ENV["BUILD_ID"] data["service_name"] = "jenkins-ci"