Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored May 17, 2024
2 parents 4bb021f + 4d7e89b commit 3d9ed4b
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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"
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Coverage"
uuid = "a2441757-f6aa-5fb2-8edb-039e3f45d037"
authors = ["Iain Dunning <[email protected]>", "contributors"]
version = "1.4.0"
version = "1.6.0"

[deps]
CoverageTools = "c36e975a-824b-4404-a568-ef97ca766997"
Expand All @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/codecovio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/coveralls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
88 changes: 88 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3d9ed4b

Please sign in to comment.