Skip to content

Commit

Permalink
Add ex_check and its curated tools (#80)
Browse files Browse the repository at this point in the history
- Rework way to cache
- Set `npm_cache`
- Bump `npm` from 7.20.1 to 7.20.5
  • Loading branch information
aifrak authored Aug 7, 2021
1 parent 1c1c60b commit 636e05f
Show file tree
Hide file tree
Showing 19 changed files with 181 additions and 79 deletions.
21 changes: 21 additions & 0 deletions .check.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
tools: [
# Curated tools from ex_check
{:compiler, env: %{"MIX_ENV" => "test"}},
{:ex_doc, env: %{"MIX_ENV" => "test"}},
{:formatter, env: %{"MIX_ENV" => "test"}},
{:npm_test, false},
{
:sobelow,
"mix sobelow --config",
env: %{"MIX_ENV" => "test"}, detect: [{:package, :phoenix, else: :disable}]
},

# Custom lints
{:dockerfile_lint, "./run dockerfile:lint"},
{:elixir_eex_lint, "./run elixir:eex:lint"},
{:markdown_lint, "./run markdown:lint"},
{:prettier_lint, "./run prettier:lint"},
{:shell_lint, "./run shell:lint"}
]
]
1 change: 1 addition & 0 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# NodeJS
node_modules/
npm_cache/

# Elixir
_build/
Expand Down
15 changes: 15 additions & 0 deletions .doctor.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%Doctor.Config{
exception_moduledoc_required: true,
failed: false,
ignore_modules: [],
ignore_paths: [],
min_module_doc_coverage: 100,
min_module_spec_coverage: 100,
min_overall_doc_coverage: 100,
min_overall_spec_coverage: 100,
moduledoc_required: true,
raise: true,
reporter: Doctor.Reporters.Full,
struct_type_spec_required: true,
umbrella: false
}
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter,.credo}.exs", "{config,lib,test}/**/*.{ex,exs}"],
inputs: ["*.exs", "{config,lib,test}/**/*.{ex,exs}", ".sobelow-conf"],
line_length: 98
]
84 changes: 41 additions & 43 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,65 +62,62 @@ jobs:
./run dc:up
# ---------------------------------------------- #
# Elixir #
# Cache #
# ---------------------------------------------- #

- name: Add Elixir and Erlang versions as environment variables
- name: Get versions
run: |
echo "NODE_VERSION=$(./run dc:exec npm -v)" >> $GITHUB_ENV
echo "ELIXIR_VERSION=$(./run dc:exec ./run elixir:version)" >> $GITHUB_ENV
echo "ERLANG_VERSION=$(./run dc:exec ./run erlang:version)" >> $GITHUB_ENV
- name: Build Elixir cache
id: elixir-cache
- name: Cache Elixir deps
id: elixir-deps-cache
uses: actions/[email protected]
with:
path: |
**/deps
**/_build
key: "\
${{ runner.os }}-mix-\
${{ env.ELIXIR_VERSION }}-\
${{ env.ERLANG_VERSION }}-\
${{ hashFiles('**/mix.lock') }}\
"
restore-keys: "\
${{ runner.os }}-mix-\
${{ env.ELIXIR_VERSION }}-\
${{ env.ERLANG_VERSION }}-\
"

