From 8d42c8cab8e8ae26a3a40435c0b9f8f03d26beda Mon Sep 17 00:00:00 2001 From: Alexandre Hamez Date: Sat, 31 Dec 2022 22:14:00 +0100 Subject: [PATCH] ci: enable mutation testing with muzak pro --- .github/workflows/elixir.yml | 9 +---- .github/workflows/mutation_testing.yml | 55 ++++++++++++++++++++++++++ .muzak.exs | 25 +----------- mix.exs | 18 ++++++++- 4 files changed, 76 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/mutation_testing.yml diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml index fc2c7577..01a1eb20 100644 --- a/.github/workflows/elixir.yml +++ b/.github/workflows/elixir.yml @@ -24,23 +24,18 @@ jobs: include: - elixir: 1.9.4 otp: 22.3 - check_deps: false - check_format: false - elixir: 1.10.4 otp: 22.3 - check_format: false - elixir: 1.11.4 otp: 23.3 - check_format: false - elixir: 1.12.3 otp: 24.1 - elixir: 1.13.0 otp: 24.1 - elixir: 1.14.1 - check_deps: true - check_format: true otp: 25.1 - + check_format: true + check_deps: true steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/mutation_testing.yml b/.github/workflows/mutation_testing.yml new file mode 100644 index 00000000..7f344d96 --- /dev/null +++ b/.github/workflows/mutation_testing.yml @@ -0,0 +1,55 @@ +name: Mutation testing + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +jobs: + build: + + runs-on: ubuntu-20.04 + name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} + strategy: + fail-fast: false + matrix: + include: + - elixir: 1.14.1 + otp: 25.1 + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 30 + + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + elixir-version: ${{matrix.elixir}} + otp-version: ${{matrix.otp}} + + - name: Restore dependencies cache + uses: actions/cache@v2 + with: + path: deps + key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-mix-${{ hashFiles('**/mix.lock') }} + + - name: Install protoc + run: | + wget https://github.com/protocolbuffers/protobuf/releases/download/v21.4/protoc-21.4-linux-x86_64.zip + unzip -d protoc protoc-21.4-linux-x86_64.zip + echo "${PWD}/protoc/bin" >> $GITHUB_PATH + + - name: Run mutation testing + env: + PROTOX_MUZAK_PRO_CREDS: ${{ secrets.PROTOX_MUZAK_PRO_CREDS }} + MIX_ENV: test + run: | + mix local.rebar --force + mix local.hex --force + mix deps.get + mix muzak --profile ci diff --git a/.muzak.exs b/.muzak.exs index de12bcc8..c3378c90 100644 --- a/.muzak.exs +++ b/.muzak.exs @@ -77,7 +77,6 @@ end) |> Enum.filter(&String.ends_with?(&1, ".ex")) |> Enum.map(&{&1, nil}) - |> IO.inspect() end, # If you would like to run fewer tests for each run, or run them in a certain order, you @@ -104,30 +103,10 @@ # being run. # mutation_filter: fn _ -> - split_pattern = ";;;" - - {commits_and_authors, 0} = - System.cmd("git", [ - "log", - "--pretty=format:%C(auto)%h#{split_pattern}%an", - "--date-order", - "-20" - ]) - - last_commit_by_a_different_author = - commits_and_authors - |> String.split("\n") - |> Enum.map(&String.split(&1, split_pattern)) - |> Enum.reduce_while(nil, fn - [_, author], nil -> {:cont, author} - [_, author], author -> {:cont, author} - [commit, _], _ -> {:halt, commit} - end) - - {diff, 0} = System.cmd("git", ["diff", "-U0", last_commit_by_a_different_author]) + {diff, 0} = System.cmd("git", ["diff", "HEAD~25"]) # All of this is to parse the git diff output to get the correct files and line numbers - # that have changed in the given diff since the last commit by a different author. + # that have changed in the given diff since the last 25 commits. first = ~r|---\ (a/)?.*| second = ~r|\+\+\+\ (b\/)?(.*)| third = ~r|@@\ -[0-9]+(,[0-9]+)?\ \+([0-9]+)(,[0-9]+)?\ @@.*| diff --git a/mix.exs b/mix.exs index b1c19202..fb6e9e51 100644 --- a/mix.exs +++ b/mix.exs @@ -17,7 +17,8 @@ defmodule Protox.Mixfile do description: description(), package: package(), dialyzer: [plt_local_path: "priv/plts"], - docs: docs() + docs: docs(), + preferred_cli_env: [muzak: :test] ] end @@ -49,6 +50,21 @@ defmodule Protox.Mixfile do {:poison, "~> 4.0 or ~> 5.0", only: [:test, :dev], optional: true}, {:propcheck, "~> 1.2", only: [:test, :dev]} ] + |> maybe_add_muzak_pro() + end + + defp maybe_add_muzak_pro(deps) do + case System.get_env("PROTOX_MUZAK_PRO_CREDS") do + nil -> + deps + + creds -> + muzak_pro = + {:muzak, + git: "https://#{creds}@git.devonestes.com/muzak/muzak.git", tag: "1.1.0", only: [:test]} + + [muzak_pro | deps] + end end defp description do