Skip to content

Commit

Permalink
verify in the last CI stage, that unit tests does not rely on feature…
Browse files Browse the repository at this point in the history
… branches
  • Loading branch information
SimeonEhrig committed Jul 6, 2023
1 parent ec24176 commit f406741
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
stages:
- unit-test
- verify-unit-test-deps

unit_tests_julia1.9:
image: julia:1.9
stage: unit-test
script:
- julia --project=. -e 'import Pkg; Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/QEDjl-project/registry.git"));'
- julia --project=. -e 'import Pkg; Pkg.Registry.add(Pkg.RegistrySpec(url="https://github.com/JuliaRegistries/General"));'
- julia --project=. ${CI_PROJECT_DIR}/SetupDevEnv/src/SetupDevEnv.jl ${CI_PROJECT_DIR}/Project.toml
- julia --project=. ${CI_PROJECT_DIR}/ci/SetupDevEnv/src/SetupDevEnv.jl ${CI_PROJECT_DIR}/Project.toml
- julia --project=. -e 'import Pkg; Pkg.instantiate()'
- julia --project=. -e 'import Pkg; Pkg.test(; coverage = true)'
tags:
- cpuonly

verify-unit-test-deps_julia1.9:
image: julia:1.9
stage: verify-unit-test-deps
script:
- julia ${CI_PROJECT_DIR}/ci/verify_env.jl
tags:
- cpuonly
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions ci/verify_env.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
The script checks, if custom dependency for unit tests via `CI_UNIT_PKG_URL_<package_name>` are set.
If yes, the script fails, which means in practice, that the PR rely on non merged code.
"""

"""
extract_env_vars_from_git_message!()
Parse the commit message, if set via variable `CI_COMMIT_MESSAGE` and set custom urls.
"""
function extract_env_vars_from_git_message!()
if haskey(ENV, "CI_COMMIT_MESSAGE")
println("Found env variable CI_COMMIT_MESSAGE")
for line in split(ENV["CI_COMMIT_MESSAGE"], "\n")
line = strip(line)
if startswith(line, "CI_UNIT_PKG_URL_")
(var_name, url) = split(line, ":"; limit=2)
println("add " * var_name * "=" * strip(url))
ENV[var_name] = strip(url)
end
end
end
end

if abspath(PROGRAM_FILE) == @__FILE__
extract_env_vars_from_git_message!()
filtered_env = filter((env_name)-> startswith(env_name, "CI_UNIT_PKG_URL_"), keys(ENV))

if isempty(filtered_env)
printstyled("No custom dependencies for unit tests detected.\n"; color = :green)
exit(0)
else
printstyled("Found custom dependencies for unit tests detected.\n"; color = :red)
for env in filtered_env
printstyled(" $env\n"; color = :red)
end
printstyled("\nPlease merge the custom dependency before and run the CI with custom dependency again.\n"; color = :red)
exit(1)
end
end

0 comments on commit f406741

Please sign in to comment.