From db58da82ce596b8dd47cb99c9f6a52a7adc5bc99 Mon Sep 17 00:00:00 2001 From: Tobias Pfeiffer Date: Thu, 9 Nov 2023 09:50:53 +0100 Subject: [PATCH] OG benchee import --- .credo.exs | 159 +++++++++++++++++++++++++++++++++++++ .formatter.exs | 8 +- .github/workflows/main.yml | 139 ++++++++++++++++++++++++++++++++ .tool-versions | 4 +- .travis.yml | 22 ----- 5 files changed, 302 insertions(+), 30 deletions(-) create mode 100644 .credo.exs create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..0089466 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,159 @@ +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any exec using `mix credo -C `. If no exec name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: ["lib/", "src/", "test/", "web/", "apps/"], + excluded: [~r"/_build/", ~r"/deps/"] + }, + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + strict: true, + # + # If you want to use uncolored output by default, you can change `color` + # to `false` below: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames}, + {Credo.Check.Consistency.LineEndings}, + {Credo.Check.Consistency.ParameterPatternMatching}, + {Credo.Check.Consistency.SpaceAroundOperators}, + {Credo.Check.Consistency.SpaceInParentheses}, + {Credo.Check.Consistency.TabsOrSpaces}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, false}, + # For some checks, you can also set other parameters + # + # If you don't want the `setup` and `test` macro calls in ExUnit tests + # or the `schema` macro in Ecto schemas to trigger DuplicatedCode, just + # set the `excluded_macros` parameter to `[:schema, :setup, :test]`. + # + {Credo.Check.Design.DuplicatedCode, excluded_macros: []}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, exit_status: 2}, + {Credo.Check.Design.TagFIXME}, + + # + ## Readability Checks + # + {Credo.Check.Readability.FunctionNames}, + {Credo.Check.Readability.LargeNumbers}, + {Credo.Check.Readability.MaxLineLength, priority: :low, max_length: 98}, + {Credo.Check.Readability.ModuleAttributeNames}, + {Credo.Check.Readability.ModuleDoc}, + {Credo.Check.Readability.ModuleNames}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs}, + {Credo.Check.Readability.ParenthesesInCondition}, + {Credo.Check.Readability.PredicateFunctionNames}, + {Credo.Check.Readability.PreferImplicitTry}, + {Credo.Check.Readability.RedundantBlankLines}, + {Credo.Check.Readability.StringSigils}, + {Credo.Check.Readability.TrailingBlankLine}, + {Credo.Check.Readability.TrailingWhiteSpace}, + {Credo.Check.Readability.VariableNames}, + {Credo.Check.Readability.Semicolons}, + {Credo.Check.Readability.SpaceAfterCommas}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.DoubleBooleanNegation}, + {Credo.Check.Refactor.CondStatements}, + {Credo.Check.Refactor.CyclomaticComplexity}, + {Credo.Check.Refactor.FunctionArity}, + {Credo.Check.Refactor.LongQuoteBlocks}, + {Credo.Check.Refactor.MatchInCondition}, + {Credo.Check.Refactor.NegatedConditionsInUnless}, + {Credo.Check.Refactor.NegatedConditionsWithElse}, + {Credo.Check.Refactor.Nesting}, + {Credo.Check.Refactor.PipeChainStart, + excluded_argument_types: [:atom, :binary, :fn, :keyword], excluded_functions: []}, + {Credo.Check.Refactor.UnlessWithElse}, + + # + ## Warnings + # + {Credo.Check.Warning.BoolOperationOnSameValues}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck}, + {Credo.Check.Warning.IExPry}, + {Credo.Check.Warning.IoInspect}, + {Credo.Check.Warning.LazyLogging}, + {Credo.Check.Warning.OperationOnSameValues}, + {Credo.Check.Warning.OperationWithConstantResult}, + {Credo.Check.Warning.UnusedEnumOperation}, + {Credo.Check.Warning.UnusedFileOperation}, + {Credo.Check.Warning.UnusedKeywordOperation}, + {Credo.Check.Warning.UnusedListOperation}, + {Credo.Check.Warning.UnusedPathOperation}, + {Credo.Check.Warning.UnusedRegexOperation}, + {Credo.Check.Warning.UnusedStringOperation}, + {Credo.Check.Warning.UnusedTupleOperation}, + {Credo.Check.Warning.RaiseInsideRescue}, + + # + # Controversial and experimental checks (opt-in, just remove `, false`) + # + {Credo.Check.Refactor.ABCSize, false}, + {Credo.Check.Refactor.AppendSingleItem, false}, + {Credo.Check.Refactor.VariableRebinding, false}, + {Credo.Check.Warning.MapGetUnsafePass, false}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, false}, + + # + # Deprecated checks (these will be deleted after a grace period) + # + {Credo.Check.Readability.Specs, false} + + # + # Custom checks can be created using `mix credo.gen.check`. + # + ] + } + ] +} diff --git a/.formatter.exs b/.formatter.exs index 3ccf5d1..939d646 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,8 +1,4 @@ +# Used by "mix format" [ - inputs: [ - "lib/**/*.{ex,exs}", - "test/**/*.{ex,exs}", - "mix/**/*.{ex,exs}", - "./mix.exs" - ] + inputs: ["{mix,.formatter}.exs", "{config,lib,test,samples,mix}/**/*.{ex,exs}"] ] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..9c9db87 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,139 @@ +name: CI + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +on: [pull_request, push] + +jobs: + linux: + name: Test on Ubuntu (Elixir ${{ matrix.elixir_version }}, OTP ${{ matrix.otp_version }}) + runs-on: ubuntu-20.04 + + strategy: + matrix: + # Thoroughly check the most recent versions + elixir_version: ['1.13.4', '1.14.5', '1.15.7', '1.16.0-rc.0'] + otp_version: ['23.3', '24.3', '25.3', '26.1'] + # Spot check older versions + # + # Goal is to have old versions (elixir and erlang) have basically one test each. + # That should be enough to affirm that they are working ok. + include: + - elixir_version: '1.7.4' + otp_version: '20.3' + - elixir_version: '1.8.2' + otp_version: '20.3' + - elixir_version: '1.9.4' + otp_version: '21.3' + - elixir_version: '1.10.4' + otp_version: '21.3' + - elixir_version: '1.11.4' + otp_version: '22.3' + - elixir_version: '1.12.3' + otp_version: '23.3' + - elixir_version: '1.13.4' + otp_version: '22.3' + exclude: + - elixir_version: '1.15.7' + otp_version: '23.3' + - elixir_version: '1.16.0-rc.0' + otp_version: '23.3' + - elixir_version: '1.13.4' + otp_version: '26.1' + - elixir_version: '1.14.5' + otp_version: '26.1' + + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{ matrix.elixir_version }} + otp-version: ${{ matrix.otp_version }} + - name: Restore deps and _build + uses: actions/cache@v3 + with: + path: | + deps + _build + key: erlef-${{ runner.os }}-mix-${{ matrix.elixir_version }}-${{ matrix.otp_version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + - name: Restore plts + uses: actions/cache@v3 + with: + path: tools/plts + key: erlef-${{ runner.os }}-dialyzer-${{ matrix.elixir_version }}-${{ matrix.otp_version }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + if: contains(matrix.elixir_version, '1.15') + - run: mix deps.get + - run: MIX_ENV=test mix compile --warnings-as-errors + - run: mix credo + if: contains(matrix.elixir_version, '1.15') + - name: Check if formatted + if: contains(matrix.elixir_version, '1.15') + run: mix format --check-formatted + - name: Actual Tests + # this will let warnings slip through but I don't wanna replicate all that magic + # right now + run: MIX_ENV=test mix coveralls.github || mix test --failed + # Apparently the one with `!` can't go without the fancy expression syntax + if: ${{ !contains(matrix.elixir_version, '1.15') }} + - name: Actual Tests WITH warnings as errors + run: MIX_ENV=test mix coveralls.github --warnings-as-errors || mix test --failed + if: contains(matrix.elixir_version, '1.15') + - name: Dialyzer + run: mix dialyzer --halt-exit-status + if: contains(matrix.elixir_version, '1.15') + + macos: + name: Test on MacOS + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + # no versioning on brew but getting asdf or something was a bigger headache + - name: Install Elixir + run: brew install elixir + - name: Restore deps and _build + uses: actions/cache@v3 + with: + path: | + deps + _build + key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + - run: mix local.hex --force + - run: mix deps.get + - run: mix local.rebar --force + - run: MIX_ENV=test mix compile --warnings-as-errors + - run: mix test || mix test --failed + + windows: + name: Test on Windows + runs-on: windows-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Restore chocolatey + uses: actions/cache@v3 + with: + path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey + key: ${{ runner.os }}-chocolatey-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-chocolatey- + - name: Install Elixir + run: | + choco install elixir --version=1.14.2 --no-progress + set MIX_ENV=test + echo "C:\ProgramData\chocolatey\lib\Elixir\bin;C:\ProgramData\chocolatey\bin;C:\ProgramData\chocolatey\lib\Elixir\tools\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Build + run: | + echo "$PATH" + mix local.hex --force + mix deps.get + mix local.rebar --force + mix compile --warnings-as-errors + - name: Test + run: mix test || mix test --failed diff --git a/.tool-versions b/.tool-versions index 57c8f30..cdf038a 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 21.3.2 -elixir 1.8.1-otp-21 +elixir 1.15.4 +erlang 26.1.2 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eedc31b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -language: elixir -elixir: - - 1.6.6 - - 1.7.4 - - 1.8.1 -otp_release: - - 20.3 - - 21.2 -before_script: - - MIX_ENV=test mix compile --warnings-as-errors - - travis_wait mix dialyzer --plt -script: - - mix credo --strict - - mix format --check-formatted - - mix dialyzer --halt-exit-status - - mix coveralls.travis -sudo: required -dist: trusty -cache: - directories: - - _build - - deps