-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(release): Add new tasks for release and tests (#33)
* Add new tasks for release and tests
- Loading branch information
1 parent
76b77f6
commit ab8f41b
Showing
23 changed files
with
321 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
elixir 1.15.7-otp-24 | ||
erlang 24.3.4.14 | ||
erlang 26.1.1 | ||
elixir 1.15.6-otp-26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Mix.Tasks.Ca.Release do | ||
@moduledoc """ | ||
Mix release wrapper that moves compressed artifact to _build/release/artifact folder | ||
Examples: | ||
$ mix ca.release | ||
It generates the following files: | ||
* _build/release/artifact/<app-name>.tar.gz | ||
""" | ||
|
||
alias ElixirStructureManager.Utils.{FileGenerator, TokenHelper} | ||
alias Mix.Tasks.Ca.BaseTask | ||
|
||
use BaseTask, | ||
name: "ca.release", | ||
description: | ||
"Mix release wrapper that moves compressed artifact to _build/release/artifact folder", | ||
switches: [], | ||
aliases: [] | ||
|
||
def execute(_any) do | ||
Mix.shell().info([:green, "* Generating release artifact"]) | ||
|
||
args = %{ | ||
folders: [ | ||
"_build/prod/rel/{app_snake}/releases/RELEASES", | ||
"_build/release/artifact" | ||
], | ||
transformations: [ | ||
{:cmd, "mix release --overwrite"}, | ||
{:cmd, | ||
"mv _build/prod/{app_snake}-{version}.tar.gz _build/release/artifact/{app_snake}.tar.gz"}, | ||
{:cmd, "ls -lR _build/release"} | ||
] | ||
} | ||
|
||
FileGenerator.execute_actions(args, TokenHelper.default_tokens()) | ||
|
||
Mix.shell().info([:green, "* Artifact generated"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule Mix.Tasks.Ca.Sobelow.Sonar do | ||
@moduledoc """ | ||
Translates the sobelow json report to sonar issues | ||
Examples: | ||
$ mix ca.sobelow.sonar -i sobelow.json -o sobelow_sonarqube.json | ||
""" | ||
|
||
alias ElixirStructureManager.Reports.Sobelow | ||
alias Mix.Tasks.Ca.BaseTask | ||
|
||
use BaseTask, | ||
name: "ca.sobelow.sonar", | ||
description: "Translates the sobelow json report to sonar issues", | ||
switches: [input: :string, output: :string], | ||
aliases: [i: :input, o: :output] | ||
|
||
def execute({opts, []}) do | ||
Mix.shell().info([:green, "* Translating sobelow report"]) | ||
|
||
input = Keyword.get(opts, :input, "sobelow.json") | ||
output = Keyword.get(opts, :output, "sobelow_sonarqube.json") | ||
|
||
sonar_base_folder = Application.get_env(:elixir_structure_manager, :sonar_base_folder, "") | ||
|
||
File.exists?(input) || Mix.shell().error([:red, "* Input file not found"]) | ||
|
||
report = | ||
File.read!(input) | ||
|> Poison.decode!() | ||
|
||
sonar_report = Sobelow.translate(report, sonar_base_folder) | ||
json = Poison.encode!(sonar_report, %{pretty: true}) | ||
File.write!(output, json) | ||
|
||
Mix.shell().info([:green, "* Sonarqube report generated"]) | ||
end | ||
|
||
def execute(_any), do: run(["-h"]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
defmodule Mix.Tasks.Ca.Test do | ||
@moduledoc """ | ||
Run common static code analysis tools and tests for the project | ||
Examples: | ||
$ mix ca.test | ||
It generates the following files: | ||
* _build/release/credo_sonarqube.json | ||
* _build/release/excoveralls.xml | ||
* _build/release/generic_test_execution_sonarqube.xml | ||
* _build/release/sobelow.json | ||
* _build/release/sobelow_sonarqube.json | ||
* _build/release/test-junit-report.xml | ||
""" | ||
|
||
alias ElixirStructureManager.Utils.{FileGenerator, TokenHelper} | ||
alias Mix.Tasks.Ca.BaseTask | ||
|
||
use BaseTask, | ||
name: "ca.test", | ||
description: "Run common static code analysis tools and tests for the project", | ||
switches: [], | ||
aliases: [] | ||
|
||
def execute(_any) do | ||
Mix.shell().info([:green, "* Executing analysis and tests"]) | ||
|
||
sonar_base_folder = Application.get_env(:elixir_structure_manager, :sonar_base_folder, "") | ||
|
||
args = %{ | ||
folders: [ | ||
"_build/release" | ||
], | ||
transformations: [ | ||
{:cmd, | ||
"mix credo --sonarqube-base-folder {sonar_base_folder} --sonarqube-file _build/release/credo_sonarqube.json --mute-exit-status"}, | ||
{:cmd, "mix sobelow -f json --out _build/release/sobelow.json"}, | ||
{:cmd, | ||
"mix ca.sobelow.sonar -i _build/release/sobelow.json -o _build/release/sobelow_sonarqube.json"}, | ||
{:cmd, "mix coveralls.xml"}, | ||
{:cmd, | ||
"mv generic_test_execution_sonarqube.xml _build/release/generic_test_execution_sonarqube.xml"} | ||
] | ||
} | ||
|
||
FileGenerator.execute_actions(args, TokenHelper.add("sonar_base_folder", sonar_base_folder)) | ||
|
||
Mix.shell().info([:green, "* Analysis executed"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
defmodule ElixirStructureManager.Reports.Sobelow do | ||
@moduledoc """ | ||
Sobelow report generator | ||
""" | ||
|
||
def translate( | ||
%{ | ||
"findings" => %{ | ||
"high_confidence" => highs, | ||
"medium_confidence" => meds, | ||
"low_confidence" => lows | ||
}, | ||
"sobelow_version" => vsn | ||
}, | ||
sonar_base_folder | ||
) do | ||
issues = | ||
Enum.map(highs, &format(&1, :high, vsn, sonar_base_folder)) | ||
|> Enum.concat(Enum.map(meds, &format(&1, :medium, vsn, sonar_base_folder))) | ||
|> Enum.concat(Enum.map(lows, &format(&1, :low, vsn, sonar_base_folder))) | ||
|
||
%{issues: issues} | ||
end | ||
|
||
defp format( | ||
%{"type" => type, "file" => file, "line" => line} = finding, | ||
confidence, | ||
vsn, | ||
prefix | ||
) do | ||
variable = Map.get(finding, "variable", "") | ||
[mod_id, _] = String.split(type, ":", parts: 2) | ||
# Code.ensure_loaded(Sobelow) | ||
rule = Sobelow.get_mod(mod_id) | ||
|
||
location = %{ | ||
filePath: "#{prefix}#{file}", | ||
message: "#{type} #{variable} \n Help: #{rule.details()}" | ||
} | ||
|
||
location = with_text_range(location, line) | ||
|
||
%{ | ||
ruleId: rule.id(), | ||
severity: confidence_to_severity(confidence), | ||
type: "VULNERABILITY", | ||
engineId: "sobelow-#{vsn}", | ||
primaryLocation: location | ||
} | ||
end | ||
|
||
defp with_text_range(%{} = location, line) when line > 0 do | ||
Map.put(location, :textRange, %{startLine: line}) | ||
end | ||
|
||
defp with_text_range(%{} = location, _line), do: location | ||
|
||
defp confidence_to_severity(:high), do: "CRITICAL" | ||
defp confidence_to_severity(:medium), do: "MAJOR" | ||
defp confidence_to_severity(:low), do: "MINOR" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.