From 5872cf79280f2791c0fc0bf9d598147f44b63234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Galy-Fajou?= Date: Tue, 24 May 2022 23:22:13 +0200 Subject: [PATCH 1/5] Add Gitlab CI to Coverage (#331) --- Project.toml | 2 +- src/codecovio.jl | 14 ++++++++ src/coveralls.jl | 12 ++++++- test/runtests.jl | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 8223321..a11430c 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.4.0" +version = "1.5.0" [deps] CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997" diff --git a/src/codecovio.jl b/src/codecovio.jl index c6f93cb..0cf2129 100644 --- a/src/codecovio.jl +++ b/src/codecovio.jl @@ -71,6 +71,7 @@ end add_ci_to_kwargs(; kwargs...) = add_ci_to_kwargs(Dict{Symbol,Any}(kwargs)) function add_ci_to_kwargs(kwargs::Dict) + # https://docs.codecov.com/reference/upload if lowercase(get(ENV, "APPVEYOR", "false")) == "true" appveyor_pr = get(ENV, "APPVEYOR_PULL_REQUEST_NUMBER", "") appveyor_job = join( @@ -175,6 +176,19 @@ function add_ci_to_kwargs(kwargs::Dict) if ENV["BUILDKITE_PULL_REQUEST"] != "false" kwargs = set_defaults(kwargs, pr = ENV["BUILDKITE_PULL_REQUEST"]) end + elseif lowercase(get(ENV, "GITLAB_CI", "false")) == "true" + # Gitlab API: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html + branch = ENV["CI_COMMIT_REF_NAME"] + num_mr = branch == ENV["CI_DEFAULT_BRANCH"] ? "false" : ENV["CI_MERGE_REQUEST_IID"] + kwargs = set_defaults(kwargs, + service = "gitlab", + branch = branch, + commit = ENV["CI_COMMIT_SHA"], + job = ENV["CI_JOB_ID"], + build_url = ENV["CI_PIPELINE_URL"], + build = ENV["CI_PIPELINE_IID"], + pr = num_mr, + ) else error("No compatible CI platform detected") end diff --git a/src/coveralls.jl b/src/coveralls.jl index 77eb00b..19cd14f 100644 --- a/src/coveralls.jl +++ b/src/coveralls.jl @@ -69,7 +69,7 @@ end function prepare_request(fcs::Vector{FileCoverage}, local_env::Bool, git_info=query_git_info) data = Dict{String,Any}("source_files" => map(to_json, fcs)) - + # Coveralls API : https://docs.coveralls.io/api-reference 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" @@ -105,6 +105,16 @@ function prepare_request(fcs::Vector{FileCoverage}, local_env::Bool, git_info=qu github_pr = get(github_pr_info, "number", "") github_pr::Union{AbstractString, Integer} ((github_pr isa Integer) || (!isempty(github_pr))) && (data["service_pull_request"] = strip(string(github_pr))) + elseif lowercase(get(ENV, "GITLAB_CI", "false")) == "true" + # Gitlab API: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html + branch = ENV["CI_COMMIT_REF_NAME"] + num_mr = branch == ENV["CI_DEFAULT_BRANCH"] ? "false" : ENV["CI_MERGE_REQUEST_IID"] + data["service_pull_request"] = num_mr + data["service_number"] = ENV["CI_PIPELINE_IID"] + data["service_job_id"] = ENV["CI_JOB_ID"] + data["service_name"] = "gitlab" + data["git"] = parse_git_info(git_info) + data["git"]["branch"] = branch else data["git"] = parse_git_info(git_info) end diff --git a/test/runtests.jl b/test/runtests.jl index b81a76f..530f1bf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -482,6 +482,79 @@ withenv( end end + # test Gitlab ci submission process + + # set up Gitlab ci env + withenv( + "GITLAB_CI" => "true", + "CI_MERGE_REQUEST_IID" => "t_pr", + "CI_JOB_ID" => "t_proj", + "CI_COMMIT_REF_NAME" => "t_branch", + "CI_COMMIT_SHA" => "t_commit", + "CI_PROJECT_NAME" => "t_repo", + "CI_PIPELINE_URL" => "t_url", + "CI_PIPELINE_IID" => "t_num", + "CI_DEFAULT_BRANCH" => "master", + ) do + + # default values + codecov_url = construct_uri_string_ci() + @test occursin("codecov.io", codecov_url) + @test occursin("service=gitlab", codecov_url) + @test occursin("branch=t_branch", codecov_url) + @test occursin("commit=t_commit", codecov_url) + @test occursin("pr=t_pr", codecov_url) + @test occursin("build_url=t_url", codecov_url) + @test occursin("build=t_num", codecov_url) + + # env var url override + withenv( "CODECOV_URL" => "https://enterprise-codecov-1.com" ) do + + codecov_url = construct_uri_string_ci() + @test occursin("enterprise-codecov-1.com", codecov_url) + @test occursin("service=gitlab", codecov_url) + @test occursin("branch=t_branch", codecov_url) + @test occursin("commit=t_commit", codecov_url) + @test occursin("pr=t_pr", codecov_url) + @test occursin("build_url=t_url", codecov_url) + @test occursin("build=t_num", codecov_url) + + # function argument url override + codecov_url = construct_uri_string_ci(codecov_url="https://enterprise-codecov-2.com") + @test occursin("enterprise-codecov-2.com", codecov_url) + @test occursin("service=gitlab", codecov_url) + @test occursin("branch=t_branch", codecov_url) + @test occursin("commit=t_commit", codecov_url) + @test occursin("pr=t_pr", codecov_url) + @test occursin("build_url=t_url", codecov_url) + @test occursin("build=t_num", codecov_url) + + # env var token + withenv( "CODECOV_TOKEN" => "token_name_1" ) do + + codecov_url = construct_uri_string_ci() + @test occursin("enterprise-codecov-1.com", codecov_url) + @test occursin("token=token_name_1", codecov_url) + @test occursin("service=gitlab", codecov_url) + @test occursin("branch=t_branch", codecov_url) + @test occursin("commit=t_commit", codecov_url) + @test occursin("pr=t_pr", codecov_url) + @test occursin("build_url=t_url", codecov_url) + @test occursin("build=t_num", codecov_url) + + # function argument token url override + codecov_url = construct_uri_string_ci(token="token_name_2") + @test occursin("enterprise-codecov-1.com", codecov_url) + @test occursin("service=gitlab", codecov_url) + @test occursin("branch=t_branch", codecov_url) + @test occursin("commit=t_commit", codecov_url) + @test occursin("pr=t_pr", codecov_url) + @test occursin("build_url=t_url", codecov_url) + @test occursin("build=t_num", codecov_url) + end + end + end + # test codecov token masking withenv( "APPVEYOR" => "true", @@ -637,6 +710,21 @@ withenv( end end + # test Gitlab see https://docs.coveralls.io/api-reference + withenv("GITLAB_CI" => "true", + "CI_PIPELINE_IID" => "my_job_num", + "CI_JOB_ID" => "my_job_id", + "CI_COMMIT_REF_NAME" => "test", + "CI_DEFAULT_BRANCH" => "master", + "CI_MERGE_REQUEST_IID" => "t_pr") do + request = Coverage.Coveralls.prepare_request(fcs, false) + @test request["repo_token"] == "token_name_1" + @test request["service_number"] == "my_job_num" + @test request["service_job_id"] == "my_job_id" + @test request["service_name"] == "gitlab" + @test request["service_pull_request"] == "t_pr" + end + # test git_info (only works with Jenkins & local at the moment) withenv("JENKINS" => "true", "BUILD_ID" => "my_job_id", From 26bc18274e570dc92dcfce548d9aa68bf4017945 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 29 Jun 2022 15:41:39 -0400 Subject: [PATCH 2/5] CompatHelper: bump compat for HTTP to 1, (keep existing compat) (#332) Co-authored-by: CompatHelper Julia --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index a11430c..ea6136d 100644 --- a/Project.toml +++ b/Project.toml @@ -12,7 +12,7 @@ MbedTLS = "739be429-bea8-5141-9913-cc70e7f3736d" [compat] CoverageTools = "1" -HTTP = "0.8, 0.9" +HTTP = "0.8, 0.9, 1" JSON = "0.21" MbedTLS = "0.6, 0.7, 1" julia = "1" From 1bc2ab48278e3d65d57cd70e8f9c60b3042fd9a3 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Wed, 29 Jun 2022 15:59:23 -0400 Subject: [PATCH 3/5] Bump version (#333) --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index ea6136d..d1e2a99 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.5.0" +version = "1.6.0" [deps] CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997" From 453ba9f0ad6ac959c0d8d167bff30aca7f818882 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 12 Dec 2022 20:59:59 +0100 Subject: [PATCH 4/5] document `COV_EXCL_START`, `COV_EXCL_STOP` and `COV_EXCL_LINE` (#335) --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index b532d8f..1495974 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,20 @@ Be aware of a few limitations: - a line that can take one of two branches gets marked as covered even if only one branch is tested - currently, code run by Julia's internal interpreter [is not marked as covered](https://github.com/JuliaLang/julia/issues/37059). +### Exclude specific lines or sections from coverage + +To exclude specific code blocks, surround the section with `COV_EXCL_START` and `COV_EXCL_STOP` comments: +```julia +# COV_EXCL_START +foo() = nothing +# COV_EXCL_STOP +``` + +To exclude a single line, add a comment with `COV_EXCL_LINE`: +```julia +const a = 1 # COV_EXCL_LINE +``` + ### Memory allocation Start julia with From 4d7e89b14ca13874e17032d20370728b0fb4b359 Mon Sep 17 00:00:00 2001 From: Hendrik Ranocha Date: Fri, 17 May 2024 12:05:43 +0200 Subject: [PATCH 5/5] Create dependabot.yml (#338) --- .github/dependabot.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..700707c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" # Location of package manifests + schedule: + interval: "weekly"