- name: Install Elixir dependencies
if: steps.elixir-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec mix deps.get
- name: Compile Elixir application (test)
if: steps.elixir-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec bash -c "MIX_ENV=test mix compile"
# ---------------------------------------------- #
# NodeJS #
# ---------------------------------------------- #
key: |
${{ runner.os }}-elixir-deps-${{ env.ELIXIR_VERSION }}-${{ env.ERLANG_VERSION }}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-elixir-deps-${{ env.ELIXIR_VERSION }}-${{ env.ERLANG_VERSION }}-
- name: Add NodeJS version as environment variable
run: |
echo "NODE_VERSION=$(./run dc:exec npm -v)" >> $GITHUB_ENV
- name: Cache Elixir build
id: elixir-build-cache
uses: actions/[email protected]
with:
path: |
**/_build
**/priv/plts/*.plt
**/priv/plts/*.plt.hash
**/.sobelow
key: |
${{ runner.os }}-elixir-build-${{ env.ELIXIR_VERSION }}-${{ env.ERLANG_VERSION }}-${{ hashFiles('**/mix.lock') }}-${{ hashFiles( '**/lib/**/*.{ex,eex}', '**/config/*.exs', '**/mix.exs' ) }}
restore-keys: |
${{ runner.os }}-elixir-build-${{ env.ELIXIR_VERSION }}-${{ env.ERLANG_VERSION }}-${{ hashFiles('**/mix.lock') }}-
${{ runner.os }}-elixir-build-${{ env.ELIXIR_VERSION }}-${{ env.ERLANG_VERSION }}-
- name: Build node modules cache
- name: Cache node modules
uses: actions/[email protected]
id: node-modules-cache
with:
path: |
**/node_modules
key: "\
${{ runner.os }}-node-\
${{ env.NODE_VERSION }}-\
${{ hashFiles('**/package-lock.json') }}\
"
**/npm_cache
key: |
${{ runner.os }}-node-${{ env.NODE_VERSION }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-${{ env.NODE_VERSION }}-
# ---------------------------------------------- #
# Dependencies #
# ---------------------------------------------- #

- name: Fetch and compile Elixir dependencies
if: steps.elixir-deps-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec bash -c "mix deps.get && mix deps.compile"
- name: Install node modules
if: steps.node-modules-cache.outputs.cache-hit != 'true'
run: |
Expand All @@ -130,10 +127,11 @@ jobs:
# Application #
# ---------------------------------------------- #

- name: Test
- name: Compile Elixir application
if: steps.elixir-build-cache.outputs.cache-hit != 'true'
run: |
./run dc:exec ./run test
./run dc:exec bash -c "MIX_ENV=test mix compile"
- name: Lint
- name: Run all checks
run: |
./run dc:exec ./run lint
./run dc:exec mix check
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# NodeJS
node_modules/
npm_cache/

# Docker compose
docker-compose.override.yml
Expand All @@ -18,6 +19,9 @@ erl_crash.dump
*.beam
config/*.secret.exs
.elixir_ls/
**/priv/plts/*.plt
**/priv/plts/*.plt.hash
.sobelow

# Keep .gitkeep files
!/**/.gitkeep
4 changes: 2 additions & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

if [ -n "$INSIDE_DOCKER" ]; then
npx lint-staged
./run test
mix check --only ex_unit
else
./run --dev dc:build
./run --dev dc:up
./run --dev dc:exec ./run install-deps
./run --dev dc:exec npx lint-staged
./run --dev dc:exec ./run test
./run --dev dc:exec mix check --only ex_unit
fi
1 change: 1 addition & 0 deletions .markdownlintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# NodeJS
node_modules/
npm_cache/

# Elixir
_build/
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cache=npm_cache
engine-strict=true
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ vendor/

# NodeJS
node_modules/
npm_cache/

# Elixir
_build/
Expand Down
1 change: 1 addition & 0 deletions .prettierignore-eex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ vendor/

# Node
node_modules/
npm_cache/

# Elixir
_build/
Expand Down
12 changes: 12 additions & 0 deletions .sobelow-conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
verbose: false,
private: false,
skip: true,
router: "",
exit: "low",
format: "txt",
out: "",
threshold: "low",
ignore: [""],
ignore_files: [""]
]
30 changes: 23 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
// Files:
"files.associations": {
".prettierignore-eex": "ignore",
".sobelow-conf": "elixir",
"run": "shellscript",
"pre-commit": "shellscript"
},
Expand All @@ -18,11 +19,16 @@
"**/.history/**": true,
// NodeJS
"**/node_modules/**": true,
"**/npm_cache/**": true,
// Elixir
"**/deps/**": true,
"**/doc/**": true,
"**/_build/**": true,
"**/.elixir_ls/**": true,
"**/erl_crash.dump": true
"**/erl_crash.dump": true,
"**/dialyzer.plt": true,
"**/dialyzer.plt.hash": true,
"**/.sobelow": true
},
"files.exclude": {
"**/.git": true,
Expand All @@ -32,16 +38,21 @@
// Search:
"search.exclude": {
"**/.git": true,
"**/.husky/_/**": true,
"**/.husky/_": true,
// VSCode
"**/.history/**": true,
"**/.history": true,
// NodeJS
"**/node_modules": true,
"**/npm_cache": true,
// Elixir
"**/deps/**": true,
"**/_build/**": true,
"**/.elixir_ls/**": true,
"**/erl_crash.dump": true
"**/deps": true,
"**/doc": true,
"**/_build": true,
"**/.elixir_ls": true,
"**/erl_crash.dump": true,
"**/dialyzer.plt": true,
"**/dialyzer.plt.hash": true,
"**/.sobelow": true
},

// Prettier:
Expand All @@ -60,6 +71,7 @@
"**/.history/**",
// NodeJS
"**/node_modules/**",
"**/npm_cache/**",
// Elixir
"**/deps/**",
"**/_build/**",
Expand Down Expand Up @@ -147,6 +159,7 @@
"chmod",
"deps",
"devcontainer",
"dialyxir",
"dockerfiles",
"dockerignore",
"doctest",
Expand All @@ -166,6 +179,7 @@
"noninteractive",
"nopasswd",
"npmrc",
"plts",
"preminor",
"prepatch",
"prettierignore",
Expand All @@ -176,7 +190,9 @@
"shellcheck",
"shfmt",
"shortdoc",
"sobelow",
"typep",
"underspecs",
"xargs",
"xtype"
],
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUN set -e \
&& mix local.rebar --force

