Skip to content

Commit

Permalink
Fix umbrella test race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
karolsluszniak committed Dec 5, 2022
1 parent 56631a0 commit 5fa8db9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/ex_check/config/default.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ defmodule ExCheck.Config.Default do
# streaming to display as many outputs as possible as soon as possible.
@curated_tools [
{:compiler, "mix compile --warnings-as-errors --force"},
{:mix_audit, "mix deps.audit", detect: [{:package, :mix_audit}]},
{:unused_deps, "mix deps.unlock --check-unused",
detect: [{:elixir, ">= 1.10.0"}], fix: "mix deps.unlock --unused"},
{:formatter, "mix format --check-formatted",
detect: [{:file, ".formatter.exs"}], fix: "mix format"},
{:mix_audit, "mix deps.audit", detect: [{:package, :mix_audit}]},
{:credo, "mix credo", detect: [{:package, :credo}]},
{:doctor, "mix doctor", detect: [{:package, :doctor}, {:elixir, ">= 1.8.0"}]},
{:sobelow, "mix sobelow --exit", umbrella: [recursive: true], detect: [{:package, :sobelow}]},
Expand Down
5 changes: 3 additions & 2 deletions lib/mix/tasks/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ defmodule Mix.Tasks.Check do
- [`:ex_doc`] - compiles the project documentation in order to ensure that there are no issues
that would make it impossible for docs to get collected and assembled
- [`:mix_audit`] - scans the project's Mix dependencies for known Elixir security vulnerabilities
based on a GitHub-sourced list of security advisories
- [`:npm_test`] - runs JavaScript tests in projects with front-end assets embedded in `assets`
directory and `package.json` in it (default for Phoenix apps)
- [`:sobelow`] - performs security-focused static analysis mainly focused on the Phoenix
framework, but also detecting vulnerable dependencies in arbitrary Mix projects
- [`:mix_audit`] - scans a project Mix dependencies for known Elixir security vulnerabilities
You can disable or adjust curated tools as well as add custom ones via the configuration file.
## Workflow
Expand Down
34 changes: 25 additions & 9 deletions test/support/ex_check/umbrella_project_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ defmodule ExCheck.UmbrellaProjectCase do

setup do
tmp_dir = create_tmp_directory()
project_dir = create_mix_project(tmp_dir, umbrella: true)
apps_dir = Path.join(project_dir, "apps")
root_project_dir = create_mix_project(tmp_dir, umbrella: true)
apps_dir = Path.join(root_project_dir, "apps")
child_a_dir = create_mix_project(apps_dir, name: "child_a")
child_b_dir = create_mix_project(apps_dir, name: "child_b")
project_dirs = [project_dir, child_a_dir, child_b_dir]
project_dirs = [root_project_dir, child_a_dir, child_b_dir]

set_mix_deps(project_dirs, [:ex_check])
write_default_config(project_dir)
copy_ex_check_dep(root_project_dir)
set_mix_deps(root_project_dir, project_dirs, [:ex_check])
write_default_config(root_project_dir)
on_exit(fn -> remove_tmp_directory(tmp_dir) end)

{:ok, project_dirs: project_dirs}
Expand Down Expand Up @@ -60,18 +61,29 @@ defmodule ExCheck.UmbrellaProjectCase do
Path.join(root_dir, name)
end

def set_mix_deps(project_dirs, deps) when is_list(project_dirs) do
Enum.map(project_dirs, &set_mix_deps(&1, deps))
def copy_ex_check_dep(root_project_dir) do
ex_check_dir = get_ex_check_dep_dir(root_project_dir)

if not File.exists?(ex_check_dir) do
File.mkdir_p!(ex_check_dir)
end

File.cp_r!(File.cwd!(), ex_check_dir)
end

def set_mix_deps(project_dir, deps) do
def set_mix_deps(root_project_dir, project_dirs, deps) when is_list(project_dirs) do
Enum.map(project_dirs, &set_mix_deps(root_project_dir, &1, deps))
end

def set_mix_deps(root_project_dir, project_dir, deps) do
ex_check_dir = get_ex_check_dep_dir(root_project_dir)
config_path = "#{project_dir}/mix.exs"
deps_from = ~r/ *defp deps.*end\n/Us

deps_list =
Enum.map(deps, fn
:ex_check ->
"{:ex_check, path: \"#{File.cwd!()}\", only: [:dev, :test], runtime: false}"
"{:ex_check, path: \"#{ex_check_dir}\", only: [:dev, :test], runtime: false}"

dep ->
"{:#{dep}, \">= 0.0.0\", only: :dev, runtime: false}"
Expand Down Expand Up @@ -124,4 +136,8 @@ defmodule ExCheck.UmbrellaProjectCase do
config_path = Path.join(project_dir, ".check.exs")
File.write!(config_path, @default_config)
end

defp get_ex_check_dep_dir(root_project_dir) do
Path.join([root_project_dir, "priv", "ex_check"])
end
end

0 comments on commit 5fa8db9

Please sign in to comment.