Skip to content

Commit

Permalink
ci: enable mutation testing with muzak pro
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamez committed Jan 1, 2023
1 parent 4bc2d2c commit 8d42c8c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 31 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/mutation_testing.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 2 additions & 23 deletions .muzak.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]+)?\ @@.*|
Expand Down
18 changes: 17 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d42c8c

Please sign in to comment.