FROM node:16.6.1-buster as node
RUN npm install -g [email protected].1 --quiet
RUN npm install -g [email protected].5 --quiet

FROM koalaman/shellcheck:v0.7.2 as shellcheck
FROM mvdan/shfmt:v3.3.1 as shfmt
Expand Down
44 changes: 38 additions & 6 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ defmodule App.MixProject do
elixir: "~> 1.12",
start_permanent: Mix.env() == :prod,
deps: deps(),
preferred_cli_env: [
credo: :test
]
preferred_cli_env: preferred_cli_env(),
dialyzer: dialyzer()
]
end

Expand All @@ -22,9 +21,42 @@ defmodule App.MixProject do

defp deps do
[
{:credo, "~> 1.5", only: [:test], runtime: false},
{:credo_contrib, "~> 0.2.0", only: [:test], runtime: false},
{:credo_naming, "~> 1.0", only: [:test], runtime: false}
{:credo, ">= 1.5.6", only: [:test], runtime: false},
{:credo_contrib, ">= 0.2.0", only: [:test], runtime: false},
{:credo_naming, ">= 1.0.0", only: [:test], runtime: false},
{:dialyxir, ">= 1.1.0", only: [:test], runtime: false},
{:doctor, ">= 0.18.0", only: [:test], runtime: false},
{:ex_check, ">= 0.14.0", only: [:test], runtime: false},
{:sobelow, ">= 0.11.1", only: [:test], runtime: false}
]
end

defp preferred_cli_env do
[
check: :test,
credo: :test,
dialyxir: :test,
dialyzer: :test,
doctor: :test,
sobelow: :test
]
end

defp dialyzer do
[
ignore_warnings: ".dialyzer_ignore.exs",
flags: [
:error_handling,
:race_conditions,
:underspecs,
:unmatched_returns
],
plt_add_apps: [
:ex_unit,
:mix
],
plt_add_deps: :apps_direct,
plt_file: {:no_warn, "priv/plts/dialyzer.plt"}
]
end
end
Loading

0 comments on commit 636e05f

Please sign in to comment.